fix(Foundation): Replace timing-dependent tests with condition-based waiting#5137
Merged
fix(Foundation): Replace timing-dependent tests with condition-based waiting#5137
Conversation
51c1e9b to
063afb1
Compare
ff4a0b6 to
541cecd
Compare
541cecd to
588672b
Compare
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.
Summary
Fixes #4977
This PR addresses flaky Foundation tests that were failing intermittently on slower/loaded systems (e.g., nixpkgs builds) due to tight timing tolerances with fixed
Thread::sleep()calls.Changes
waitForCondition()helper function to CppUnit for condition-based polling with timeoutThread::sleep()calls with condition-based waiting in Foundation testswhile (...) Thread::sleep()loops to bounded waits that fail cleanly on timeoutFiles Modified
CppUnit/include/CppUnit/TestCase.hwaitForCondition()template functionActivityTest.cppAsyncNotificationCenterTest.cppExpireCacheTest.cppExpireLRUCacheTest.cppUniqueExpireCacheTest.cppUniqueExpireLRUCacheTest.cppTaskTest.cppTaskManagerTest.cppNotificationQueueTest.cppTimestampTest.cppSemaphoreTest.cppPattern Applied
waitForCondition API
trueif condition met,falseon timeoutstd::chrono::steady_clock,std::this_thread::sleep_for)Future Improvements: Net Library
The Net testsuite has similar patterns that could benefit from
waitForCondition:High Priority (Unbounded Loops)
PollSetTest.cppwhile (!poller.isRunning()) Thread::sleep(100);UDPServerTest.cppdo { Thread::sleep(10); } while (count < i);Medium Priority (Fixed Sleeps + Assertions)
DatagramSocketTest.cppassertTrue(ss.available() == 5)WebSocketTest.cppSyslogTest.cppTCPServerTest.cppTotal: ~49
Thread::sleepcalls across 13 files, of which 2 are critical unbounded loops and ~8-10 are good candidates for condition-based waiting.Test Plan