perf(auction): reduce polling with verified socket recovery
Keep fixed 30-second safety polling with separate recovery polling, confirm persistent heartbeat gaps, and refresh shared history after durable writes.
This commit is contained in:
1 parent
e349684523
commit
23a0a3f8dd
20 files changed
+790
-154
No files matched your search
@@ -6,9 +6,192 @@ import {
|
||||
shouldApplyIncomingAuctionState,
|
||||
shouldApplyPolledAuctionState,
|
||||
shouldResyncForBidDelta,
|
||||
resolveCurrentBidPointAmount,
|
||||
shouldResyncForAuctionIdentity,
|
||||
createAuctionHeartbeatMonitor,
|
||||
} from "../src/api/auction-state.ts";
|
||||
import type { ApiAuction } from "../src/api/types.ts";
|
||||
|
||||
test("Redis-only snapshots retain the bid amount without a legacy alias", () => {
|
||||
assert.equal(
|
||||
resolveCurrentBidPointAmount({
|
||||
currentHighestBidPointAmount: 310,
|
||||
} as ApiAuction),
|
||||
310,
|
||||
);
|
||||
assert.equal(
|
||||
resolveCurrentBidPointAmount({ currentBid: 120 } as ApiAuction),
|
||||
120,
|
||||
);
|
||||
assert.equal(
|
||||
resolveCurrentBidPointAmount({
|
||||
currentHighestBidPointAmount: 0,
|
||||
currentBid: 120,
|
||||
} as ApiAuction),
|
||||
0,
|
||||
);
|
||||
assert.equal(
|
||||
resolveCurrentBidPointAmount({
|
||||
currentHighestBidPointAmount: NaN,
|
||||
} as ApiAuction),
|
||||
0,
|
||||
);
|
||||
});
|
||||
|
||||
test("heartbeats detect missed state and separately versioned side effects", () => {
|
||||
const state = {
|
||||
auctionLifecycleId: "life",
|
||||
revision: 10,
|
||||
matchSideEffectRevision: 2,
|
||||
} as ApiAuction;
|
||||
assert.equal(
|
||||
shouldResyncForAuctionIdentity(state, {
|
||||
auctionLifecycleId: "life",
|
||||
revision: 11,
|
||||
}),
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
shouldResyncForAuctionIdentity(state, {
|
||||
auctionLifecycleId: "life",
|
||||
revision: 10,
|
||||
matchSideEffectRevision: 3,
|
||||
}),
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
shouldResyncForAuctionIdentity(state, {
|
||||
auctionLifecycleId: "life",
|
||||
revision: 10,
|
||||
matchSideEffectRevision: 2,
|
||||
}),
|
||||
false,
|
||||
);
|
||||
assert.equal(
|
||||
shouldResyncForAuctionIdentity(state, {
|
||||
auctionLifecycleId: "new-life",
|
||||
revision: 1,
|
||||
}),
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test("a delayed heartbeat cannot pull an advanced socket backward", () => {
|
||||
const advanced = { auctionLifecycleId: "life", revision: 12 } as ApiAuction;
|
||||
assert.equal(
|
||||
shouldResyncForAuctionIdentity(advanced, {
|
||||
auctionLifecycleId: "life",
|
||||
revision: 11,
|
||||
matchSideEffectRevision: 9,
|
||||
}),
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
test("expired complete runtimes and legacy archives do not repeatedly resync", () => {
|
||||
assert.equal(
|
||||
shouldResyncForAuctionIdentity(
|
||||
{ auctionLifecycleId: "life", phase: "complete" } as ApiAuction,
|
||||
null,
|
||||
),
|
||||
false,
|
||||
);
|
||||
assert.equal(
|
||||
shouldResyncForAuctionIdentity({ phase: "bidding" } as ApiAuction, null),
|
||||
false,
|
||||
);
|
||||
assert.equal(
|
||||
shouldResyncForAuctionIdentity(
|
||||
{
|
||||
auctionEngineVersion: "legacy-renamed",
|
||||
auctionLifecycleId: "legacy-auction:1",
|
||||
phase: "bidding",
|
||||
} as ApiAuction,
|
||||
null,
|
||||
),
|
||||
false,
|
||||
);
|
||||
assert.equal(
|
||||
shouldResyncForAuctionIdentity(
|
||||
{
|
||||
auctionEngineVersion: "redis-v1",
|
||||
auctionLifecycleId: "life",
|
||||
phase: "bidding",
|
||||
} as ApiAuction,
|
||||
null,
|
||||
),
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test("a new in-flight bid does not confirm an earlier gap that already closed", () => {
|
||||
const monitor = createAuctionHeartbeatMonitor();
|
||||
const client = {
|
||||
auctionEngineVersion: "redis-v1",
|
||||
auctionLifecycleId: "life",
|
||||
revision: 10,
|
||||
} as ApiAuction;
|
||||
assert.equal(
|
||||
monitor.inspect(client, { auctionLifecycleId: "life", revision: 11 })
|
||||
.needsResync,
|
||||
false,
|
||||
);
|
||||
const caughtUp = { ...client, revision: 11 };
|
||||
assert.equal(
|
||||
monitor.inspect(caughtUp, { auctionLifecycleId: "life", revision: 12 })
|
||||
.needsResync,
|
||||
false,
|
||||
);
|
||||
assert.equal(
|
||||
monitor.inspect(caughtUp, { auctionLifecycleId: "life", revision: 13 })
|
||||
.needsResync,
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test("heartbeat failures require two misses and reset after a healthy reply", () => {
|
||||
const monitor = createAuctionHeartbeatMonitor();
|
||||
assert.equal(monitor.recordFailure(), false);
|
||||
assert.equal(monitor.recordFailure(), true);
|
||||
monitor.inspect(
|
||||
{ auctionEngineVersion: "legacy-renamed" } as ApiAuction,
|
||||
null,
|
||||
);
|
||||
assert.equal(monitor.recordFailure(), false);
|
||||
monitor.reset();
|
||||
assert.equal(monitor.recordFailure(), false);
|
||||
});
|
||||
|
||||
test("heartbeat confirmation covers side effects and missing runtimes", () => {
|
||||
const monitor = createAuctionHeartbeatMonitor();
|
||||
const client = {
|
||||
auctionEngineVersion: "redis-v1",
|
||||
auctionLifecycleId: "life",
|
||||
revision: 10,
|
||||
matchSideEffectRevision: 1,
|
||||
} as ApiAuction;
|
||||
const identity = {
|
||||
auctionLifecycleId: "life",
|
||||
revision: 10,
|
||||
matchSideEffectRevision: 2,
|
||||
};
|
||||
assert.equal(monitor.inspect(client, identity).needsResync, false);
|
||||
assert.equal(
|
||||
monitor.inspect({ ...client, matchSideEffectRevision: 2 }, identity)
|
||||
.isCurrent,
|
||||
true,
|
||||
);
|
||||
assert.equal(monitor.inspect(client, null).needsResync, false);
|
||||
assert.equal(monitor.inspect(client, null).needsResync, true);
|
||||
monitor.reset();
|
||||
const legacy = {
|
||||
...client,
|
||||
auctionEngineVersion: "legacy-renamed",
|
||||
} as ApiAuction;
|
||||
assert.equal(monitor.inspect(legacy, null).isCurrent, true);
|
||||
assert.equal(monitor.inspect(legacy, null).needsResync, false);
|
||||
});
|
||||
|
||||
const current = {
|
||||
auctionLifecycleId: "life",
|
||||
revision: 10,
|
||||
|
||||
Reference in new issue
Block a user