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); });