Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky Observer tests using fake clock #3318

Merged

Conversation

williamckha
Copy link
Contributor

Description

The tests in observer_test.cpp that call helper function testGetDataReceivedPerSecondByFillingBuffer are flaky in CI because they rely on the passage of actual time.

This PR adds a FakeClock that simulates the passage of time and can be substituted for any std::chrono clock. The time point of FakeClock is fixed and can be explicitly advanced forward with FakeClock::advance. Observer now has a template arg that specifies the clock to use (default is std::chrono::steady_clock) which enables usage of FakeClock in observer_test.cpp.

Testing Done

  • observer_test.cpp passes
  • Added fake_clock_test.cpp

Resolved Issues

Resolves #3309

Length Justification and Key Files to Review

Review Checklist

It is the reviewers responsibility to also make sure every item here has been covered

  • Function & Class comments: All function definitions (usually in the .h file) should have a javadoc style comment at the start of them. For examples, see the functions defined in thunderbots/software/geom. Similarly, all classes should have an associated Javadoc comment explaining the purpose of the class.
  • Remove all commented out code
  • Remove extra print statements: for example, those just used for testing
  • Resolve all TODO's: All TODO (or similar) statements should either be completed or associated with a github issue

Copy link
Contributor

@sauravbanna sauravbanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great!

@williamckha williamckha merged commit 327c969 into UBC-Thunderbots:master Oct 12, 2024
6 checks passed
Lmh-java pushed a commit to Lmh-java/Software that referenced this pull request Oct 25, 2024
* Fix observer test flakiness using FakeClock

* Add FakeClock unit tests

* Run formatting

* Use using instead of typedef

* [pre-commit.ci lite] apply automatic fixes

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
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.

Fix flaky Observer test
3 participants