Files
Christian Aurich ed6f3bc756 test: deflake node-api test-free-called
`node-api/test_worker_buffer_callback/test-free-called` checks that
`getFreeCallCount()` is 0 on a line that runs after `new Worker()`. The
worker thread can load the addon and run its finalizer before the main
thread reaches that line, in which case the counter is already 1 and the
assertion fails. The zero check is only a baseline, so it does not need
the worker to exist.

Move it above the worker creation. The equivalent test under
test/addons/worker-buffer-callback was changed the same way in
64f7d0e0bd.

Signed-off-by: Christian Aurich <christian.aurichzm@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/65948
Refs: https://github.com/nodejs/node/pull/51013
Refs: https://github.com/nodejs/reliability/blob/e457f5b68957d1502256488977bc33b4346d8a4b/reports/2026-09-10.md
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2026-09-12 09:36:45 +02:00

19 lines
618 B
JavaScript

'use strict';
const common = require('../../common');
const path = require('path');
const assert = require('assert');
const { Worker } = require('worker_threads');
const binding = path.resolve(__dirname, `./build/${common.buildType}/binding`);
const { getFreeCallCount } = require(binding);
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 });
w.on('exit', common.mustCall(() => {
assert.strictEqual(getFreeCallCount(), 1);
}));