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

Refactor task_timer to allow mocking the timer #884

Closed
StefanoPetrilli opened this issue Sep 1, 2024 · 1 comment · Fixed by #897
Closed

Refactor task_timer to allow mocking the timer #884

StefanoPetrilli opened this issue Sep 1, 2024 · 1 comment · Fixed by #897
Labels
discussion The viability / implementation of the issue is up for debate feature Code based project improvement

Comments

@StefanoPetrilli
Copy link
Contributor

The class task_timer uses std::chrono::steady_clock. Currently, in the tests the real time has to elapse which makes running the test suite take much longer than it could because of the tests regarding this component.

I propose refactoring task_timer to something like:

template <typename ClockType = std::chrono::steady_clock>
class task_timer {
...
}

This would allow instantiating the task_timer using a mock timer and would allow replacing this_thread::sleep_for(chrono::seconds(4)); with something along the line of timer.advance(4); effectively making all the tests involving timers instant to execute.

@gittiver gittiver added feature Code based project improvement discussion The viability / implementation of the issue is up for debate labels Sep 4, 2024
@gittiver
Copy link
Member

gittiver commented Sep 6, 2024

What about giving the interval time to the constructor (with a default of 1s)?

@gittiver gittiver linked a pull request Sep 10, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion The viability / implementation of the issue is up for debate feature Code based project improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants