Skip to content

Commit

Permalink
test: add test for workers thread-safety issues fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rmnilin committed Feb 2, 2025
1 parent b3fcd1a commit bcd8064
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/test-worker-imports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Test for thread-safety issues caused by subsequent imports of the module
// in worker threads: https://github.com/mscdex/ssh2/issues/1393.
// Each subsequent worker increases probability of abnormal termination.
// The probability of a false pass due to zero response becomes negligible
// for 4 consecutive workers.
'use strict';

const { Worker, isMainThread } = require('worker_threads');
require('../lib/index.js');

if (isMainThread) {
async function runWorker() {
return new Promise((r) => new Worker(__filename).on("exit", r));

Check failure on line 13 in test/test-worker-imports.js

View workflow job for this annotation

GitHub Actions / lint-js

Strings must use singlequote
}
runWorker()
.then(runWorker)
.then(runWorker)
.then(runWorker);
}

0 comments on commit bcd8064

Please sign in to comment.