fix: fully cancel redis auctions
This commit is contained in:
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);
|
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 matchId = new mongoose.Types.ObjectId();
|
||||||
const communityId = new mongoose.Types.ObjectId();
|
const communityId = new mongoose.Types.ObjectId();
|
||||||
const auctionId = new mongoose.Types.ObjectId();
|
const auctionId = new mongoose.Types.ObjectId();
|
||||||
@@ -1889,58 +1889,37 @@ describe('AuctionService', () => {
|
|||||||
deleteOne: jest.fn().mockResolvedValue(undefined),
|
deleteOne: jest.fn().mockResolvedValue(undefined),
|
||||||
};
|
};
|
||||||
const match = {
|
const match = {
|
||||||
|
gameSchedule: [{ gameNumber: 1, teamAIndex: 1, teamBIndex: 2 }],
|
||||||
communityId,
|
communityId,
|
||||||
status: 'team-built',
|
status: 'team-built',
|
||||||
teams: [],
|
teams: [{ teamIndex: 1 }],
|
||||||
tournamentCodeIds: [],
|
tournamentCodeIds: [new mongoose.Types.ObjectId()],
|
||||||
gameSchedule: [],
|
participants: [{ excluded: true }, { excluded: false }],
|
||||||
participants: [],
|
result: { games: [] },
|
||||||
|
resultPollState: { state: 'polling' },
|
||||||
|
teamBuiltAt: new Date(),
|
||||||
save: jest.fn().mockResolvedValue(undefined),
|
save: jest.fn().mockResolvedValue(undefined),
|
||||||
};
|
};
|
||||||
const currentRedisState = {
|
const sideEffectDeleteMany = jest.fn().mockReturnValue({
|
||||||
auctionLifecycleId: 'life-1',
|
session: jest.fn().mockResolvedValue(undefined),
|
||||||
auctionPlayerOrder: [{ userId: 'player-1', passCount: 0 }],
|
});
|
||||||
auctionTeams: [
|
const {
|
||||||
{
|
service,
|
||||||
captainUserId: new mongoose.Types.ObjectId(),
|
connectionService,
|
||||||
members: [],
|
tournamentCodeService,
|
||||||
remainingBidPointAmount: 1000,
|
tournamentResultService,
|
||||||
teamIndex: 1,
|
auctionHistoryModel,
|
||||||
},
|
auctionRedisCommandService,
|
||||||
],
|
auctionRedisService,
|
||||||
bidRoundExtensionSeconds: 5,
|
} = createService({
|
||||||
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({
|
|
||||||
auction: {
|
auction: {
|
||||||
findOne: jest.fn().mockReturnValue({
|
findOne: jest.fn().mockReturnValue({
|
||||||
session: jest.fn().mockResolvedValue(auction),
|
session: jest.fn().mockResolvedValue(auction),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
auctionSideEffectApplication: {
|
||||||
|
deleteMany: sideEffectDeleteMany,
|
||||||
|
},
|
||||||
match: {
|
match: {
|
||||||
findById: jest.fn().mockReturnValue({
|
findById: jest.fn().mockReturnValue({
|
||||||
session: jest.fn().mockResolvedValue(match),
|
session: jest.fn().mockResolvedValue(match),
|
||||||
@@ -1948,9 +1927,10 @@ describe('AuctionService', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
connectionService.createSession.mockResolvedValue(session);
|
connectionService.createSession.mockResolvedValue(session);
|
||||||
auctionRedisStateReaderService.readAuctionStateView
|
const redisClient = auctionRedisService.raw();
|
||||||
.mockResolvedValueOnce(currentRedisState)
|
redisClient.sendCommand
|
||||||
.mockResolvedValueOnce(resetRedisState);
|
.mockResolvedValueOnce(1)
|
||||||
|
.mockResolvedValueOnce(['0', []]);
|
||||||
|
|
||||||
await service.reset({
|
await service.reset({
|
||||||
auctionActionRequestId: '00000000-0000-4000-8000-000000000080',
|
auctionActionRequestId: '00000000-0000-4000-8000-000000000080',
|
||||||
@@ -1963,46 +1943,39 @@ describe('AuctionService', () => {
|
|||||||
communityId,
|
communityId,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(auction.deleteOne).not.toHaveBeenCalled();
|
expect(
|
||||||
expect(match.save).not.toHaveBeenCalled();
|
auctionRedisCommandService.reserveActionRequest,
|
||||||
expect(auctionRedisCommandService.reserveActionRequest).toHaveBeenCalledWith(
|
).not.toHaveBeenCalled();
|
||||||
matchId.toString(),
|
expect(auctionRedisCommandService.applyTransition).not.toHaveBeenCalled();
|
||||||
expect.objectContaining({
|
expect(tournamentCodeService.releaseFromMatch).toHaveBeenCalledWith(match);
|
||||||
auctionActionRequestId: '00000000-0000-4000-8000-000000000080',
|
expect(tournamentResultService.cancelPolling).toHaveBeenCalledWith(match);
|
||||||
auctionStateTransitionId:
|
expect(match).toMatchObject({
|
||||||
'reset:life-1:00000000-0000-4000-8000-000000000080',
|
gameSchedule: [],
|
||||||
clientObservedAuctionLifecycleId: 'life-1',
|
result: undefined,
|
||||||
clientObservedCurrentAuctionPlayerOrderIndex: 0,
|
resultPollState: undefined,
|
||||||
clientObservedCurrentBidRoundPlayerUserId: 'player-1',
|
status: 'recruiting',
|
||||||
clientObservedPhase: 'bidding',
|
teamBuiltAt: undefined,
|
||||||
clientObservedRevision: 4,
|
teams: [],
|
||||||
}),
|
tournamentCodeIds: [],
|
||||||
);
|
|
||||||
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(transitionInput.shouldResetBidRuntime).toBe(true);
|
expect(match.participants).toEqual([
|
||||||
const durabilityPayload = JSON.parse(
|
{ excluded: false },
|
||||||
transitionInput.durabilityPayloadJson,
|
{ excluded: false },
|
||||||
);
|
]);
|
||||||
expect(durabilityPayload).toMatchObject({
|
expect(match.save).toHaveBeenCalledWith({ session });
|
||||||
auctionActionType: 'reset',
|
expect(sideEffectDeleteMany).toHaveBeenCalledWith({ auctionId });
|
||||||
historyMutation: { resetMode: 'clear-history', type: 'reset' },
|
expect(auctionHistoryModel.deleteMany).toHaveBeenCalledWith({
|
||||||
matchSideEffectMutation: { type: 'resetMatchAfterAuctionReset' },
|
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 () => {
|
it('undoes to a history snapshot and releases resources when leaving complete', async () => {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
AuctionPlayerSnapshot,
|
AuctionPlayerSnapshot,
|
||||||
AuctionTeam,
|
AuctionTeam,
|
||||||
AuctionTopTierThreshold,
|
AuctionTopTierThreshold,
|
||||||
|
MatchDocument,
|
||||||
MatchParticipant,
|
MatchParticipant,
|
||||||
MatchTeamMember,
|
MatchTeamMember,
|
||||||
Position,
|
Position,
|
||||||
@@ -1128,16 +1129,18 @@ export class AuctionService {
|
|||||||
const AuctionModel = await this.connectionService.getModel('auction');
|
const AuctionModel = await this.connectionService.getModel('auction');
|
||||||
const AuctionHistoryModel =
|
const AuctionHistoryModel =
|
||||||
await this.connectionService.getModel('auctionHistory');
|
await this.connectionService.getModel('auctionHistory');
|
||||||
|
const AuctionSideEffectApplicationModel =
|
||||||
|
await this.connectionService.getModel('auctionSideEffectApplication');
|
||||||
const MatchModel = await this.connectionService.getModel('match');
|
const MatchModel = await this.connectionService.getModel('match');
|
||||||
|
|
||||||
const session = await this.connectionService.createSession();
|
const session = await this.connectionService.createSession();
|
||||||
if (!session) {
|
if (!session) {
|
||||||
throw new InternalServerErrorException('Failed to start DB session.');
|
throw new InternalServerErrorException('Failed to start DB session.');
|
||||||
}
|
}
|
||||||
let redisResetContext:
|
let redisRuntimeToClear:
|
||||||
| {
|
| {
|
||||||
actionRequestParams?: AuctionStructureActionRequestParams;
|
auctionLifecycleId?: string;
|
||||||
auction: AuctionDocument;
|
matchId: string;
|
||||||
}
|
}
|
||||||
| null = null;
|
| null = null;
|
||||||
try {
|
try {
|
||||||
@@ -1154,10 +1157,18 @@ export class AuctionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.isRedisV1Auction(auction)) {
|
if (this.isRedisV1Auction(auction)) {
|
||||||
redisResetContext = {
|
redisRuntimeToClear = {
|
||||||
auction,
|
auctionLifecycleId: auction.auctionLifecycleId,
|
||||||
actionRequestParams: params,
|
matchId: params.matchId.toString(),
|
||||||
};
|
};
|
||||||
|
await this.resetMatchAfterAuctionCancellation(match, session);
|
||||||
|
await AuctionSideEffectApplicationModel.deleteMany({
|
||||||
|
auctionId: auction._id,
|
||||||
|
}).session(session);
|
||||||
|
await AuctionHistoryModel.deleteMany({ auctionId: auction._id }).session(
|
||||||
|
session,
|
||||||
|
);
|
||||||
|
await auction.deleteOne({ session });
|
||||||
} else {
|
} else {
|
||||||
await auction.deleteOne({ session });
|
await auction.deleteOne({ session });
|
||||||
await AuctionHistoryModel.deleteMany({ auctionId: auction._id }).session(
|
await AuctionHistoryModel.deleteMany({ auctionId: auction._id }).session(
|
||||||
@@ -1186,8 +1197,11 @@ export class AuctionService {
|
|||||||
await session.endSession();
|
await session.endSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (redisResetContext) {
|
if (redisRuntimeToClear) {
|
||||||
await this.resetRedisAuction(redisResetContext);
|
await this.clearRedisAuctionRuntimeForLifecycle(
|
||||||
|
redisRuntimeToClear.matchId,
|
||||||
|
redisRuntimeToClear.auctionLifecycleId,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2223,6 +2237,25 @@ export class AuctionService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async resetMatchAfterAuctionCancellation(
|
||||||
|
match: MatchDocument,
|
||||||
|
session: mongoose.ClientSession,
|
||||||
|
): Promise<void> {
|
||||||
|
await this.tournamentCodeService.releaseFromMatch(match);
|
||||||
|
await this.tournamentResultService.cancelPolling(match);
|
||||||
|
match.status = 'recruiting';
|
||||||
|
match.teams = [];
|
||||||
|
match.tournamentCodeIds = [];
|
||||||
|
match.gameSchedule = [];
|
||||||
|
match.participants.forEach((participant) => {
|
||||||
|
participant.excluded = false;
|
||||||
|
});
|
||||||
|
match.teamBuiltAt = undefined;
|
||||||
|
match.result = undefined;
|
||||||
|
match.resultPollState = undefined;
|
||||||
|
await match.save({ session });
|
||||||
|
}
|
||||||
|
|
||||||
private assertLiveAuctionOperationSupported(auction: AuctionDocument): void {
|
private assertLiveAuctionOperationSupported(auction: AuctionDocument): void {
|
||||||
if (auction.auctionEngineVersion && !this.isRedisV1Auction(auction)) {
|
if (auction.auctionEngineVersion && !this.isRedisV1Auction(auction)) {
|
||||||
throw new BadRequestException(
|
throw new BadRequestException(
|
||||||
@@ -2385,13 +2418,13 @@ export class AuctionService {
|
|||||||
expectedAuctionLifecycleId?: string,
|
expectedAuctionLifecycleId?: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const keys = buildAuctionRedisKeys(matchId);
|
const keys = buildAuctionRedisKeys(matchId);
|
||||||
await this.auctionRedisService.raw().sendCommand([
|
const cleared = await this.auctionRedisService.raw().sendCommand([
|
||||||
'EVAL',
|
'EVAL',
|
||||||
[
|
[
|
||||||
"local expectedAuctionLifecycleId = ARGV[2]",
|
"local expectedAuctionLifecycleId = ARGV[2]",
|
||||||
"if expectedAuctionLifecycleId ~= '' then",
|
"if expectedAuctionLifecycleId ~= '' then",
|
||||||
" local currentAuctionLifecycleId = redis.call('HGET', KEYS[1], 'auctionLifecycleId')",
|
" local currentAuctionLifecycleId = redis.call('HGET', KEYS[1], 'auctionLifecycleId')",
|
||||||
" if currentAuctionLifecycleId ~= expectedAuctionLifecycleId then",
|
" if currentAuctionLifecycleId and currentAuctionLifecycleId ~= expectedAuctionLifecycleId then",
|
||||||
" return 0",
|
" return 0",
|
||||||
' end',
|
' end',
|
||||||
'end',
|
'end',
|
||||||
@@ -2414,6 +2447,75 @@ export class AuctionService {
|
|||||||
matchId,
|
matchId,
|
||||||
expectedAuctionLifecycleId ?? '',
|
expectedAuctionLifecycleId ?? '',
|
||||||
]);
|
]);
|
||||||
|
if (Number(cleared) !== 1) return;
|
||||||
|
await this.clearRedisDurabilityPayloadsForLifecycle(
|
||||||
|
keys,
|
||||||
|
expectedAuctionLifecycleId,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async clearRedisDurabilityPayloadsForLifecycle(
|
||||||
|
keys: ReturnType<typeof buildAuctionRedisKeys>,
|
||||||
|
expectedAuctionLifecycleId?: string,
|
||||||
|
): Promise<void> {
|
||||||
|
let cursor = '0';
|
||||||
|
do {
|
||||||
|
const reply = await this.auctionRedisService.raw().sendCommand([
|
||||||
|
'SCAN',
|
||||||
|
cursor,
|
||||||
|
'MATCH',
|
||||||
|
`${keys.durabilityPayloadKeyPrefix}*`,
|
||||||
|
'COUNT',
|
||||||
|
'100',
|
||||||
|
]);
|
||||||
|
if (!Array.isArray(reply) || reply.length < 2) return;
|
||||||
|
cursor = String(reply[0]);
|
||||||
|
const payloadKeys = Array.isArray(reply[1]) ? reply[1].map(String) : [];
|
||||||
|
if (payloadKeys.length === 0) continue;
|
||||||
|
|
||||||
|
const values = await this.auctionRedisService
|
||||||
|
.raw()
|
||||||
|
.sendCommand(['MGET', ...payloadKeys]);
|
||||||
|
const payloadKeysToDelete = payloadKeys.filter((payloadKey, index) =>
|
||||||
|
this.shouldDeleteRedisDurabilityPayload(
|
||||||
|
Array.isArray(values) ? values[index] : undefined,
|
||||||
|
expectedAuctionLifecycleId,
|
||||||
|
payloadKey,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (payloadKeysToDelete.length === 0) continue;
|
||||||
|
|
||||||
|
await this.auctionRedisService.raw().sendCommand([
|
||||||
|
'ZREM',
|
||||||
|
keys.durabilityRetryQueueKey,
|
||||||
|
...payloadKeysToDelete,
|
||||||
|
]);
|
||||||
|
await this.auctionRedisService.raw().sendCommand([
|
||||||
|
'ZREM',
|
||||||
|
keys.durabilityDeadLetterQueueKey,
|
||||||
|
...payloadKeysToDelete,
|
||||||
|
]);
|
||||||
|
await this.auctionRedisService.raw().sendCommand([
|
||||||
|
'DEL',
|
||||||
|
...payloadKeysToDelete,
|
||||||
|
]);
|
||||||
|
} while (cursor !== '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
private shouldDeleteRedisDurabilityPayload(
|
||||||
|
payloadValue: unknown,
|
||||||
|
expectedAuctionLifecycleId: string | undefined,
|
||||||
|
payloadKey: string,
|
||||||
|
): boolean {
|
||||||
|
if (!expectedAuctionLifecycleId) return true;
|
||||||
|
if (typeof payloadValue !== 'string') return false;
|
||||||
|
try {
|
||||||
|
const payload = JSON.parse(payloadValue) as Record<string, unknown>;
|
||||||
|
return payload.auctionLifecycleId === expectedAuctionLifecycleId;
|
||||||
|
} catch {
|
||||||
|
this.logger.warn(`Failed to parse auction durability payload ${payloadKey}.`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private enqueueBackgroundOrderEnrichment(params: {
|
private enqueueBackgroundOrderEnrichment(params: {
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ import { SecretService } from '../modules/global/secret/secret.service';
|
|||||||
type RedisClient = ReturnType<typeof createClient>;
|
type RedisClient = ReturnType<typeof createClient>;
|
||||||
|
|
||||||
const REHEARSAL_PREFIX = 'redis-sot-rehearsal';
|
const REHEARSAL_PREFIX = 'redis-sot-rehearsal';
|
||||||
const WAIT_FOR_EXPIRY_MS = 6200;
|
const WAIT_FOR_EXPIRY_POLL_INTERVAL_MS = 1000;
|
||||||
|
const WAIT_FOR_EXPIRY_TIMEOUT_MS = 20_000;
|
||||||
|
|
||||||
interface RehearsalResources {
|
interface RehearsalResources {
|
||||||
auctionIds: mongoose.Types.ObjectId[];
|
auctionIds: mongoose.Types.ObjectId[];
|
||||||
@@ -345,6 +346,27 @@ async function flushDurability(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function waitForDeadlineCompletion(
|
||||||
|
deadlineScheduler: AuctionDeadlineScheduler,
|
||||||
|
): Promise<void> {
|
||||||
|
const startedAt = Date.now();
|
||||||
|
let lastResult: Awaited<
|
||||||
|
ReturnType<AuctionDeadlineScheduler['processDueBidRoundDeadlines']>
|
||||||
|
> | null = null;
|
||||||
|
|
||||||
|
while (Date.now() - startedAt < WAIT_FOR_EXPIRY_TIMEOUT_MS) {
|
||||||
|
await new Promise((resolve) =>
|
||||||
|
setTimeout(resolve, WAIT_FOR_EXPIRY_POLL_INTERVAL_MS),
|
||||||
|
);
|
||||||
|
lastResult = await deadlineScheduler.processDueBidRoundDeadlines(20);
|
||||||
|
if (lastResult.completed >= 1) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
`Expected deadline completion, got ${JSON.stringify(lastResult)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function assertState(
|
function assertState(
|
||||||
state: Record<string, unknown> | null,
|
state: Record<string, unknown> | null,
|
||||||
expectedPhase: string,
|
expectedPhase: string,
|
||||||
@@ -508,14 +530,29 @@ async function main(): Promise<void> {
|
|||||||
auctionActionRequestId: randomUUID(),
|
auctionActionRequestId: randomUUID(),
|
||||||
});
|
});
|
||||||
await flushDurability(durabilityScheduler);
|
await flushDurability(durabilityScheduler);
|
||||||
logStep(`waiting ${WAIT_FOR_EXPIRY_MS}ms for Redis TIME deadline`);
|
const secondBiddingState = assertState(
|
||||||
await new Promise((resolve) => setTimeout(resolve, WAIT_FOR_EXPIRY_MS));
|
await auctionRedisStateReaderService.readAuctionStateView(
|
||||||
const deadlineResult = await deadlineScheduler.processDueBidRoundDeadlines(20);
|
resources.matchId.toString(),
|
||||||
if (deadlineResult.completed < 1) {
|
),
|
||||||
|
'bidding',
|
||||||
|
);
|
||||||
|
const secondBiddingKeys = buildAuctionRedisKeys(resources.matchId.toString());
|
||||||
|
const queuedDeadlineScore = await auctionRedisService.raw().sendCommand([
|
||||||
|
'ZSCORE',
|
||||||
|
secondBiddingKeys.deadlineQueueKey,
|
||||||
|
resources.matchId.toString(),
|
||||||
|
]);
|
||||||
|
if (!queuedDeadlineScore) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Expected deadline completion, got ${JSON.stringify(deadlineResult)}`,
|
`Expected deadline queue item after second open-bidding, state deadline=${String(
|
||||||
|
secondBiddingState.currentBidRoundDeadlineTimestampMS,
|
||||||
|
)}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
logStep(
|
||||||
|
`waiting up to ${WAIT_FOR_EXPIRY_TIMEOUT_MS}ms for Redis TIME deadline`,
|
||||||
|
);
|
||||||
|
await waitForDeadlineCompletion(deadlineScheduler);
|
||||||
await flushDurability(durabilityScheduler);
|
await flushDurability(durabilityScheduler);
|
||||||
assertState(
|
assertState(
|
||||||
await auctionRedisStateReaderService.readAuctionStateView(
|
await auctionRedisStateReaderService.readAuctionStateView(
|
||||||
@@ -546,13 +583,15 @@ async function main(): Promise<void> {
|
|||||||
matchId: resources.matchId,
|
matchId: resources.matchId,
|
||||||
});
|
});
|
||||||
await flushDurability(durabilityScheduler);
|
await flushDurability(durabilityScheduler);
|
||||||
assertState(
|
const resetState = await auctionRedisStateReaderService.readAuctionStateView(
|
||||||
await auctionRedisStateReaderService.readAuctionStateView(
|
resources.matchId.toString(),
|
||||||
resources.matchId.toString(),
|
|
||||||
),
|
|
||||||
'waiting',
|
|
||||||
);
|
);
|
||||||
logStep('reset -> waiting + side effect OK');
|
if (resetState) {
|
||||||
|
throw new Error(
|
||||||
|
`Expected reset to clear Redis state, got phase=${String(resetState.phase)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
logStep('reset -> auction data cleared OK');
|
||||||
|
|
||||||
const restartedAuction = await auctionService.start({
|
const restartedAuction = await auctionService.start({
|
||||||
bidRoundExtensionSeconds: 1,
|
bidRoundExtensionSeconds: 1,
|
||||||
|
|||||||
Reference in new issue
Block a user