From ae19f944f822048827fb7dd327e06b16b4d687bc Mon Sep 17 00:00:00 2001 From: Gireesh Punathil Date: Mon, 17 Dec 2018 02:52:43 -0500 Subject: [PATCH] test: exit sequence sanity tests Execute many module loads in worker in a loop while exiting from the main thread at arbitrary execution points, and make sure that the workers quiesce without crashing. `worker_threads` are not necessarily the subject of testing, those are used for easy simulation of multi-thread scenarios. Refs: https://github.com/nodejs/node/issues/25007 PR-URL: https://github.com/nodejs/node/pull/25083 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- .../test-worker-cleanexit-with-moduleload.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 test/parallel/test-worker-cleanexit-with-moduleload.js diff --git a/test/parallel/test-worker-cleanexit-with-moduleload.js b/test/parallel/test-worker-cleanexit-with-moduleload.js new file mode 100644 index 00000000000000..172544f50aba79 --- /dev/null +++ b/test/parallel/test-worker-cleanexit-with-moduleload.js @@ -0,0 +1,24 @@ +'use strict'; +require('../common'); + +// Harden the thread interactions on the exit path. +// Ensure workers are able to bail out safe at +// arbitrary execution points. By using a number of +// internal modules as load candidates, the expectation +// is that those will be at various control flow points +// preferrably in the C++ land. + +const { Worker } = require('worker_threads'); +for (let i = 0; i < 10; i++) { + new Worker("const modules = ['fs', 'assert', 'async_hooks'," + + "'buffer', 'child_process', 'net', 'http', 'https', 'os'," + + "'path', 'v8', 'vm'];" + + 'modules.forEach((module) => {' + + 'const m = require(module);' + + '});', { eval: true }); +} + +// Allow workers to go live. +setTimeout(() => { + process.exit(0); +}, 200);