From e0bdd44cdb0be602f6510ce7e311b7f70abe16a5 Mon Sep 17 00:00:00 2001 From: Devin Ivy Date: Tue, 7 Apr 2026 00:01:33 -0400 Subject: [PATCH] test: error handling for dedicated and pool workers --- test/error.test.ts | 23 +++++++++++++++++++++++ test/fixtures/math.ts | 3 +++ 2 files changed, 26 insertions(+) create mode 100644 test/error.test.ts diff --git a/test/error.test.ts b/test/error.test.ts new file mode 100644 index 0000000..0ee321e --- /dev/null +++ b/test/error.test.ts @@ -0,0 +1,23 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert/strict'; +import { workerPool } from 'moroutine'; +import { fail } from './fixtures/math.ts'; + +describe('error handling', () => { + it('rejects with error from dedicated worker', async () => { + await assert.rejects(() => fail('boom').then((x) => x), { + message: 'boom', + }); + }); + + it('rejects with error from pool worker', async () => { + const run = workerPool(1); + try { + await assert.rejects(() => run(fail('pool boom')), { + message: 'pool boom', + }); + } finally { + run[Symbol.dispose](); + } + }); +}); diff --git a/test/fixtures/math.ts b/test/fixtures/math.ts index 53d9594..2ff285d 100644 --- a/test/fixtures/math.ts +++ b/test/fixtures/math.ts @@ -2,3 +2,6 @@ import { mo } from 'moroutine'; export const double = mo(import.meta, (x: number) => 2 * x); export const add = mo(import.meta, (a: number, b: number) => a + b); +export const fail = mo(import.meta, (msg: string) => { + throw new Error(msg); +}); -- 2.51.2