Skip to content

Commit bcd8064

Browse files
committed
test: add test for workers thread-safety issues fix
1 parent b3fcd1a commit bcd8064

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/test-worker-imports.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Test for thread-safety issues caused by subsequent imports of the module
2+
// in worker threads: https://github.com/mscdex/ssh2/issues/1393.
3+
// Each subsequent worker increases probability of abnormal termination.
4+
// The probability of a false pass due to zero response becomes negligible
5+
// for 4 consecutive workers.
6+
'use strict';
7+
8+
const { Worker, isMainThread } = require('worker_threads');
9+
require('../lib/index.js');
10+
11+
if (isMainThread) {
12+
async function runWorker() {
13+
return new Promise((r) => new Worker(__filename).on("exit", r));
14+
}
15+
runWorker()
16+
.then(runWorker)
17+
.then(runWorker)
18+
.then(runWorker);
19+
}

0 commit comments

Comments
 (0)