@@ -55,11 +55,11 @@ func TestTicker(t *testing.T) {
55
55
count , delta := test .count , test .delta
56
56
ticker := NewTicker (delta )
57
57
t0 := Now ()
58
- for i := 0 ; i < count / 2 ; i ++ {
58
+ for range count / 2 {
59
59
<- ticker .C
60
60
}
61
61
ticker .Reset (delta * 2 )
62
- for i := count / 2 ; i < count ; i ++ {
62
+ for range count - count / 2 {
63
63
<- ticker .C
64
64
}
65
65
ticker .Stop ()
@@ -114,7 +114,7 @@ func TestTeardown(t *testing.T) {
114
114
if testing .Short () {
115
115
Delta = 20 * Millisecond
116
116
}
117
- for i := 0 ; i < 3 ; i ++ {
117
+ for range 3 {
118
118
ticker := NewTicker (Delta )
119
119
<- ticker .C
120
120
ticker .Stop ()
@@ -356,14 +356,19 @@ func testTimerChan(t *testing.T, tim timer, C <-chan Time, synctimerchan bool) {
356
356
// Windows in particular has very coarse timers so we have to
357
357
// wait 10ms just to make a timer go off.
358
358
const (
359
- sched = 10 * Millisecond
360
- tries = 100
359
+ sched = 10 * Millisecond
360
+ tries = 100
361
+ drainTries = 5
361
362
)
362
363
363
364
drain := func () {
364
- select {
365
- case <- C :
366
- default :
365
+ for range drainTries {
366
+ select {
367
+ case <- C :
368
+ return
369
+ default :
370
+ }
371
+ Sleep (sched )
367
372
}
368
373
}
369
374
noTick := func () {
@@ -381,7 +386,7 @@ func testTimerChan(t *testing.T, tim timer, C <-chan Time, synctimerchan bool) {
381
386
case <- C :
382
387
return
383
388
}
384
- for i := 0 ; i < tries ; i ++ {
389
+ for range tries {
385
390
Sleep (sched )
386
391
select {
387
392
default :
@@ -403,7 +408,7 @@ func testTimerChan(t *testing.T, tim timer, C <-chan Time, synctimerchan bool) {
403
408
if n = len (C ); n == 1 {
404
409
return
405
410
}
406
- for i := 0 ; i < tries ; i ++ {
411
+ for range tries {
407
412
Sleep (sched )
408
413
if n = len (C ); n == 1 {
409
414
return
@@ -477,7 +482,7 @@ func testTimerChan(t *testing.T, tim timer, C <-chan Time, synctimerchan bool) {
477
482
478
483
waitDone := func (done chan bool ) {
479
484
t .Helper ()
480
- for i := 0 ; i < tries ; i ++ {
485
+ for range tries {
481
486
Sleep (sched )
482
487
select {
483
488
case <- done :
@@ -580,7 +585,7 @@ func testTimerChan(t *testing.T, tim timer, C <-chan Time, synctimerchan bool) {
580
585
// Test enqueueTimerChan when timer is stopped.
581
586
stop = make (chan bool )
582
587
done = make (chan bool , 2 )
583
- for i := 0 ; i < 2 ; i ++ {
588
+ for range 2 {
584
589
go func () {
585
590
select {
586
591
case <- C :
@@ -641,7 +646,7 @@ func TestAfterTimes(t *testing.T) {
641
646
// Make sure it does.
642
647
// To avoid flakes due to very long scheduling delays,
643
648
// require 10 failures in a row before deciding something is wrong.
644
- for i := 0 ; i < 10 ; i ++ {
649
+ for range 10 {
645
650
start := Now ()
646
651
c := After (10 * Millisecond )
647
652
Sleep (500 * Millisecond )
@@ -657,7 +662,7 @@ func TestAfterTimes(t *testing.T) {
657
662
func TestTickTimes (t * testing.T ) {
658
663
t .Parallel ()
659
664
// See comment in TestAfterTimes
660
- for i := 0 ; i < 10 ; i ++ {
665
+ for range 10 {
661
666
start := Now ()
662
667
c := Tick (10 * Millisecond )
663
668
Sleep (500 * Millisecond )
0 commit comments