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

Ticker doesn't get delivered #1

Open
joliveirinha opened this issue Jun 25, 2021 · 0 comments
Open

Ticker doesn't get delivered #1

joliveirinha opened this issue Jun 25, 2021 · 0 comments

Comments

@joliveirinha
Copy link

joliveirinha commented Jun 25, 2021

Hi,

I was testing this and detected a corner case where the ticker is not called if one tick is "missed" while code is executing.

The following code stops executing after the sleep is triggered.

func TestRandomTicker(t *testing.T) {

	ticker := clock.NewRandomTicker(4*time.Second, 6*time.Second)
	defer ticker.Stop()
	var counter = 0

	for {
		select {
		case <-ticker.C:
			counter++
			fmt.Printf("c %d\n", counter)

			if counter > 5 {
				println("sleeping for 10 seconds")
				time.Sleep(10 * time.Second)
				println("finished sleeping")
			}
		}
	}
}

The problem is on the default clause in the RandomTicker loop. Replacing the Timer for a Ticker solves that since we guarantee that it will be called again.

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

No branches or pull requests

1 participant