mirror of
https://github.com/denoland/deno.git
synced 2024-11-26 16:09:27 -05:00
add test case for metrics
This commit is contained in:
parent
fd2bb015c7
commit
3a226f166f
2 changed files with 29 additions and 6 deletions
|
@ -1,8 +1,8 @@
|
||||||
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
// 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";
|
import * as deno from "deno";
|
||||||
|
|
||||||
test(function metrics() {
|
test(async function metrics() {
|
||||||
const m1 = deno.metrics();
|
const m1 = deno.metrics();
|
||||||
assert(m1.opsDispatched > 0);
|
assert(m1.opsDispatched > 0);
|
||||||
assert(m1.opsCompleted > 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
|
// Write to stdout to ensure a "data" message gets sent instead of just
|
||||||
// control messages.
|
// control messages.
|
||||||
const dataMsg = new Uint8Array([41, 42, 43]);
|
const dataMsg = new Uint8Array([41, 42, 43]);
|
||||||
deno.stdout.write(dataMsg);
|
await deno.stdout.write(dataMsg);
|
||||||
|
|
||||||
const m2 = deno.metrics();
|
const m2 = deno.metrics();
|
||||||
assert(m2.opsDispatched > m1.opsDispatched);
|
assert(m2.opsDispatched > m1.opsDispatched);
|
||||||
|
@ -22,3 +22,23 @@ test(function metrics() {
|
||||||
assert(m2.bytesSentData >= m1.bytesSentData + dataMsg.byteLength);
|
assert(m2.bytesSentData >= m1.bytesSentData + dataMsg.byteLength);
|
||||||
assert(m2.bytesReceived > m1.bytesReceived);
|
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);
|
||||||
|
});
|
|
@ -171,6 +171,8 @@ impl Isolate {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn respond(&mut self, req_id: i32, buf: Buf) {
|
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
|
// 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)
|
// don't do the memcpy in ImportBuf() (in libdeno/binding.cc)
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -188,9 +190,7 @@ impl Isolate {
|
||||||
// completing.
|
// completing.
|
||||||
self.ntasks_decrement();
|
self.ntasks_decrement();
|
||||||
// Call into JS with the buf.
|
// Call into JS with the buf.
|
||||||
let buf_size = buf.len() as u64;
|
|
||||||
self.respond(req_id, buf);
|
self.respond(req_id, buf);
|
||||||
self.state.metrics_op_completed(buf_size)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn timeout(&mut self) {
|
fn timeout(&mut self) {
|
||||||
|
@ -305,10 +305,13 @@ extern "C" fn pre_dispatch(
|
||||||
// Execute op synchronously.
|
// Execute op synchronously.
|
||||||
let buf = tokio_util::block_on(op).unwrap();
|
let buf = tokio_util::block_on(op).unwrap();
|
||||||
let buf_size = buf.len();
|
let buf_size = buf.len();
|
||||||
|
|
||||||
if buf_size != 0 {
|
if buf_size != 0 {
|
||||||
// Set the synchronous response, the value returned from isolate.send().
|
// Set the synchronous response, the value returned from isolate.send().
|
||||||
isolate.respond(req_id, buf);
|
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 {
|
} else {
|
||||||
// Execute op asynchronously.
|
// Execute op asynchronously.
|
||||||
|
|
Loading…
Reference in a new issue