Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add concurrent safe StubTime test helper #298

Merged
merged 1 commit into from
Apr 19, 2024
Merged

Conversation

brandur
Copy link
Contributor

@brandur brandur commented Apr 15, 2024

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 protected
by 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.

@brandur brandur force-pushed the brandur-stub-time-safe branch from 9e5fba2 to 86df22c Compare April 15, 2024 01:28
@brandur brandur requested a review from bgentry April 15, 2024 01:33
@brandur brandur force-pushed the brandur-stub-time-safe branch from 86df22c to bfe1e29 Compare April 19, 2024 02:13
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 protected
by 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.
@brandur brandur force-pushed the brandur-stub-time-safe branch from bfe1e29 to cf158c3 Compare April 19, 2024 02:22
@brandur
Copy link
Contributor Author

brandur commented Apr 19, 2024

This one's a really minor test-only change, so in the interest of getting a lot of PRs done, going to time out and merge it.

@brandur brandur merged commit 7086be1 into master Apr 19, 2024
10 checks passed
@brandur brandur deleted the brandur-stub-time-safe branch April 19, 2024 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant