Fix the listener single-flight race; make the certificate metrics test deterministic #86

Merged
calvin merged 3 commits from deterministic-test-budgets into master 2026-11-15 09:50:40 +00:00
Owner

Two flaky tests, one of them a real (benign) listener race.

  1. Listener single-flight race (lib/salt_dns/listener/guard.ex, miss/4). A handler that missed the cache could claim the key just after another handler had stored the answer and released its claim, then ask the database again. "One name repeated costs one lookup" therefore did not always hold (review_fixes_test.exs:158 got 4 queries instead of 2 under CI load). The budget and gate always applied. Fix: the claim reads the cache once more and returns a fresh hit; the flight marker is deleted on every exit (try/after, a raising lookup included). miss/4 is now public with @doc false so a test can enter at the claim; no sleep or hook in lib. Tests in guard_test.exs: a late claim does not ask again, a fresh claim looks up and releases, a raising lookup releases. Shown: a temporary random sleep before the claim made the F3 test fail 5/5 (42-52 queries); with the fix and the same sleep it passes 5/5; the file passed 30/30.
  2. SaltDns.Certificates.MetricsTest no longer depends on the shared Prometheus reporter: labels of its own per test, the unlabelled challenge_wait count read as a difference, the certificate module forced off and certificate series cleared in setup/on_exit. Shown: with an earlier module emitting a challenge_wait and a metrics-ca order the old file failed and the new one passes; 30/30 alone.

CHANGELOG entry added.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DnYzaTxC2GmdSpvCNyHNne

Two flaky tests, one of them a real (benign) listener race. 1. **Listener single-flight race** (`lib/salt_dns/listener/guard.ex`, `miss/4`). A handler that missed the cache could claim the key just after another handler had stored the answer and released its claim, then ask the database again. "One name repeated costs one lookup" therefore did not always hold (review_fixes_test.exs:158 got 4 queries instead of 2 under CI load). The budget and gate always applied. Fix: the claim reads the cache once more and returns a fresh hit; the flight marker is deleted on every exit (try/after, a raising lookup included). `miss/4` is now public with `@doc false` so a test can enter at the claim; no sleep or hook in lib. Tests in guard_test.exs: a late claim does not ask again, a fresh claim looks up and releases, a raising lookup releases. Shown: a temporary random sleep before the claim made the F3 test fail 5/5 (42-52 queries); with the fix and the same sleep it passes 5/5; the file passed 30/30. 2. **SaltDns.Certificates.MetricsTest** no longer depends on the shared Prometheus reporter: labels of its own per test, the unlabelled challenge_wait count read as a difference, the certificate module forced off and certificate series cleared in setup/on_exit. Shown: with an earlier module emitting a challenge_wait and a `metrics-ca` order the old file failed and the new one passes; 30/30 alone. CHANGELOG entry added. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01DnYzaTxC2GmdSpvCNyHNne
Make the certificate metrics test independent of the shared reporter
Some checks failed
ci/woodpecker/pr/integration Pipeline is pending
ci/woodpecker/pr/image Pipeline was successful
ci/woodpecker/pr/quality Pipeline was canceled
0c56071440
The Prometheus reporter is global to the VM and other modules feed it, so
the test's exact assertions (unlabelled challenge_wait count, provider and
certificate series, prune counts, enabled?) depended on what ran before.
Give each test labels of its own, read the unlabelled distribution as a
difference, switch the module off and clear certificate series in setup
and teardown.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DnYzaTxC2GmdSpvCNyHNne
calvin changed title from Make the certificate metrics test independent of the shared reporter to Fix the listener single-flight race; make the certificate metrics test deterministic 2026-11-15 09:30:48 +00:00
Guard: re-read the cache after claiming a lookup
Some checks failed
ci/woodpecker/pr/quality Pipeline failed
ci/woodpecker/pr/integration unknown status
ci/woodpecker/pr/image Pipeline was successful
a57ba7ccfa
A handler that missed the cache could claim the key just after another
handler had stored the answer and released its claim, and then ask the
database again, so one repeated unsigned query could cost two lookups.
The claim now reads the cache once more (the marker is still deleted on
every way out). miss/4 is public, @doc false, so a test can enter at the
claim without a sleep or hook in lib.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DnYzaTxC2GmdSpvCNyHNne
Guard test: no always-true condition in the lookup funs
All checks were successful
ci/woodpecker/pr/image Pipeline was successful
ci/woodpecker/pr/quality Pipeline was successful
ci/woodpecker/pr/integration Pipeline was successful
a6274adf73
The quality job runs the tests with --warnings-as-errors; the type checker
flagged send(...) && value.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DnYzaTxC2GmdSpvCNyHNne
calvin merged commit 189fcd26cd into master 2026-11-15 09:50:40 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
external/salt-dns!86
No description provided.