Skip to content

Commit

Permalink
test: resolve flakiness in worker*.test-free-called
Browse files Browse the repository at this point in the history
Fixes: nodejs#51003

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.
  • Loading branch information
MrJithil committed Dec 2, 2023
1 parent 1b16bf6 commit 77db520
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion test/addons/worker-buffer-callback/test-free-called.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}));

0 comments on commit 77db520

Please sign in to comment.