mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
test: fix the thread-spawn handshake in the WASI threads fixture
test-wasi-pthread fails now and then on every platform with "Assertion failed: r == 0 (c/pthread.c: main: 17)", i.e. pthread_create() itself reporting an error. The fixture implements `thread-spawn` by starting a Worker and blocking in Atomics.wait(result, 0, 0, 1000) until the worker signals that it has instantiated the module. Two things go wrong there: the worker signals success by storing 0, the value the main thread is already waiting on, so when the worker is quicker than the main thread its notify is lost and the wait runs into the timeout; and one second is not always enough for a Worker to start and instantiate a threads build on the slower CI hosts (arm debug, Windows, macOS). Either way spawn() returns -6 and wasi-libc turns that into a pthread_create() failure. Wait on a sentinel value that neither outcome writes, and give the worker a platform-scaled 30 seconds. Drop the flaky markers. Fixes: https://github.com/nodejs/node/issues/64226 Refs: https://github.com/nodejs/node/issues/59146 Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com> PR-URL: https://github.com/nodejs/node/pull/65780 Refs: https://github.com/nodejs/node/issues/54534 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
This commit is contained in:
1 parent
7eb20b1810
commit
62e2a6265c
2 files changed
+4
-8
No files matched your search
Vendored
+4
-1
@@ -68,6 +68,9 @@ assert.strictEqual(wasiPreview1.wasiImport,
|
||||
const name = `pthread-${tid}`;
|
||||
const sab = new SharedArrayBuffer(8 + 8192);
|
||||
const result = new Int32Array(sab);
|
||||
// The thread stores 0 once it has loaded or 1 with an error; wait on a
|
||||
// value neither of them writes so an early notify cannot be missed.
|
||||
Atomics.store(result, 0, -1);
|
||||
|
||||
const workerData = {
|
||||
name,
|
||||
@@ -106,7 +109,7 @@ assert.strictEqual(wasiPreview1.wasiImport,
|
||||
throw new Error(e);
|
||||
});
|
||||
|
||||
const r = Atomics.wait(result, 0, 0, 1000);
|
||||
const r = Atomics.wait(result, 0, -1, common.platformTimeout(30_000));
|
||||
if (r === 'timed-out') {
|
||||
workers[tid].terminate();
|
||||
delete workers[tid];
|
||||
|
||||
@@ -15,10 +15,3 @@ test-wasi-getrusage: SKIP
|
||||
# Unsupported on Windows and Android
|
||||
test-wasi-readdir: SKIP
|
||||
|
||||
[$system==win32 || $system==macos]
|
||||
# https://github.com/nodejs/node/issues/64226#issuecomment-5423585588
|
||||
test-wasi-pthread: PASS, FLAKY
|
||||
|
||||
[$system==linux]
|
||||
# https://github.com/nodejs/node/issues/59146
|
||||
test-wasi-pthread: PASS, FLAKY
|
||||
Reference in new issue
Block a user