Skip to content

Commit d7c2572

Browse files
MrJithilRafaelGSS
authored andcommitted
test: fix flakiness in worker*.test-free-called
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: #51003 PR-URL: #51013 Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 8a2dd93 commit d7c2572

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

test/addons/worker-buffer-callback/test-free-called.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ const { Worker } = require('worker_threads');
66
const binding = path.resolve(__dirname, `./build/${common.buildType}/binding`);
77
const { getFreeCallCount } = require(binding);
88

9+
// getFreeCallCount initial value is 0
10+
assert.strictEqual(getFreeCallCount(), 0);
11+
912
// Test that buffers allocated with a free callback through our APIs are
1013
// released when a Worker owning it exits.
1114

1215
const w = new Worker(`require(${JSON.stringify(binding)})`, { eval: true });
1316

14-
assert.strictEqual(getFreeCallCount(), 0);
1517
w.on('exit', common.mustCall(() => {
1618
assert.strictEqual(getFreeCallCount(), 1);
1719
}));

0 commit comments

Comments
 (0)