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
@@ -21,7 +21,8 @@ import { SecretService } from '../modules/global/secret/secret.service';
|
||||
type RedisClient = ReturnType<typeof createClient>;
|
||||
|
||||
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 {
|
||||
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(
|
||||
state: Record<string, unknown> | null,
|
||||
expectedPhase: string,
|
||||
@@ -508,14 +530,29 @@ async function main(): Promise<void> {
|
||||
auctionActionRequestId: randomUUID(),
|
||||
});
|
||||
await flushDurability(durabilityScheduler);
|
||||
logStep(`waiting ${WAIT_FOR_EXPIRY_MS}ms for Redis TIME deadline`);
|
||||
await new Promise((resolve) => setTimeout(resolve, WAIT_FOR_EXPIRY_MS));
|
||||
const deadlineResult = await deadlineScheduler.processDueBidRoundDeadlines(20);
|
||||
if (deadlineResult.completed < 1) {
|
||||
const secondBiddingState = assertState(
|
||||
await auctionRedisStateReaderService.readAuctionStateView(
|
||||
resources.matchId.toString(),
|
||||
),
|
||||
'bidding',
|
||||
);
|
||||
const secondBiddingKeys = buildAuctionRedisKeys(resources.matchId.toString());
|
||||
const queuedDeadlineScore = await auctionRedisService.raw().sendCommand([
|
||||
'ZSCORE',
|
||||
secondBiddingKeys.deadlineQueueKey,
|
||||
resources.matchId.toString(),
|
||||
]);
|
||||
if (!queuedDeadlineScore) {
|
||||
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);
|
||||
assertState(
|
||||
await auctionRedisStateReaderService.readAuctionStateView(
|
||||
@@ -546,13 +583,15 @@ async function main(): Promise<void> {
|
||||
matchId: resources.matchId,
|
||||
});
|
||||
await flushDurability(durabilityScheduler);
|
||||
assertState(
|
||||
await auctionRedisStateReaderService.readAuctionStateView(
|
||||
resources.matchId.toString(),
|
||||
),
|
||||
'waiting',
|
||||
const resetState = await auctionRedisStateReaderService.readAuctionStateView(
|
||||
resources.matchId.toString(),
|
||||
);
|
||||
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({
|
||||
bidRoundExtensionSeconds: 1,
|
||||
|
||||
Reference in new issue
Block a user