fix: Rare race in cluster tests - #3194
Merged
Merged
Conversation
kuznetsss
approved these changes
Aug 27, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
While working on #3174 we had a failure in https://github.com/XRPLF/clio/actions/runs/33074493704/job/98527800974?pr=3174 which appears to be an actual race. This PR fixes the small and rare race that the run exposed.
Backend::run()starts two independentRepeatedTasks on separate strands: a reader(
doRead→onNewState_) and a writer (doWrite→writeNodeMessage). Seven testsasserted
EXPECT_CALL(writeNodeMessage).Times(AtLeast(1))but only ever waited on theread path (
semaphore.acquire()is released from the state callback). When the test bodyreturns,
~Backend→stop()setsstate_ = Stopped, andRepeatedTask's loop checksstate_after the timer wait — so a writer whose first tick hasn't landed yet breaksout without ever calling
doWrite(). CI hit exactly that:writeNodeMessage"never called - unsatisfied and active".
Both intervals are 1 ms, so the writer almost always wins the race — hence the rarity.
Times(AnyNumber()). None of them inspects thewritten message; the expectation only existed because the fixture is a
StrictMock.The write path stays properly covered by the two
WriteNodeMessage*tests, whichrelease the semaphore from inside the write action and so actually wait for it.
StopkeepsAtLeast(1)(it sleeps 20 ms and asserting both tasks ran is its point).std::binary_semaphore→std::counting_semaphore<>in the fixture: both callbacksare
WillRepeatedlyon a 1 ms timer, so a secondrelease()before the main thread'sacquire()was UB.