Files
lolympus-tournament-support/apps/api/src/modules/global/redis/redis.service.spec.ts
T
dahyeon 4b8ccf0077 fix: harden result polling and Redis 8.10 operations
Preserve tournament result jobs through lock contention and transient failures,
atomically schedule retries before acknowledgement, and publish initial polls
after releasing the preparation lock.

Fix Redis connection blocking, durability Hash cleanup, duplicate auction
request ordering, and scheduled-job promotion. Use native Redis 8.10 stream,
lock, counter, and field-expiring cache operations with invalidation fencing.

Repair 90 test type errors and add a repeatable API typecheck command.

Validation: 704 API tests, 129 web tests, 31 real Redis integration tests,
3 dependency checks, workspace type checks and builds, and changed-file lint.
2026-11-09 17:33:13 +09:00

73 lines
1.9 KiB
TypeScript

import { RedisService } from './redis.service';
function createRedisService(client: Record<string, unknown>) {
return new RedisService(client as never);
}
describe('RedisService stream pending recovery', () => {
it('destroys a dedicated client when connection startup fails without closing the shared client', async () => {
const error = new Error('connection failed');
const dedicated = {
on: jest.fn(),
connect: jest.fn().mockRejectedValue(error),
isOpen: true,
destroy: jest.fn(),
};
const shared = {
duplicate: jest.fn().mockReturnValue(dedicated),
destroy: jest.fn(),
};
const service = createRedisService(shared);
await expect(service.createDedicatedConnection()).rejects.toBe(error);
expect(dedicated.destroy).toHaveBeenCalledTimes(1);
expect(shared.destroy).not.toHaveBeenCalled();
});
it('normalizes XAUTOCLAIM array replies into stream entries', async () => {
const sendCommand = jest
.fn()
.mockResolvedValue([
'0-0',
[
[
'1700000000000-0',
['job', '{"kind":"poll-tournament-result"}', 'source', 'test'],
],
],
]);
const service = createRedisService({ sendCommand });
await expect(
service.claimStalePendingStreamMessages({
key: 'riot:queue:high',
group: 'riot-refresh-worker',
consumer: 'worker-1',
stalePendingMessageMinimumIdleMilliseconds: 1_800_000,
count: 1,
}),
).resolves.toEqual({
nextStartId: '0-0',
messages: [
{
id: '1700000000000-0',
message: {
job: '{"kind":"poll-tournament-result"}',
source: 'test',
},
},
],
});
expect(sendCommand).toHaveBeenCalledWith([
'XAUTOCLAIM',
'riot:queue:high',
'riot-refresh-worker',
'worker-1',
'1800000',
'0-0',
'COUNT',
'1',
]);
});
});