-
-
Notifications
You must be signed in to change notification settings - Fork 230
Description
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() and core::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:
virtual core::nanoseconds_t timestamp_imp() const
In test_pipeline_loop.cpp we 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.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status