From 3a226f166fef38829810fb8813b46dee73c83005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 17 Oct 2018 20:30:23 +0200 Subject: add test case for metrics --- js/metrics_test.ts | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'js') 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 -- cgit v1.2.3