fix: harden multi-instance scheduler and worker execution
This commit is contained in:
1 parent
df7dcd3a9c
commit
60a006008a
23 files changed
+1442
-299
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import mongoose from 'mongoose';
|
||||
import type { MatchDocument } from '../global/database/schema';
|
||||
import { DistributedLockService } from '../global/redis/distributed-lock.service';
|
||||
import type { RiotMatchDto } from '../riot/riot.types';
|
||||
import { TournamentResultService } from './tournament-result.service';
|
||||
|
||||
@@ -16,15 +17,38 @@ type TournamentResultServiceInternals = TournamentResultService & {
|
||||
};
|
||||
|
||||
function createService() {
|
||||
const distributedLockService = createDistributedLockService();
|
||||
return new TournamentResultService(
|
||||
{} as never,
|
||||
{} as never,
|
||||
{} as never,
|
||||
{} as never,
|
||||
{} as never,
|
||||
distributedLockService as never,
|
||||
) as unknown as TournamentResultServiceInternals;
|
||||
}
|
||||
|
||||
function createDistributedLockService() {
|
||||
return {
|
||||
runWithLock: jest.fn().mockImplementation(async (options, operation) =>
|
||||
operation({
|
||||
lockKey: options.lockKey,
|
||||
lockOwnershipToken: 'lock-owner',
|
||||
lockExpirationDurationMilliseconds:
|
||||
options.lockExpirationDurationMilliseconds,
|
||||
}),
|
||||
),
|
||||
runWithRenewedLock: jest.fn().mockImplementation(async (options, operation) =>
|
||||
operation({
|
||||
lockKey: options.lockKey,
|
||||
lockOwnershipToken: 'lock-owner',
|
||||
lockExpirationDurationMilliseconds:
|
||||
options.lockExpirationDurationMilliseconds,
|
||||
}),
|
||||
),
|
||||
} as unknown as jest.Mocked<DistributedLockService>;
|
||||
}
|
||||
|
||||
interface MatchOverrides {
|
||||
gameCount?: number;
|
||||
gameMode?: 'pair' | 'bracket' | 'round-robin';
|
||||
@@ -281,12 +305,14 @@ describe('TournamentResultService tournament code polling', () => {
|
||||
const riotJobQueueService = {
|
||||
enqueueTournamentResultPoll: jest.fn().mockResolvedValue(undefined),
|
||||
};
|
||||
const distributedLockService = createDistributedLockService();
|
||||
const service = new TournamentResultService(
|
||||
connectionService as never,
|
||||
riotMatchService as never,
|
||||
riotJobQueueService as never,
|
||||
{ invalidateCommunity: jest.fn().mockResolvedValue(undefined) } as never,
|
||||
{ buildAndUpsert: jest.fn().mockResolvedValue(undefined) } as never,
|
||||
distributedLockService as never,
|
||||
);
|
||||
|
||||
return { service, match, code, riotMatchService };
|
||||
@@ -455,12 +481,14 @@ describe('TournamentResultService manual result collection', () => {
|
||||
getMatchIdsByPuuid: jest.fn().mockResolvedValue(['KR_1234567890']),
|
||||
getMatch: jest.fn().mockResolvedValue(detail),
|
||||
};
|
||||
const distributedLockService = createDistributedLockService();
|
||||
const service = new TournamentResultService(
|
||||
connectionService as never,
|
||||
riotMatchService as never,
|
||||
{} as never,
|
||||
{ invalidateCommunity: jest.fn().mockResolvedValue(undefined) } as never,
|
||||
{ buildAndUpsert: jest.fn().mockResolvedValue(undefined) } as never,
|
||||
distributedLockService as never,
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user