@@ -2,37 +2,47 @@ package timer
22
33import (
44 "testing"
5+ "testing/synctest"
56 "time"
67
78 "github.com/stretchr/testify/require"
89)
910
1011func TestTimer_Reset (t * testing.T ) {
11- tt := New ()
12+ synctest .Test (t , func (t * testing.T ) {
13+ tt := New ()
1214
13- tt .Reset (1 , 2 , time .Millisecond * 100 )
14- time .Sleep (time .Millisecond * 200 )
15- shouldReceive (t , tt , 1 , 2 , "no value in timer" )
15+ tt .Reset (1 , 2 , time .Millisecond * 100 )
16+ time .Sleep (time .Millisecond * 200 )
17+ synctest .Wait ()
18+ shouldReceive (t , tt , 1 , 2 , "no value in timer" )
1619
17- tt .Reset (1 , 2 , time .Second )
18- tt .Reset (2 , 3 , 0 )
19- shouldReceive (t , tt , 2 , 3 , "no value in timer after reset(0)" )
20+ tt .Reset (1 , 2 , time .Second )
21+ tt .Reset (2 , 3 , 0 )
22+ synctest .Wait ()
23+ shouldReceive (t , tt , 2 , 3 , "no value in timer after reset(0)" )
2024
21- tt .Reset (1 , 2 , time .Millisecond * 100 )
22- time .Sleep (time .Millisecond * 200 )
23- tt .Reset (1 , 3 , time .Millisecond * 100 )
24- time .Sleep (time .Millisecond * 200 )
25- shouldReceive (t , tt , 1 , 3 , "invalid value after reset" )
25+ tt .Reset (1 , 2 , time .Millisecond * 100 )
26+ time .Sleep (time .Millisecond * 200 )
27+ synctest .Wait ()
28+ tt .Reset (1 , 3 , time .Millisecond * 100 )
29+ time .Sleep (time .Millisecond * 200 )
30+ synctest .Wait ()
31+ shouldReceive (t , tt , 1 , 3 , "invalid value after reset" )
2632
27- tt .Reset (3 , 1 , time .Millisecond * 100 )
28- shouldNotReceive (t , tt , "value arrived too early" )
33+ tt .Reset (3 , 1 , time .Millisecond * 100 )
34+ synctest .Wait ()
35+ shouldNotReceive (t , tt , "value arrived too early" )
2936
30- tt .Extend (time .Millisecond * 300 )
31- time .Sleep (time .Millisecond * 200 )
32- shouldNotReceive (t , tt , "value arrived too early after extend" )
37+ tt .Extend (time .Millisecond * 300 )
38+ time .Sleep (time .Millisecond * 200 )
39+ synctest .Wait ()
40+ shouldNotReceive (t , tt , "value arrived too early after extend" )
3341
34- time .Sleep (time .Millisecond * 300 )
35- shouldReceive (t , tt , 3 , 1 , "no value in timer after extend" )
42+ time .Sleep (time .Millisecond * 300 )
43+ synctest .Wait ()
44+ shouldReceive (t , tt , 3 , 1 , "no value in timer after extend" )
45+ })
3646}
3747
3848func shouldReceive (t * testing.T , tt * Timer , height uint32 , view byte , msg string ) {
0 commit comments