Serialize lifecycle changes and make cancellation, deadlines, and match side effects recoverable and idempotent. Archive accepted bids durably, quarantine invalid payloads, and preserve compatibility with empty round IDs. Synchronize HTTP polling and socket state with scoped resync events. Add cancellation cleanup index migration and regression coverage. Validated with 744 API tests, 65 Redis integration tests, and 28 Mongo integration tests.
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import { AuctionLifecycleLock } from './auction-lifecycle-lock';
|
|
|
|
afterEach(() => jest.useRealTimers());
|
|
|
|
it('renews ownership and handles renewal/release failures without unhandled rejection', async () => {
|
|
jest.useFakeTimers();
|
|
const sendCommand = jest
|
|
.fn()
|
|
.mockRejectedValue(new Error('redis disconnected'));
|
|
const releaseTokenLock = jest
|
|
.fn()
|
|
.mockRejectedValue(new Error('release failed'));
|
|
const lock = new AuctionLifecycleLock({
|
|
acquireTokenLock: jest.fn().mockResolvedValue(true),
|
|
releaseTokenLock,
|
|
raw: () => ({ sendCommand }),
|
|
} as never);
|
|
const result = lock.run('match', async () => {
|
|
await jest.advanceTimersByTimeAsync(10000);
|
|
});
|
|
await expect(result).rejects.toThrow('redis disconnected');
|
|
expect(releaseTokenLock).toHaveBeenCalledTimes(1);
|
|
expect(jest.getTimerCount()).toBe(0);
|
|
});
|
|
|
|
it('preserves an operation result if only lock release fails', async () => {
|
|
const lock = new AuctionLifecycleLock({
|
|
acquireTokenLock: jest.fn().mockResolvedValue(true),
|
|
releaseTokenLock: jest.fn().mockRejectedValue(new Error('release failed')),
|
|
} as never);
|
|
await expect(lock.run('match', async () => 42)).resolves.toBe(42);
|
|
});
|