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,3 +1,4 @@
|
||||
import { DistributedLockService } from '../global/redis/distributed-lock.service';
|
||||
import { TournamentCodeScheduler } from './tournament-code.scheduler';
|
||||
|
||||
describe('TournamentCodeScheduler', () => {
|
||||
@@ -18,16 +19,28 @@ describe('TournamentCodeScheduler', () => {
|
||||
scheduleInitialPoll:
|
||||
params?.scheduleInitialPoll ?? jest.fn().mockResolvedValue(null),
|
||||
};
|
||||
const distributedLockService = {
|
||||
runWithRenewedLock: jest.fn().mockImplementation(async (options, operation) =>
|
||||
operation({
|
||||
lockKey: options.lockKey,
|
||||
lockOwnershipToken: 'lock-owner',
|
||||
lockExpirationDurationMilliseconds:
|
||||
options.lockExpirationDurationMilliseconds,
|
||||
}),
|
||||
),
|
||||
} as unknown as jest.Mocked<DistributedLockService>;
|
||||
const scheduler = new TournamentCodeScheduler(
|
||||
tournamentCodeService as never,
|
||||
autoProvisionService as never,
|
||||
tournamentResultService as never,
|
||||
distributedLockService as never,
|
||||
) as unknown as { attachPending(): Promise<void> };
|
||||
|
||||
return {
|
||||
scheduler,
|
||||
tournamentCodeService,
|
||||
tournamentResultService,
|
||||
distributedLockService,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -59,4 +72,16 @@ describe('TournamentCodeScheduler', () => {
|
||||
|
||||
expect(tournamentResultService.scheduleInitialPoll).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not attach pending tournament codes when another instance owns the scheduler lock', async () => {
|
||||
const { scheduler, tournamentCodeService, distributedLockService } =
|
||||
createScheduler();
|
||||
distributedLockService.runWithRenewedLock.mockResolvedValueOnce(null);
|
||||
|
||||
await scheduler.attachPending();
|
||||
|
||||
expect(
|
||||
tournamentCodeService.attachPendingMatchDocuments,
|
||||
).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user