-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
terminateTimeout
option (#50)
- Loading branch information
1 parent
d5e5738
commit 95d148c
Showing
3 changed files
with
74 additions
and
14 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 { dirname, resolve } from 'path' | ||
import { Tinypool } from 'tinypool' | ||
import { fileURLToPath } from 'url' | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)) | ||
const cleanups: (() => Promise<unknown>)[] = [] | ||
|
||
afterEach(async () => { | ||
await Promise.all(cleanups.splice(0).map((cleanup) => cleanup())) | ||
}) | ||
|
||
test('termination timeout throws when worker does not terminate in time', async () => { | ||
const pool = new Tinypool({ | ||
filename: resolve(__dirname, 'fixtures/sleep.js'), | ||
terminateTimeout: 10, | ||
minThreads: 1, | ||
maxThreads: 2, | ||
isolateWorkers: true, | ||
}) | ||
|
||
expect(pool.threads.length).toBe(1) | ||
|
||
const worker = pool.threads[0] | ||
expect(worker).toBeTruthy() | ||
|
||
cleanups.push(worker!.terminate.bind(worker)) | ||
worker!.terminate = () => new Promise(() => {}) | ||
|
||
await expect(pool.run('default')).rejects.toThrowError( | ||
'Failed to terminate worker' | ||
) | ||
}) |