// We want to test that a ticker takes as much time as expected.
// Since we don't want the test to run for too long, we don't
// want to use lengthy times. This makes the test inherently flaky.
- // So only report an error if it fails five times in a row.
+ // Start with a short time, but try again with a long one if the
+ // first test fails.
- count := 10
- delta := 20 * Millisecond
+ baseCount := 10
+ baseDelta := 20 * Millisecond
// On Darwin ARM64 the tick frequency seems limited. Issue 35692.
if (runtime.GOOS == "darwin" || runtime.GOOS == "ios") && runtime.GOARCH == "arm64" {
// Since tick frequency is limited on Darwin ARM64, use even
// number to give the ticks more time to let the test pass.
// See CL 220638.
- count = 6
- delta = 100 * Millisecond
+ baseCount = 6
+ baseDelta = 100 * Millisecond
}
var errs []string
}
}
- for i := 0; i < 5; i++ {
+ for _, test := range []struct {
+ count int
+ delta Duration
+ }{{
+ count: baseCount,
+ delta: baseDelta,
+ }, {
+ count: 8,
+ delta: 1 * Second,
+ }} {
+ count, delta := test.count, test.delta
ticker := NewTicker(delta)
t0 := Now()
for i := 0; i < count/2; i++ {