Skip to content

Commit b13a9c8

Browse files
committed
test: fix async kill handler test to properly await and verify completion
- Make test async to properly await kill handler promise - Add sendToMainWorker stub to verify kill success message - Add sleep to wait for async handler completion - Update CI workflow step names for consistency
1 parent b97f368 commit b13a9c8

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
if: ${{ matrix.os == 'ubuntu-latest' && matrix.deno == 'v2.x' }}
4848
run: deno task lint
4949

50-
- name: Tests with Coverage
50+
- name: Tests & Coverage
5151
run: deno task test:coverage
5252

5353
- name: Bundle

.github/workflows/release-please.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
- name: Lint
5454
run: deno task lint
5555

56-
- name: Tests with Coverage
56+
- name: Tests & Coverage
5757
run: deno task test:coverage
5858

5959
- name: Bundle

tests/worker/abstract-worker.test.mjs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { expect } from '@std/expect'
22
import { describe, it } from '@std/testing/bdd'
3-
import { assertSpyCalls, stub } from '@std/testing/mock'
3+
import { assertSpyCall, assertSpyCalls, stub } from '@std/testing/mock'
44
import {
55
KillBehaviors,
66
ThreadWorker,
77
WorkerChoiceStrategies,
88
} from '../../src/mod.ts'
99
import { DEFAULT_TASK_NAME, EMPTY_FUNCTION } from '../../src/utils.ts'
10+
import { sleep } from '../test-utils.mjs'
1011

1112
describe('Abstract worker test suite', () => {
1213
it('Verify worker options default values', () => {
@@ -231,13 +232,18 @@ describe('Abstract worker test suite', () => {
231232
)
232233
})
233234

234-
it('Verify that async kill handler is called when worker is killed', () => {
235+
it('Verify that async kill handler is called when worker is killed', async () => {
235236
const killHandlerStub = stub(() => {})
236237
const worker = new ThreadWorker(() => {}, {
237238
killHandler: async () => await Promise.resolve(killHandlerStub()),
238239
})
240+
const sendToMainWorkerStub = stub(worker, 'sendToMainWorker')
239241
worker.handleKillMessage()
242+
await sleep(10)
240243
assertSpyCalls(killHandlerStub, 1)
244+
assertSpyCalls(sendToMainWorkerStub, 1)
245+
assertSpyCall(sendToMainWorkerStub, 0, { args: [{ kill: 'success' }] })
246+
sendToMainWorkerStub.restore()
241247
killHandlerStub.restore()
242248
})
243249

0 commit comments

Comments
 (0)