Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 0 additions & 77 deletions nodejs/src/cdp/services/hogflows/idempotency-keys.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,83 +284,6 @@ describe('IdempotencyKeys', () => {
}
})

it.each([
{ completion: 'waits for the store', writesBeforeFailing: false, storeRecovers: true, holdExpires: false },
{
completion: 'is written but its answer is lost',
writesBeforeFailing: true,
storeRecovers: true,
holdExpires: false,
},
{
completion: 'is lost with its process',
writesBeforeFailing: false,
storeRecovers: false,
holdExpires: false,
},
{
completion: 'is lost with its process and its hold expires',
writesBeforeFailing: false,
storeRecovers: false,
holdExpires: true,
},
])(
'replays a moved run past 24 hours when its completion $completion',
async ({ writesBeforeFailing, storeRecovers, holdExpires }) => {
const scope = `scope-${new UUIDT().toString()}`
const scopedKeys = new IdempotencyKeys(valkey, scope)
const replayFields = { attachment_count: 1, attachment_bytes: 512 }
await scopedKeys.reserve(1, key, 'request-a', 'run-1')
const useClient = valkey.useClient
let storeAnswers = false
const store = jest.spyOn(valkey, 'useClient').mockImplementation(async (...args) => {
if (args[0].name !== 'idempotency-mark-queued' || storeAnswers) {
return useClient(...args)
}
if (writesBeforeFailing) {
await useClient(...args)
}
throw new Error('connection lost')
})
const redisKey = scopedKeys['redisKey'](1, key)
try {
await scopedKeys.markQueued(1, key, 'request-a', 'run-1', 'run-1', replayFields)
if (holdExpires) {
await valkey.useClient({ name: 'test-expire' }, (client) => client.del(redisKey))
}
await scopedKeys.replayUntilDayAfter(
1,
'run-1',
{ hash: IdempotencyKeys.hash(key), fingerprint: 'request-a', replayFields },
new Date(Date.now() + 30 * 24 * HOUR_MS)
)
const completionLands = async () => {
storeAnswers = true
await waitForExpect(async () =>
expect(await operations(scope, 'mark_queued', 'written')).toEqual(1)
)
}
if (storeRecovers) {
await completionLands()
}

await valkey.useClient({ name: 'test-age' }, async (client) => {
const ttlMs = await client.pttl(redisKey)
await (ttlMs > 25 * HOUR_MS ? client.pexpire(redisKey, ttlMs - 25 * HOUR_MS) : client.del(redisKey))
})

expect(await scopedKeys.reserve(1, key, 'request-a', 'run-2')).toEqual({
status: 'replayed',
invocationId: 'run-1',
replayFields,
})
await completionLands()
} finally {
store.mockRestore()
}
}
)

it('records a retry whose completion fails while the earlier completion of its key is still writing', async () => {
await keys.reserve(1, key, 'request-a', 'run-1')
const useClient = valkey.useClient
Expand Down
Loading