2019-01-21 14:03:30 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2018-10-17 14:30:23 -04:00
|
|
|
import { test, testPerm, assert } from "./test_util.ts";
|
2018-10-05 13:21:15 -04:00
|
|
|
|
2018-10-17 14:30:23 -04:00
|
|
|
test(async function metrics() {
|
2019-02-12 10:08:56 -05:00
|
|
|
const m1 = Deno.metrics();
|
2018-10-05 13:21:15 -04:00
|
|
|
assert(m1.opsDispatched > 0);
|
|
|
|
assert(m1.opsCompleted > 0);
|
|
|
|
assert(m1.bytesSentControl > 0);
|
|
|
|
assert(m1.bytesSentData >= 0);
|
|
|
|
assert(m1.bytesReceived > 0);
|
|
|
|
|
|
|
|
// Write to stdout to ensure a "data" message gets sent instead of just
|
|
|
|
// control messages.
|
|
|
|
const dataMsg = new Uint8Array([41, 42, 43]);
|
2019-02-12 10:08:56 -05:00
|
|
|
await Deno.stdout.write(dataMsg);
|
2018-10-05 13:21:15 -04:00
|
|
|
|
2019-02-12 10:08:56 -05:00
|
|
|
const m2 = Deno.metrics();
|
2018-10-05 13:21:15 -04:00
|
|
|
assert(m2.opsDispatched > m1.opsDispatched);
|
|
|
|
assert(m2.opsCompleted > m1.opsCompleted);
|
|
|
|
assert(m2.bytesSentControl > m1.bytesSentControl);
|
|
|
|
assert(m2.bytesSentData >= m1.bytesSentData + dataMsg.byteLength);
|
|
|
|
assert(m2.bytesReceived > m1.bytesReceived);
|
|
|
|
});
|
2018-10-17 14:30:23 -04:00
|
|
|
|
|
|
|
testPerm({ write: true }, function metricsUpdatedIfNoResponseSync() {
|
2019-02-12 10:08:56 -05:00
|
|
|
const filename = Deno.makeTempDirSync() + "/test.txt";
|
2018-10-17 14:30:23 -04:00
|
|
|
|
|
|
|
const data = new Uint8Array([41, 42, 43]);
|
2019-02-12 10:08:56 -05:00
|
|
|
Deno.writeFileSync(filename, data, { perm: 0o666 });
|
2018-10-17 14:30:23 -04:00
|
|
|
|
2019-02-12 10:08:56 -05:00
|
|
|
const metrics = Deno.metrics();
|
2018-10-17 14:30:23 -04:00
|
|
|
assert(metrics.opsDispatched === metrics.opsCompleted);
|
|
|
|
});
|
|
|
|
|
|
|
|
testPerm({ write: true }, async function metricsUpdatedIfNoResponseAsync() {
|
2019-02-12 10:08:56 -05:00
|
|
|
const filename = Deno.makeTempDirSync() + "/test.txt";
|
2018-10-17 14:30:23 -04:00
|
|
|
|
|
|
|
const data = new Uint8Array([41, 42, 43]);
|
2019-02-12 10:08:56 -05:00
|
|
|
await Deno.writeFile(filename, data, { perm: 0o666 });
|
2018-10-17 14:30:23 -04:00
|
|
|
|
2019-02-12 10:08:56 -05:00
|
|
|
const metrics = Deno.metrics();
|
2018-10-17 14:30:23 -04:00
|
|
|
assert(metrics.opsDispatched === metrics.opsCompleted);
|
2018-10-18 18:28:47 -04:00
|
|
|
});
|