Implement fake timers for unit tests #1058
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implement support for fake timers (timers that run "faster than real time") to make unit tests faster and more predictable.
The approach taken in this PR is to have two implementations of the Timer class. One based on LibUV and one based on a simple map keeping the list of timers (FakeTimerManager). Which one is compiled depends on the FAKE_TIMERS macro being defined that is defined for the test target now.
One of the use cases is to be able to run long tests (f.e. bandwidth estimation tests that take seconds) in milliseconds in unit tests. Existing tests like KeyFrameManagerTests are also faster now.
From a design point of view it also removes the dependency with DevLibUV from many files that should be LibUV agnostic.
Maybe there is a better way to do this, it is open for discussion and I'm happy to take other approach if it makes more sense for mediasoup philosophy or close the PR if it doesn't make sense.