Improve auction realtime bid responsiveness

This commit is contained in:
dahyeon committed 2026-06-23 09:46:38 -07:00
1 parent c6f5a7077f
commit b367328df0
16 files changed
+1364 -203

No files matched your search

@@ -91,6 +91,7 @@ describe('AuctionService', () => {
auctionLifecycleId: 'life-1',
revision: 1,
}),
readBidContext: jest.fn().mockResolvedValue(null),
readAuctionStateView: jest.fn().mockResolvedValue(null),
};
@@ -1006,6 +1007,123 @@ describe('AuctionService', () => {
);
});
it('returns bid deltas without re-reading the full Redis state', async () => {
const matchId = new mongoose.Types.ObjectId();
const captainUserId = new mongoose.Types.ObjectId();
const playerUserId = new mongoose.Types.ObjectId();
const biddingContext = {
auctionLifecycleId: 'life-1',
bidderTeamCaptainUserId: captainUserId.toString(),
currentBidRoundPlayerUserId: playerUserId.toString(),
phase: 'bidding',
};
const auctionBidHistoryEntry = {
bidderTeamIndex: 1,
bidderUserId: captainUserId.toString(),
bidPlacedAtTimestampMS: 1780000000000,
bidPointAmount: 120,
};
const {
connectionService,
service,
auctionRedisCommandService,
auctionRedisStateReaderService,
} = createService({});
auctionRedisStateReaderService.readBidContext.mockResolvedValueOnce(
biddingContext,
);
auctionRedisCommandService.placeBid.mockResolvedValueOnce({
auctionBidHistoryEntry,
bidRequestId: '00000000-0000-4000-8000-000000000050',
currentBidRoundDeadlineTimestampMS: 1780000030000,
currentHighestBidderTeamIndex: 1,
currentHighestBidPointAmount: 120,
currentServerTimestampMS: 1780000000000,
ok: true,
revision: 3,
});
await expect(
service.placeBidDelta({
amount: 120,
bidRequestId: '00000000-0000-4000-8000-000000000050',
matchId,
teamIndex: 1,
}),
).resolves.toEqual(
expect.objectContaining({
auctionBidHistoryEntry,
auctionLifecycleId: 'life-1',
bidRequestId: '00000000-0000-4000-8000-000000000050',
bidServerTiming: expect.objectContaining({
redisBidCommandDurationMS: expect.any(Number),
redisBidContextReadDurationMS: expect.any(Number),
serviceTotalDurationMS: expect.any(Number),
}),
currentBidRoundDeadlineTimestampMS: 1780000030000,
currentHighestBidderTeamIndex: 1,
currentHighestBidPointAmount: 120,
currentServerTimestampMS: 1780000000000,
revision: 3,
}),
);
expect(
auctionRedisStateReaderService.readAuctionStateView,
).not.toHaveBeenCalled();
expect(connectionService.getModel).not.toHaveBeenCalledWith('auction');
});
it('includes redis bid diagnostics and timing on realtime bid rejection', async () => {
const matchId = new mongoose.Types.ObjectId();
const captainUserId = new mongoose.Types.ObjectId();
const playerUserId = new mongoose.Types.ObjectId();
const {
service,
auctionRedisCommandService,
auctionRedisStateReaderService,
} = createService({});
auctionRedisStateReaderService.readBidContext.mockResolvedValueOnce({
auctionLifecycleId: 'life-1',
bidderTeamCaptainUserId: captainUserId.toString(),
currentBidRoundPlayerUserId: playerUserId.toString(),
phase: 'bidding',
});
auctionRedisCommandService.placeBid.mockResolvedValueOnce({
bidRequestId: 'bid-1',
code: 'EXPIRED',
currentBidRoundDeadlineTimestampMS: 1780000002500,
currentServerTimestampMS: 1780000003000,
rejected: true,
});
try {
await service.placeBidDelta({
amount: 120,
bidRequestId: 'bid-1',
matchId,
teamIndex: 1,
});
throw new Error('Expected bid rejection.');
} catch (error) {
const response = (error as { getResponse: () => unknown }).getResponse();
expect(response).toEqual(
expect.objectContaining({
bidDiagnostics: {
currentBidRoundDeadlineTimestampMS: 1780000002500,
currentServerTimestampMS: 1780000003000,
},
bidServerTiming: expect.objectContaining({
redisBidCommandDurationMS: expect.any(Number),
redisBidContextReadDurationMS: expect.any(Number),
serviceTotalDurationMS: expect.any(Number),
}),
code: 'EXPIRED',
message: 'Bid deadline has already expired.',
}),
);
}
});
it('syncs match teams when a redis-v1 auction completes', async () => {
const matchId = new mongoose.Types.ObjectId();
const captainUserId = new mongoose.Types.ObjectId();