2020-01-02 15:13:47 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-03-04 11:31:14 -05:00
|
|
|
import { unitTest, assert } from "./test_util.ts";
|
2018-10-05 13:21:15 -04:00
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(async function metrics(): Promise<void> {
|
2019-02-12 10:08:56 -05:00
|
|
|
const m1 = Deno.metrics();
|
2018-10-05 13:21:15 -04:00
|
|
|
assert(m1.opsDispatched > 0);
|
2020-03-02 13:13:36 -05:00
|
|
|
assert(m1.opsDispatchedSync > 0);
|
2018-10-05 13:21:15 -04:00
|
|
|
assert(m1.opsCompleted > 0);
|
2020-03-02 13:13:36 -05:00
|
|
|
assert(m1.opsCompletedSync > 0);
|
2018-10-05 13:21:15 -04:00
|
|
|
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.
|
2020-03-03 09:51:07 -05:00
|
|
|
const dataMsg = new Uint8Array([13, 13, 13]); // "\r\r\r",
|
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);
|
2020-03-02 13:13:36 -05:00
|
|
|
assert(m2.opsDispatchedSync > m1.opsDispatchedSync);
|
|
|
|
assert(m2.opsDispatchedAsync > m1.opsDispatchedAsync);
|
2018-10-05 13:21:15 -04:00
|
|
|
assert(m2.opsCompleted > m1.opsCompleted);
|
2020-03-02 13:13:36 -05:00
|
|
|
assert(m2.opsCompletedSync > m1.opsCompletedSync);
|
|
|
|
assert(m2.opsCompletedAsync > m1.opsCompletedAsync);
|
2018-10-05 13:21:15 -04:00
|
|
|
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
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(
|
|
|
|
{ perms: { write: true } },
|
|
|
|
function metricsUpdatedIfNoResponseSync(): void {
|
|
|
|
const filename = Deno.makeTempDirSync() + "/test.txt";
|
2018-10-17 14:30:23 -04:00
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
const data = new Uint8Array([41, 42, 43]);
|
2020-03-07 22:29:12 -05:00
|
|
|
Deno.writeFileSync(filename, data, { mode: 0o666 });
|
2018-10-17 14:30:23 -04:00
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
const metrics = Deno.metrics();
|
|
|
|
assert(metrics.opsDispatched === metrics.opsCompleted);
|
|
|
|
assert(metrics.opsDispatchedSync === metrics.opsCompletedSync);
|
|
|
|
}
|
|
|
|
);
|
2018-10-17 14:30:23 -04:00
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(
|
|
|
|
{ perms: { write: true } },
|
2019-04-21 16:40:10 -04:00
|
|
|
async function metricsUpdatedIfNoResponseAsync(): Promise<void> {
|
|
|
|
const filename = Deno.makeTempDirSync() + "/test.txt";
|
2018-10-17 14:30:23 -04:00
|
|
|
|
2019-04-21 16:40:10 -04:00
|
|
|
const data = new Uint8Array([41, 42, 43]);
|
2020-03-07 22:29:12 -05:00
|
|
|
await Deno.writeFile(filename, data, { mode: 0o666 });
|
2018-10-17 14:30:23 -04:00
|
|
|
|
2019-04-21 16:40:10 -04:00
|
|
|
const metrics = Deno.metrics();
|
|
|
|
assert(metrics.opsDispatched === metrics.opsCompleted);
|
2020-03-02 13:13:36 -05:00
|
|
|
assert(metrics.opsDispatchedSync === metrics.opsCompletedSync);
|
|
|
|
assert(metrics.opsDispatchedAsync === metrics.opsCompletedAsync);
|
2019-04-21 16:40:10 -04:00
|
|
|
}
|
|
|
|
);
|