Skip to content

mock TickerFunc allows more than one function call at a time #6

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

Closed
spikecurtis opened this issue Oct 17, 2024 · 0 comments · Fixed by #7
Closed

mock TickerFunc allows more than one function call at a time #6

spikecurtis opened this issue Oct 17, 2024 · 0 comments · Fixed by #7
Labels
bug Something isn't working

Comments

@spikecurtis
Copy link
Collaborator

The real implementation of ticker func looks like this:

func (t *realContextTicker) run() {
	defer t.tkr.Stop()
	for {
		select {
		case <-t.ctx.Done():
			t.err <- t.ctx.Err()
			return
		case <-t.tkr.C:
			err := t.f()
			if err != nil {
				t.err <- err
				return
			}
		}
	}
}

This means that only one call to t.f() can occur at at time, no matter how long it takes. (The underlying ticker chan drops excess ticks.)

In contrast, the mock implementation will run t.f() multiple times in parallel if you advance the clock across multiple ticks.

@coder-labeler coder-labeler bot added the bug Something isn't working label Oct 17, 2024
spikecurtis added a commit that referenced this issue Oct 18, 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant