Skip to content

fix: fix mock TickerFunc to act like real #7

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

Merged
merged 1 commit into from
Oct 18, 2024

Conversation

spikecurtis
Copy link
Collaborator

@spikecurtis spikecurtis commented Oct 17, 2024

fixes #5
fixes #6

Fixes the mock TickerFunc to behave like the real one in that it won't run more than one callback at a time and will wait until the callback completes to return from a Wait() call.

Copy link
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @spikecurtis and the rest of your teammates on Graphite Graphite

@spikecurtis spikecurtis requested a review from johnstcn October 17, 2024 13:20
@spikecurtis spikecurtis marked this pull request as ready for review October 17, 2024 13:20
Comment on lines +515 to +517
for m.inProgress {
m.cond.Wait()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this is the canonical usage from https://pkg.go.dev/sync#Cond.Wait

mClock.Advance(time.Second).MustWait(testCtx)

waitErr := make(chan error, 1)
go func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Do we need a waitgroup to ensure this goroutine is completely finished by the time the text exits? Ditto above on L244.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We read from waitErr on L307, so a waitgroup is redundant. On success, we know this goroutine has terminated.

Generally speaking, we mainly care about whether the code under test leaks goroutines. Leaking a test goroutine almost never matters, since the test is finite (the exception is if the leaked goroutine interferes with other tests, which is rare).

Copy link
Collaborator Author

spikecurtis commented Oct 18, 2024

Merge activity

  • Oct 18, 2:47 AM EDT: A user started a stack merge that includes this pull request via Graphite.
  • Oct 18, 2:47 AM EDT: A user merged this pull request with Graphite.

@spikecurtis spikecurtis merged commit abe75f0 into main Oct 18, 2024
1 check passed
spikecurtis added a commit that referenced this pull request Oct 18, 2024
Turns out #7 is bugged.  When we refused to call the TickerFunc callback, we didn't advance the next event time, so the Mock kept re-scheduling `fire()` and we could never finish processing on the tick time.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants