-
-
Notifications
You must be signed in to change notification settings - Fork 243
Use virtual time in TaskQueue unit tests #435
Copy link
Copy link
Open
Labels
C-refactoringcategory: Refactoringcategory: RefactoringC-testscategory: Writing or improving testscategory: Writing or improving testseasy hacksSolution requires minimal project contextSolution requires minimal project contexthelp wantedLooking for contributorsLooking for contributorsmost wantedNeeded most among other help-wanted issuesNeeded most among other help-wanted issues
Description
Activity
Metadata
Metadata
Assignees
Labels
C-refactoringcategory: Refactoringcategory: RefactoringC-testscategory: Writing or improving testscategory: Writing or improving testseasy hacksSolution requires minimal project contextSolution requires minimal project contexthelp wantedLooking for contributorsLooking for contributorsmost wantedNeeded most among other help-wanted issuesNeeded most among other help-wanted issues
Type
Projects
- StatusShow more project fieldsHelp wanted
Last revised: Oct 2023
Update: The task is still relevant. Description is updated to address problems discussed in unfinished PR, linked below.
Currently unit tests for ctl::ControlTaskQueue (test_task_queue.cpp) are partially bound to real clock time (
core::timestamp()andcore::Timer) and due to this they can fail on loaded system, e.g. slow CI runners.We can make them 100% reliable by using virtual clock instead of real time, i.e. clock that is fully controlled by unit tests.
We already use such approach in unit tests for pipeline::PipelineLoop (test_pipeline_loop.cpp). PipelineLoop doesn't call
core::timestamp()directly. Instead, it have a protected virtual method to get time:In
test_pipeline_loop.cppwe inherit PipelineLoop, override this method to return virtual (fake) time, and test this derived class instead of original PipelineLoop.Now we could use the same approach
test_task_queue.cpp:In
ctl::ControlTaskQueue, add virtual methods that isolate calls tocore::timestamp()andcore::TimerFor example, we can add 3 methods:
core::nanoseconds_t timestamp_imp()bool try_set_deadline(nanoseconds_t)void wait_deadline()Default implementations will just call
core::timestamp()andTimermethods.In
test_task_queue.cpp, add a class that inheritsctl::ControlTaskQueue, overrides these 3 methods to work with virtual/fake time, and adds helpers to control that fake time.Adjust tests to work with virtual time instead of real time, i.e. don't use sleep and instead call helpers to control fake time.