Add concurrent safe StubTime
test helper
#298
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.
This one's not strictly necessary, but it came up in another project so
I thought I may as well port a similar feature here. There's currently a
test helper for setting a stub time in tests, but it's not very useful,
and not useful in case a test case is setting a new test time while a
service is simultaneously trying to access it.
Here, replace
StubTime
with a new test helper that returns a(getTime, setTime)
function pair in which each invocation is protectedby a mutex so the concurrency problem described above is solved.
As seen here, this helper isn't used all that much and could plausibly
be removed or refactored out. However, there's no particularly good
reason to do that since it's not causing any trouble so I think
augmenting it is just as good of a potential path.