fix: recover auction finalization across worker restarts

This commit is contained in:
2026-07-31 11:59:02 +00:00
parent 439e4272e0
commit 1345aa25a1
8 changed files with 1202 additions and 146 deletions
@@ -0,0 +1,35 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { createPollingWorkerControl, waitForWorkerPoll } from '../src/services/pollingWorkerLifecycle.js';
afterEach(() => {
vi.useRealTimers();
});
describe('polling worker lifecycle', () => {
it('merges repeated process signals and external abort into one idempotent stop signal', () => {
const external = new AbortController();
const control = createPollingWorkerControl(external.signal);
const aborts = vi.fn();
control.signal.addEventListener('abort', aborts);
process.emit('SIGTERM');
process.emit('SIGINT');
external.abort();
expect(control.signal.aborted).toBe(true);
expect(aborts).toHaveBeenCalledTimes(1);
control.dispose();
});
it('interrupts an idle poll without canceling caller-owned in-flight work', async () => {
vi.useFakeTimers();
const external = new AbortController();
const control = createPollingWorkerControl(external.signal);
const wait = waitForWorkerPoll(control.signal, 60_000);
external.abort();
await expect(wait).resolves.toBeUndefined();
control.dispose();
});
});