mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
3738b57102
These tests spawn many workers, which may be CPU intensive causing timeouts (see the referenced PR for more details). Let's move them to sequential. Refs: https://github.com/nodejs/node/pull/44090 PR-URL: https://github.com/nodejs/node/pull/44139 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
52 lines
1.2 KiB
JavaScript
52 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const fs = require('fs/promises');
|
|
const { scheduler } = require('timers/promises');
|
|
const { parentPort, Worker } = require('worker_threads');
|
|
|
|
const MAX_ITERATIONS = 5;
|
|
const MAX_THREADS = 6;
|
|
|
|
// Do not use isMainThread so that this test itself can be run inside a Worker.
|
|
if (!process.env.HAS_STARTED_WORKER) {
|
|
process.env.HAS_STARTED_WORKER = 1;
|
|
|
|
function spinWorker(iter) {
|
|
const w = new Worker(__filename);
|
|
w.on('message', common.mustCall((msg) => {
|
|
assert.strictEqual(msg, 'terminate');
|
|
w.terminate();
|
|
}));
|
|
|
|
w.on('exit', common.mustCall(() => {
|
|
if (iter < MAX_ITERATIONS)
|
|
spinWorker(++iter);
|
|
}));
|
|
}
|
|
|
|
for (let i = 0; i < MAX_THREADS; i++) {
|
|
spinWorker(0);
|
|
}
|
|
} else {
|
|
async function open_nok() {
|
|
await assert.rejects(
|
|
fs.open('this file does not exist'),
|
|
{
|
|
code: 'ENOENT',
|
|
syscall: 'open'
|
|
}
|
|
);
|
|
await scheduler.yield();
|
|
await open_nok();
|
|
}
|
|
|
|
// These async function calls never return as they are meant to continually
|
|
// open nonexistent files until the worker is terminated.
|
|
open_nok();
|
|
open_nok();
|
|
|
|
parentPort.postMessage('terminate');
|
|
}
|