Repository navigation
Accept an idempotency key when arming a fault - #40
Closed
RhysSullivan wants to merge 1 commit into
Closed
RhysSullivan wants to merge 1 commit into
RhysSullivan wants to merge 1 commit into
Conversation
An arm may carry idempotencyKey. Another arm with the same key and the same fault stores nothing and returns the fault first stored for that key, so a caller that lost an answer can send the arm again. Each key is remembered with the instance's state, through consumption, removal, clearing, reset and Durable Object eviction, so a late copy cannot arm its fault again. The same key with a different fault is refused with 409. Arms without a key behave as before. The faults list says the emulator honors keys.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
POST /_emulate/faultsaccepts an optionalidempotencyKey. A test harness whose arm lost its answer (a reset connection, a time-out) can send it again with the same key without arming a second fault.replayed: true. This holds whether the first copy landed before or after the retry, and for as long as the instance's state lives: through consumption, removal by id, clearing all faults,POST /_emulate/resetand Durable Object eviction (the key records are kept in the persisted faults snapshot). A late copy whose fault is gone gets that fault back withremaining: 0and arms nothing.409 idempotency_key_conflict.replayedfield.GET /_emulate/faultsaddsidempotencyKeys: true, so a caller can tell an emulator that honors keys from an older deploy./__seedstill wipes every fault and key with the rest of the instance.The key check and the store happen in one synchronous step in
FaultRegistry.armOnce, so concurrent arms with one key cannot both store.Tests:
core/src/__tests__/fault-keys.test.ts(sequence, concurrent, late copies after consumption, removal, clearing and reset, conflicting definition, no key, snapshot and restore) and one Durable Object case incloudflare/src/__tests__/worker.test.ts(a retry lands, the instance is replaced, the late original arrives, the fault is consumed, the instance is reset). All seven fail onmainand pass here.pnpm build,format:check,type-check,lintandtestpass locally.Deploy: merging does not deploy. No workflow deploys the
emulate-hostsworker, and there is no Cloudflare build check onmain. emulators.dev changes only when someone runswrangler deployfrompackages/@emulators/cloudflareafterpnpm build. Until then, emulators.dev keeps today's behaviour: it ignores the key and does not listidempotencyKeys.