Skip to content

Refactor flaky tests: Replace sleep_for with synchronization (Issue #188)#189

Merged
kcenon merged 3 commits into
mainfrom
fix/issue-188-refactor-flaky-tests
Dec 8, 2025
Merged

Refactor flaky tests: Replace sleep_for with synchronization (Issue #188)#189
kcenon merged 3 commits into
mainfrom
fix/issue-188-refactor-flaky-tests

Conversation

@kcenon

@kcenon kcenon commented Dec 8, 2025

Copy link
Copy Markdown
Owner

Description

Refactored unit tests in improved_event_bus_test.cpp and thread_safety_tests.cpp to eliminate flaky behavior caused by hardcoded std::this_thread::sleep_for delays. Introduced a wait_for_condition helper for deterministic
synchronization. Additionally, enabled improved_event_bus_test.cpp in the build system as it was previously excluded.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring

Related Issues

Fixes #188

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Testing

  • Unit tests pass (Ran ctest successfully with 104/104 tests passing)
  • Integration tests pass
  • Manual testing completed

Screenshots (if applicable)

N/A

Additional Notes

The improved_event_bus_test.cpp file was previously missing from tests/CMakeLists.txt, meaning these tests were not running in CI. This PR ensures they are built and executed. The wait_for_condition helper was implemented using
snake_case to strictly adhere to the project's coding conventions.

Replaced blind sleep_for calls with a custom WaitForCondition helper that polls for the expected condition. This eliminates flakiness caused by timing issues and speeds up tests on faster machines.
Also added improved_event_bus_test.cpp to the common_system_tests executable in CMakeLists.txt to ensure it is actually run.
Removed sleep_for(100ms) calls that were placed after joining threads. Since thread::join() guarantees that the threads have finished execution, waiting afterwards is unnecessary and only slows down the test suite.
Renamed the helper function in improved_event_bus_test.cpp to match the project's snake_case convention for function names.
@kcenon kcenon merged commit 95d7fca into main Dec 8, 2025
19 checks passed
@kcenon kcenon deleted the fix/issue-188-refactor-flaky-tests branch December 8, 2025 10:21
kcenon added a commit that referenced this pull request Apr 13, 2026
) (#189)

* Refactor flaky tests in improved_event_bus_test.cpp

Replaced blind sleep_for calls with a custom WaitForCondition helper that polls for the expected condition. This eliminates flakiness caused by timing issues and speeds up tests on faster machines.
Also added improved_event_bus_test.cpp to the common_system_tests executable in CMakeLists.txt to ensure it is actually run.

* Remove redundant sleep_for calls in thread_safety_tests.cpp

Removed sleep_for(100ms) calls that were placed after joining threads. Since thread::join() guarantees that the threads have finished execution, waiting afterwards is unnecessary and only slows down the test suite.

* Style fix: Rename WaitForCondition to wait_for_condition

Renamed the helper function in improved_event_bus_test.cpp to match the project's snake_case convention for function names.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(refactor): replace sleep_for with synchronization primitives

1 participant