node/test/parallel/test-worker-ref-onexit.js
Anna Henningsen 2da7ff5e96
test: fix flaky test-worker-ref-onexit
Fixes: https://github.com/nodejs/node/issues/26167

PR-URL: https://github.com/nodejs/node/pull/26170
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com>
2019-02-18 00:09:47 +01:00

13 lines
442 B
JavaScript

'use strict';
const common = require('../common');
const { Worker } = require('worker_threads');
// Check that worker.unref() makes the 'exit' event not be emitted, if it is
// the only thing we would otherwise be waiting for.
// Use `setInterval()` to make sure the worker is alive until the end of the
// event loop turn.
const w = new Worker('setInterval(() => {}, 100);', { eval: true });
w.unref();
w.on('exit', common.mustNotCall());