-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent hang when
process
is overwritten (#83)
- Loading branch information
1 parent
6ca7bb4
commit 18c8684
Showing
3 changed files
with
42 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import * as path from 'path' | ||
import { fileURLToPath } from 'url' | ||
import { Tinypool } from 'tinypool' | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)) | ||
|
||
describe.each(['worker_threads', 'child_process'] as const)('%s', (runtime) => { | ||
test("doesn't hang when process is overwritten", async () => { | ||
const pool = createPool({ runtime }) | ||
|
||
const result = await pool.run(` | ||
(async () => { | ||
return new Promise(resolve => { | ||
globalThis.process = { exit: resolve }; | ||
process.exit("exit() from overwritten process"); | ||
}); | ||
})(); | ||
`) | ||
expect(result).toBe('exit() from overwritten process') | ||
}) | ||
}) | ||
|
||
function createPool(options: Partial<Tinypool['options']>) { | ||
const pool = new Tinypool({ | ||
filename: path.resolve(__dirname, 'fixtures/eval.js'), | ||
minThreads: 1, | ||
maxThreads: 1, | ||
...options, | ||
}) | ||
|
||
return pool | ||
} |