Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions test/parallel/test-worker-stack-overflow-stack-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ const { Worker } = require('worker_threads');
// Verify that Workers don't care about --stack-size, as they have their own
// fixed and known stack sizes.

// The depth of the stack depends not only on the stack size, but also on the size of each
// stack frame, which in turn depends on which tier the recursive function happens to be
// running at when the overflow occurs. Under load the background tier-up can land at a
// non-deterministic point in the recursion and flake the test. Keep the recursive
// function in the interpreter with %NeverOptimizeFunction() so the frame size -
// and thus the depth - is deterministic.
v8.setFlagsFromString('--allow-natives-syntax');

async function runWorker(options = {}) {
const empiricalStackDepth = new Uint32Array(new SharedArrayBuffer(4));
const worker = new Worker(`
Expand All @@ -16,6 +24,7 @@ async function runWorker(options = {}) {
empiricalStackDepth[0]++;
f();
}
%NeverOptimizeFunction(f);
f();`, {
eval: true,
workerData: { empiricalStackDepth },
Expand Down
Loading