From efd6630143d1cc334cdf1881d844de89eb01ffeb Mon Sep 17 00:00:00 2001 From: Jithil P Ponnan Date: Tue, 19 Dec 2023 22:41:27 +0530 Subject: [PATCH] test: fix flakiness in worker*.test-free-called MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The issue arises from the `getFreeCallCount()` function yielding the initial value of 0. Upon instantiation of the `Worker` object, it increments to 1. In the case of this flaky test, if the creation of the `Worker` object is faster, the subsequent `getFreeCallCount()` call always returns 1 instead of the expected 0. Fixes: https://github.com/nodejs/node/issues/51003 PR-URL: https://github.com/nodejs/node/pull/51013 Reviewed-By: Vinícius Lourenço Claro Cardoso Reviewed-By: Joyee Cheung Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- test/addons/worker-buffer-callback/test-free-called.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/addons/worker-buffer-callback/test-free-called.js b/test/addons/worker-buffer-callback/test-free-called.js index 2a3cc9e47c22ff..c15cdde432cd31 100644 --- a/test/addons/worker-buffer-callback/test-free-called.js +++ b/test/addons/worker-buffer-callback/test-free-called.js @@ -6,12 +6,14 @@ const { Worker } = require('worker_threads'); const binding = path.resolve(__dirname, `./build/${common.buildType}/binding`); const { getFreeCallCount } = require(binding); +// getFreeCallCount initial value is 0 +assert.strictEqual(getFreeCallCount(), 0); + // Test that buffers allocated with a free callback through our APIs are // released when a Worker owning it exits. const w = new Worker(`require(${JSON.stringify(binding)})`, { eval: true }); -assert.strictEqual(getFreeCallCount(), 0); w.on('exit', common.mustCall(() => { assert.strictEqual(getFreeCallCount(), 1); }));