Repository navigation
test(registrar): subscribe before Start in TestSyncer_Start_NoEventsAfterInitialSync (#1187) - #1188
Merged
Merged
Conversation
…fterInitialSync (#1187) The flake was a missing barrier, not a no-op publish. Synced() closes inside the first sync cycle BEFORE that cycle's Broadcast runs, so a watcher that subscribes right after Synced() can still receive the initial sync's version-1 events late. Every stray event in the failing runs carried version "1" (the first cycle) and the same content the snapshot already held; no later cycle ever emitted an event. The test now subscribes before Start, requires exactly the initial sync's events (SERVICE_ADDED + one ENDPOINT_ADDED per synced protocol), and asserts every event carries that first version. Start returning is the barrier for the later cycles: Broadcast is a synchronous enqueue on the sync goroutine. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
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.
Diagnosis: (B), a missing barrier in the test. The syncer is not publishing no-op versions.
I added temporary logging of each stray event's content and version, then reproduced on
main@6394d25withbazel test --config=race --runs_per_test=40 --nocache_test_results --test_filter=TestSyncer_Start_NoEventsAfterInitialSync //registrar/internal/server:server_test. It failed 5/40. Every failing run logged the same four events:These are the initial sync's events, and they arrived late. None of them came from a later cycle. The cause is in
Syncer.sync:close(s.synced)runs before that same cycle'ss.broadcaster.Broadcast(events)(this ordering dates from #142). So the test'srequireSyncedthenSubscribesequence can register the watcher inside that window, and the watcher then receives the first cycle's fan-out. #1142 and #1152 are not involved, because this test uses a plainmockRegistry: there is noChangeNotifierand no write-behind queue. The window got easier to hit when #788 replaced the 50 ms sleep with theSynced()gate. The gate opens slightly before the broadcast.Why the production path is fine
WatchEndpointswaits onawaitSynced, sendsFullSnapshotEventsat the current version, and then callsSubscribe. If the first cycle's broadcast lands after that, the agent seesENDPOINT_ADDED/SERVICE_ADDEDfor state it already received in the snapshot.RegistrarRegistryappliesENDPOINT_ADDEDasupsertLocked, which is idempotent, so the result is a redundant change signal and no wrong state. The same snapshot-then-subscribe overlap exists for every later cycle too, becauseBroadcastruns outside the snapshot lock, and it is tolerated the same way. Unchanged syncs never broadcast:diffLockedproduces no events, andsynconly callsBroadcastwhenlen(events) > 0.Fix (test-only)
Start, so the initial sync's events are observed deterministically instead of being raced against.SERVICE_ADDEDplus oneENDPOINT_ADDEDper synced protocol. It then asserts that every received event carries that first version, which means no later cycle emitted anything.Startreturning (<-done).Broadcastis a synchronous enqueue on the sync goroutine, so onceStartreturns every event is already in the channel.Unsubscribethen closes the channel, and the test drains it withrange. There are no sleeps.I checked that the new test still catches the real bug it guards. I temporarily injected a mutation that makes a no-op sync emit
ENDPOINT_UPDATEDfor unchanged endpoints, and the test failed 5/5, reporting the version-2 and version-3 events. The mutation was reverted.Gates
bazel test --config=race --runs_per_test=50 --nocache_test_results --test_filter=TestSyncer_Start_NoEventsAfterInitialSync //registrar/internal/server:server_test: 50/50 pass (it was 5/40 failing before the fix).bazel test --config=raceon all 11go_testtargets under//registrar/... //registry/...: all pass. A bare//registrar/...pattern fails at analysis on//registrar/cmd/registrar:image_indexunder race because cgo is off, so I ran the test targets explicitly.bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //registrar/... //registry/...: clean.make format-check: clean.make gazelle: no changes.Fixes #1187
🤖 Generated with Claude Code
https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr