Skip to content

Commit

Permalink
fix: ensureMinimumWorkers in isolateWorkers
Browse files Browse the repository at this point in the history
  • Loading branch information
Aslemammad committed Jun 24, 2022
1 parent 25b7629 commit 601486e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ class ThreadPool {
// When `isolateWorkers` is enabled, remove the worker after task is finished
if (this.options.isolateWorkers && taskInfo.workerInfo) {
this._removeWorker(taskInfo.workerInfo)
this._ensureMinimumWorkers()
}
},
signal,
Expand Down
11 changes: 3 additions & 8 deletions test/simple.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,13 @@ test('workerId for each thread, that does not go more than maxThreads', async ()
minThreads: 2,
maxThreads: 2,
})
await pool.destroy()

expect(pool.run({ slow: true })).resolves.toBe(1)
await sleep(10)
expect(pool.run({ slow: true })).resolves.toBe(2)
await sleep(10)
expect(pool.run({ slow: true })).resolves.toBe(1)
await sleep(10)
expect(pool.run({ slow: false })).resolves.toBe(2)
expect(pool.run({ slow: true })).resolves.toBe(1)
expect(pool.run({ slow: true })).resolves.toBe(2)

// await pool.destroy()
await sleep(300)
await sleep(500)
})

test('workerId should never be more than maxThreads=1', async () => {
Expand Down

0 comments on commit 601486e

Please sign in to comment.