fix: fully cancel redis auctions

This commit is contained in:
dahyeon committed 2026-06-23 03:34:45 -07:00
1 parent e8bb20d988
commit 7c372f0392
3 files changed
+221 -107

No files matched your search

@@ -1870,7 +1870,7 @@ describe('AuctionService', () => {
expect(session.commitTransaction).toHaveBeenCalledTimes(1);
});
it('uses Redis transition when resetting a redis-v1 auction', async () => {
it('fully deletes redis-v1 auction data when cancelling an auction', async () => {
const matchId = new mongoose.Types.ObjectId();
const communityId = new mongoose.Types.ObjectId();
const auctionId = new mongoose.Types.ObjectId();
@@ -1889,58 +1889,37 @@ describe('AuctionService', () => {
deleteOne: jest.fn().mockResolvedValue(undefined),
};
const match = {
gameSchedule: [{ gameNumber: 1, teamAIndex: 1, teamBIndex: 2 }],
communityId,
status: 'team-built',
teams: [],
tournamentCodeIds: [],
gameSchedule: [],
participants: [],
teams: [{ teamIndex: 1 }],
tournamentCodeIds: [new mongoose.Types.ObjectId()],
participants: [{ excluded: true }, { excluded: false }],
result: { games: [] },
resultPollState: { state: 'polling' },
teamBuiltAt: new Date(),
save: jest.fn().mockResolvedValue(undefined),
};
const currentRedisState = {
auctionLifecycleId: 'life-1',
auctionPlayerOrder: [{ userId: 'player-1', passCount: 0 }],
auctionTeams: [
{
captainUserId: new mongoose.Types.ObjectId(),
members: [],
remainingBidPointAmount: 1000,
teamIndex: 1,
},
],
bidRoundExtensionSeconds: 5,
currentAuctionHistorySequence: 4,
currentAuctionPlayerOrderIndex: 0,
currentAuctionRound: 1,
currentBidRoundPlayerUserId: 'player-1',
currentHighestBidPointAmount: 20,
currentHighestBidderTeamIndex: 1,
initialTeamBidPointAmount: 1000,
maximumBidRoundDurationSeconds: 30,
passedAuctionPlayerQueue: [],
phase: 'bidding',
revision: 4,
topTierAuctionPriorityThreshold: 'NONE',
};
const resetRedisState = {
...currentRedisState,
auctionPlayerOrder: [],
auctionTeams: [],
currentAuctionHistorySequence: 5,
currentAuctionPlayerOrderIndex: 0,
currentHighestBidPointAmount: 0,
currentHighestBidderTeamIndex: -1,
matchSideEffectRevision: 1,
matchSideEffectStatus: 'pending',
phase: 'waiting',
revision: 5,
};
const { service, connectionService, auctionRedisCommandService, auctionRedisStateReaderService } = createService({
const sideEffectDeleteMany = jest.fn().mockReturnValue({
session: jest.fn().mockResolvedValue(undefined),
});
const {
service,
connectionService,
tournamentCodeService,
tournamentResultService,
auctionHistoryModel,
auctionRedisCommandService,
auctionRedisService,
} = createService({
auction: {
findOne: jest.fn().mockReturnValue({
session: jest.fn().mockResolvedValue(auction),
}),
},
auctionSideEffectApplication: {
deleteMany: sideEffectDeleteMany,
},
match: {
findById: jest.fn().mockReturnValue({
session: jest.fn().mockResolvedValue(match),
@@ -1948,9 +1927,10 @@ describe('AuctionService', () => {
},
});
connectionService.createSession.mockResolvedValue(session);
auctionRedisStateReaderService.readAuctionStateView
.mockResolvedValueOnce(currentRedisState)
.mockResolvedValueOnce(resetRedisState);
const redisClient = auctionRedisService.raw();
redisClient.sendCommand
.mockResolvedValueOnce(1)
.mockResolvedValueOnce(['0', []]);
await service.reset({
auctionActionRequestId: '00000000-0000-4000-8000-000000000080',
@@ -1963,46 +1943,39 @@ describe('AuctionService', () => {
communityId,
});
expect(auction.deleteOne).not.toHaveBeenCalled();
expect(match.save).not.toHaveBeenCalled();
expect(auctionRedisCommandService.reserveActionRequest).toHaveBeenCalledWith(
matchId.toString(),
expect.objectContaining({
auctionActionRequestId: '00000000-0000-4000-8000-000000000080',
auctionStateTransitionId:
'reset:life-1:00000000-0000-4000-8000-000000000080',
clientObservedAuctionLifecycleId: 'life-1',
clientObservedCurrentAuctionPlayerOrderIndex: 0,
clientObservedCurrentBidRoundPlayerUserId: 'player-1',
clientObservedPhase: 'bidding',
clientObservedRevision: 4,
}),
);
expect(auctionRedisCommandService.applyTransition).toHaveBeenCalledTimes(1);
const transitionInput =
auctionRedisCommandService.applyTransition.mock.calls[0][1];
expect(transitionInput.deadline).toEqual({ mode: 'remove' });
expect(transitionInput.expectedPhase).toBe('bidding');
expect(transitionInput.liveStatePatch).toMatchObject({
currentBidRoundDeadlineTimestampMS: 0,
currentBidRoundPlayerUserId: '',
currentHighestBidPointAmount: 0,
currentHighestBidderTeamIndex: -1,
matchSideEffectRevision: 1,
matchSideEffectStatus: 'pending',
phase: 'waiting',
'team:1:assignedAuctionTeamMemberCount': 0,
'team:1:remainingBidPointAmount': 0,
expect(
auctionRedisCommandService.reserveActionRequest,
).not.toHaveBeenCalled();
expect(auctionRedisCommandService.applyTransition).not.toHaveBeenCalled();
expect(tournamentCodeService.releaseFromMatch).toHaveBeenCalledWith(match);
expect(tournamentResultService.cancelPolling).toHaveBeenCalledWith(match);
expect(match).toMatchObject({
gameSchedule: [],
result: undefined,
resultPollState: undefined,
status: 'recruiting',
teamBuiltAt: undefined,
teams: [],
tournamentCodeIds: [],
});
expect(transitionInput.shouldResetBidRuntime).toBe(true);
const durabilityPayload = JSON.parse(
transitionInput.durabilityPayloadJson,
);
expect(durabilityPayload).toMatchObject({
auctionActionType: 'reset',
historyMutation: { resetMode: 'clear-history', type: 'reset' },
matchSideEffectMutation: { type: 'resetMatchAfterAuctionReset' },
expect(match.participants).toEqual([
{ excluded: false },
{ excluded: false },
]);
expect(match.save).toHaveBeenCalledWith({ session });
expect(sideEffectDeleteMany).toHaveBeenCalledWith({ auctionId });
expect(auctionHistoryModel.deleteMany).toHaveBeenCalledWith({
auctionId,
});
expect(auction.deleteOne).toHaveBeenCalledWith({ session });
expect(redisClient.sendCommand).toHaveBeenCalledWith(
expect.arrayContaining([
'auction:bidRoundDeadlineQueue',
matchId.toString(),
'life-1',
]),
);
expect(session.commitTransaction).toHaveBeenCalledTimes(1);
});
it('undoes to a history snapshot and releases resources when leaving complete', async () => {