introduce an API to set a mock clock #20
Merged
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.
Fixes #17. Closes #18.
This should be significantly easier than #18. It only adds a
SetClock
function, and no way to switch out the clock. That means that in tests, you have to define a global clock variable (and not a separate clock for every test).This also means that I had to create a new testing package to test the mock clock. At some point, we probably should rewrite the tests to take advantage of the mock clock, but this will be a larger undertaking, especially since registering a new meter is not done synchronously (it's put in the
registerChannel
, and picked up by the sweeper eventually), which makes it impossible to know when to advance the clock.In https://github.com/libp2p/go-libp2p-core/pull/276/files#diff-3dda9486f00364eaac26b64ff16560cde7b6cf8ff03eda4de9752f0fb0a96f42R130, I work around this by sleeping for a short while.