diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2018-10-17 20:30:23 +0200 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-10-18 05:08:49 -0400 |
commit | 3a226f166fef38829810fb8813b46dee73c83005 (patch) | |
tree | 9b4a3fc598e96f544a59a1dc8eae796713bf17ac | |
parent | fd2bb015c721c2db447272b4e9cd47fec353c6e1 (diff) |
add test case for metrics
-rw-r--r-- | js/metrics_test.ts | 26 | ||||
-rw-r--r-- | src/isolate.rs | 9 |
2 files changed, 29 insertions, 6 deletions
diff --git a/js/metrics_test.ts b/js/metrics_test.ts index 6954ae2ce..fd146df2d 100644 --- a/js/metrics_test.ts +++ b/js/metrics_test.ts @@ -1,8 +1,8 @@ // Copyright 2018 the Deno authors. All rights reserved. MIT license. -import { test, assert } from "./test_util.ts"; +import { test, testPerm, assert } from "./test_util.ts"; import * as deno from "deno"; -test(function metrics() { +test(async function metrics() { const m1 = deno.metrics(); assert(m1.opsDispatched > 0); assert(m1.opsCompleted > 0); @@ -13,7 +13,7 @@ test(function metrics() { // Write to stdout to ensure a "data" message gets sent instead of just // control messages. const dataMsg = new Uint8Array([41, 42, 43]); - deno.stdout.write(dataMsg); + await deno.stdout.write(dataMsg); const m2 = deno.metrics(); assert(m2.opsDispatched > m1.opsDispatched); @@ -22,3 +22,23 @@ test(function metrics() { assert(m2.bytesSentData >= m1.bytesSentData + dataMsg.byteLength); assert(m2.bytesReceived > m1.bytesReceived); }); + +testPerm({ write: true }, function metricsUpdatedIfNoResponseSync() { + const filename = deno.makeTempDirSync() + "/test.txt"; + + const data = new Uint8Array([41, 42, 43]); + deno.writeFileSync(filename, data, 0o666); + + const metrics = deno.metrics(); + assert(metrics.opsDispatched === metrics.opsCompleted); +}); + +testPerm({ write: true }, async function metricsUpdatedIfNoResponseAsync() { + const filename = deno.makeTempDirSync() + "/test.txt"; + + const data = new Uint8Array([41, 42, 43]); + await deno.writeFile(filename, data, 0o666); + + const metrics = deno.metrics(); + assert(metrics.opsDispatched === metrics.opsCompleted); +});
\ No newline at end of file diff --git a/src/isolate.rs b/src/isolate.rs index 4d6f7cdfc..340b1db89 100644 --- a/src/isolate.rs +++ b/src/isolate.rs @@ -171,6 +171,8 @@ impl Isolate { } pub fn respond(&mut self, req_id: i32, buf: Buf) { + self.state.metrics_op_completed(buf.len() as u64); + // TODO(zero-copy) Use Buf::leak(buf) to leak the heap allocated buf. And // don't do the memcpy in ImportBuf() (in libdeno/binding.cc) unsafe { @@ -188,9 +190,7 @@ impl Isolate { // completing. self.ntasks_decrement(); // Call into JS with the buf. - let buf_size = buf.len() as u64; self.respond(req_id, buf); - self.state.metrics_op_completed(buf_size) } fn timeout(&mut self) { @@ -305,10 +305,13 @@ extern "C" fn pre_dispatch( // Execute op synchronously. let buf = tokio_util::block_on(op).unwrap(); let buf_size = buf.len(); + if buf_size != 0 { // Set the synchronous response, the value returned from isolate.send(). isolate.respond(req_id, buf); - isolate.state.metrics_op_completed(buf_size as u64); + } else { + // FIXME + isolate.state.metrics_op_completed(buf.len() as u64); } } else { // Execute op asynchronously. |