Repository navigation
feat(sqs): seedable create-then-lookup consistency window (#413) - #427
Merged
Merged
Conversation
AWS documents that a caller "must wait at least one second after the queue is created to be able to use the queue", so a real CreateQueue -> GetQueueUrl -> retry loop can legitimately observe QueueDoesNotExist for a queue that exists. Substrate resolved a new queue instantly, which made that retry path unreachable: the consumer could not exercise it offline at all, so a suite asserting on it passed without ever running the loop. POST/DELETE /v1/sqs/consistency seeds how many subsequent lookups report QueueDoesNotExist for a queue that does exist, keyed by queue name or the "*" wildcard. GetQueueUrl and GetQueueAttributes have independent counters, both defaulting to 0, so unseeded behavior is unchanged. Counted in misses, not measured as a duration. TimeController.Now advances with wall time from its baseline, so a duration seed would expire partway through a test and make "still missing" assertions wall-clock dependent, which CLAUDE.md forbids. A miss counter is exactly reproducible. emulator/consistency.go is not reusable here for the same reason plus three others: it is evaluated in server middleware, returns 409 InconsistentStateException, and its primaryParam list has no QueueName candidate. Two ordering rules, each pinned by a test: - A miss is consumed only after the queue is known to exist. Seeding before CreateQueue is the natural harness order, and consuming budget on a genuinely absent queue would silently spend what the test meant to spend on the window. - A seed counts down the next N misses rather than re-arming on CreateQueue. createQueue is unconditionally idempotent, so "after its CreateQueue" is ambiguous when create runs twice, and re-arming would make the data path write control-plane state. An exhausted name-scoped seed falls through to the wildcard, so an empty named seed cannot mask a wildcard that still has budget. Consuming a miss is a read-modify-write and StateManager offers no compare-and-swap (MemoryStateManager is last-write-wins), so concurrent lookups could each read misses=1 and each write 0, consuming one miss where several were seeded. A striped per-queue mutex closes that window. TestSQS_Consistency_ConcurrentGetQueueUrl drives 32 goroutines through one barrier and asserts exactly N misses; it fails 3/3 runs with the lock removed. sqsQueueMutex deliberately mirrors s3KeyMutex rather than generalizing it: that type's lock(bucket, key) is two-part by design and its documentation is written entirely in S3 terms, so sharing would mean changing a signature used at every S3 conditional-write call site from inside a PR about SQS. Extract a common type on the third caller. Seeds go through StateManager because PluginConfig carries only State, Logger and Options, so a plugin cannot reach ServerOptions controllers. The side benefit is that POST /v1/state/reset wipes them, which is what a harness expects between cases; TestSQS_Consistency_ResetClearsSeeds pins it. Closes #413.
This was referenced Aug 1, 2026
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Raised by codecov/patch on #427 at 60.24% against a 74.09% target. The uncovered lines were the state-failure branches, and they turn out to be worth testing on their own merits rather than as a coverage exercise. QueueDoesNotExist is a 400 telling a caller the queue is gone and to stop retrying; a store failure is transient and should be retried. Collapsing the latter into the former sends a consumer down a permanent-failure path over a blip. That distinction matters more here than usual, because the seed added in this PR exists precisely so consumers can test their retry loops — getting it backwards would undercut the feature. Same argument as TestS3_StateFailureIsNotReportedAsNoSuchBucket (#392), and the failing-store double follows errAfterGetsStateManager from that work. Verified load-bearing: collapsing consumeQueueMiss's Get error into "(false, nil)" makes both subtests fail with 200 where 500 is expected. Also covers the control plane's own error paths. A seed that silently fails to persist is worse than no seed: the harness proceeds believing the window is armed, every lookup succeeds, and the retry assertion passes vacuously — exactly the failure mode #413 was filed about. Four rows: seed Put, clear-one Delete, clear-all List, clear-all Delete. Plus a malformed request body, a corrupt stored seed (which must not read as "no misses left"), and a table over sqsQueueNameFromURL's degenerate inputs. newSQSTestServer now delegates to newSQSTestServerWithState so a test can substitute a failing store; the no-argument signature is unchanged, so the ~40 existing call sites are untouched. Two export_test.go helpers write a seed directly into state, which is needed to arrange one behind a store whose Put or Delete is rigged to fail. Patch coverage 60.24% -> 96.92%. The four statements still uncovered are json.Marshal on a struct of two ints and a string, which cannot fail.
Merged
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.
Part B of #413 — the seedable consistency window. Part A (#426) corrected the error
code these tests assert on and had to land first.
AWS documents that a caller "must wait at least one second after the queue is
created to be able to use the queue", so a real
CreateQueue→GetQueueUrl→retry loop can legitimately observe
QueueDoesNotExistfor a queue that exists.Substrate resolved a new queue instantly, which made that retry path unreachable
— the consumer could not exercise it offline at all, so a suite asserting on it
passed without ever running the loop.
The seed
Keyed by queue name or the
"*"wildcard.GetQueueUrlandGetQueueAttributeshave independent counters, both defaulting to 0, so unseeded behavior is
unchanged. An exhausted name-scoped seed falls through to the wildcard, so an empty
named seed cannot mask a wildcard that still has budget.
End to end, matching how the reporter will use it:
Counts, not durations
The issue explicitly offered "or a clock-duration form"; this is counted in misses
deliberately.
TimeController.Nowadvances with wall time from its baseline —it is not a frozen, manually-stepped clock — so a duration seed would expire partway
through a test and make "still missing" assertions wall-clock dependent, which
CLAUDE.md forbids outright. A miss counter is exactly reproducible.
emulator/consistency.gois not reusable here for that same reason plus threeothers: it is evaluated in server middleware, returns HTTP 409
InconsistentStateException(a different error entirely), and itsprimaryParamlist has no
QueueNamecandidate.Two ordering rules, each pinned by a test
CreateQueueis the natural harness order, and consuming budget on a genuinelyabsent queue would silently spend what the test meant to spend on the window.
CreateQueue.createQueueis unconditionally idempotent (it early-returns the existing URL),so "after its CreateQueue" is ambiguous when create runs twice, and re-arming
would make the data path write control-plane state.
Concurrency
Consuming a miss is a read-modify-write and
StateManageroffers nocompare-and-swap (
MemoryStateManageris last-write-wins), so concurrent lookupscould each read
misses=1and each write0, consuming one miss where several wereseeded — a test asserting "exactly N calls fail" would flake.
A striped per-queue mutex closes that window.
TestSQS_Consistency_ConcurrentGetQueueUrldrives 32 goroutines through one barrier and asserts exactly N misses; it fails
3/3 runs with the lock removed and passes
-count=3with it restored.sqsQueueMutexdeliberately mirrorss3KeyMutexrather than generalizing it:that type's
lock(bucket, key)is two-part by design and its documentation iswritten entirely in S3 terms, so sharing would mean changing a signature used at
every S3 conditional-write call site from inside a PR about SQS. Extract a common
type on the third caller — the doc comment says so.
Why the seed goes through StateManager
PluginConfigcarries only State, Logger and Options, so a plugin cannot reachServerOptionscontrollers. The side benefit is thatPOST /v1/state/resetwipesseeds, which is what a harness expects between cases;
TestSQS_Consistency_ResetClearsSeedspins it.Tests
New
emulator/sqs_consistency_test.go— 11 tests, the protocol-sensitive ones rununder both query and JSON (SQS is dual-protocol and the reporter reaches it
through an SDK): the two window tests, counter independence, unseeded-is-instant,
absent-queue-does-not-consume, no-re-arm-on-create, wildcard,
name-over-wildcard precedence, clear (by name and all), negative-count rejection,
the concurrency test, and reset.
Verification
gofmt,go build ./...,go vet ./...,golangci-lint run ./...(0 issues),make test(race),cd test/e2e && go test ./...,make docs-reference-check,make docs-versions— all clean.Closes #413.