feat: redesign auction engine with redis sot
This commit is contained in:
1 parent
737702d78c
commit
e8bb20d988
75 files changed
+12737
-542
No files matched your search
@@ -0,0 +1,111 @@
|
||||
import { buildAuctionRedisKeys } from './auction-redis.keys';
|
||||
import {
|
||||
AUCTION_HYDRATE_STATE_SCRIPT,
|
||||
assembleAuctionViewFromRedisState,
|
||||
buildHydrateAuctionStateScriptInvocation,
|
||||
shouldHydrateRedisAuctionState,
|
||||
} from './auction-redis.state';
|
||||
|
||||
describe('auction redis state assembly', () => {
|
||||
it.each([
|
||||
{
|
||||
expected: true,
|
||||
live: null,
|
||||
mongo: { auctionLifecycleId: 'life-1', revision: 1 },
|
||||
},
|
||||
{
|
||||
expected: true,
|
||||
live: { auctionLifecycleId: 'life-1', revision: 1 },
|
||||
mongo: { auctionLifecycleId: 'life-1', revision: 2 },
|
||||
},
|
||||
{
|
||||
expected: true,
|
||||
live: { auctionLifecycleId: 'old-life', revision: 2 },
|
||||
mongo: { auctionLifecycleId: 'new-life', revision: 2 },
|
||||
},
|
||||
{
|
||||
expected: false,
|
||||
live: { auctionLifecycleId: 'redis-life', revision: 3 },
|
||||
mongo: { auctionLifecycleId: 'mongo-life', revision: 2 },
|
||||
},
|
||||
])('decides rehydrate need: %#', ({ live, mongo, expected }) => {
|
||||
expect(shouldHydrateRedisAuctionState({ live, mongo })).toBe(expected);
|
||||
});
|
||||
|
||||
it('assembles public view and maps internal expiring phase to bidding', () => {
|
||||
expect(
|
||||
assembleAuctionViewFromRedisState({
|
||||
auctionBidHistoryEntries: ['{"bidPointAmount":100}'],
|
||||
currentServerTimestampMS: 1_000,
|
||||
liveState: {
|
||||
auctionLifecycleId: 'life-1',
|
||||
currentBidRoundPlayerUserId: 'player-1',
|
||||
phase: 'expiring',
|
||||
revision: 3,
|
||||
},
|
||||
shouldForceAuctionStateResync: true,
|
||||
structureState: {
|
||||
auctionTeams: [],
|
||||
},
|
||||
}),
|
||||
).toMatchObject({
|
||||
auctionBidHistory: [{ bidPointAmount: 100 }],
|
||||
auctionLifecycleId: 'life-1',
|
||||
canPlaceBidInCurrentBidRound: false,
|
||||
currentBidRoundPlayerUserId: 'player-1',
|
||||
currentServerTimestampMS: 1000,
|
||||
isAuctionStateTransitionInProgress: true,
|
||||
phase: 'bidding',
|
||||
revision: 3,
|
||||
shouldForceAuctionStateResync: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('builds HYDRATE invocation and keeps CAS conditions in Lua', () => {
|
||||
const invocation = buildHydrateAuctionStateScriptInvocation(
|
||||
buildAuctionRedisKeys('match-1'),
|
||||
{
|
||||
auctionHistorySequence: 4,
|
||||
auctionLifecycleId: 'life-1',
|
||||
liveStatePatch: {
|
||||
'team:1:assignedAuctionTeamMemberCount': 1,
|
||||
'team:1:remainingBidPointAmount': 1000,
|
||||
},
|
||||
maximumBidRoundDurationSeconds: 30,
|
||||
matchId: 'match-1',
|
||||
phase: 'bidding',
|
||||
revision: 7,
|
||||
structureStateJson: '{"auctionTeams":[]}',
|
||||
},
|
||||
);
|
||||
|
||||
expect(invocation.script).toBe(AUCTION_HYDRATE_STATE_SCRIPT);
|
||||
expect(invocation.keys).toEqual([
|
||||
'auction:match-1:liveAuctionState',
|
||||
'auction:match-1:auctionStructureState',
|
||||
'auction:bidRoundDeadlineQueue',
|
||||
]);
|
||||
expect(invocation.values).toEqual([
|
||||
'match-1',
|
||||
'life-1',
|
||||
'7',
|
||||
'bidding',
|
||||
'4',
|
||||
'30',
|
||||
'{"auctionTeams":[]}',
|
||||
'2',
|
||||
'team:1:assignedAuctionTeamMemberCount',
|
||||
'1',
|
||||
'team:1:remainingBidPointAmount',
|
||||
'1000',
|
||||
]);
|
||||
expect(AUCTION_HYDRATE_STATE_SCRIPT.lua).toContain("redis.call('TIME')");
|
||||
expect(AUCTION_HYDRATE_STATE_SCRIPT.lua).toContain(
|
||||
'INVALID_PATCH_ARITY',
|
||||
);
|
||||
expect(AUCTION_HYDRATE_STATE_SCRIPT.lua).toContain(
|
||||
'mongoRevision > redisRevision',
|
||||
);
|
||||
expect(AUCTION_HYDRATE_STATE_SCRIPT.lua).toContain("redis.call('ZADD'");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user