From a92ccab169cc76f4e639368fc0fc9b7e010b9586 Mon Sep 17 00:00:00 2001 From: Levente Kurusa Date: Wed, 12 Apr 2023 00:22:12 +0200 Subject: [PATCH] fix(node/crypto): test randomFill --- cli/tests/unit_node/internal/_randomFill_test.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cli/tests/unit_node/internal/_randomFill_test.ts b/cli/tests/unit_node/internal/_randomFill_test.ts index 00ff029cc989d3..fd10405788f4e4 100644 --- a/cli/tests/unit_node/internal/_randomFill_test.ts +++ b/cli/tests/unit_node/internal/_randomFill_test.ts @@ -1,11 +1,13 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { Buffer } from "node:buffer"; +import { AsyncLocalStorage } from "node:async_hooks"; import { randomFill, randomFillSync } from "node:crypto"; import { assertEquals, assertNotEquals, assertThrows, } from "../../../../test_util/std/testing/asserts.ts"; +import { deferred } from "../../../../test_util/std/async/deferred.ts"; const validateNonZero = (buf: Buffer) => { if (!buf.some((ch) => ch > 0)) throw new Error("Error"); @@ -15,14 +17,18 @@ const validateZero = (buf: Buffer) => { buf.forEach((val) => assertEquals(val, 0)); }; -Deno.test("[node/crypto.randomFill]", () => { +Deno.test("[node/crypto.randomFill]", async () => { + const promise = deferred(); const buf = Buffer.alloc(10); const before = buf.toString("hex"); randomFill(buf, 5, 5, (_err, bufTwo) => { const after = bufTwo?.toString("hex"); assertEquals(before.slice(0, 10), after?.slice(0, 10)); + promise.resolve(true); }); + + await promise; }); Deno.test("[node/crypto.randomFillSync]", () => {