@@ -7,37 +7,37 @@ package spinlock_test
77import (
88 "errors"
99 "testing"
10+ "testing/synctest"
1011 "time"
1112
1213 "github.com/ethersphere/bee/v2/pkg/spinlock"
1314)
1415
1516func TestWait (t * testing.T ) {
16- t .Parallel ()
1717
1818 t .Run ("timed out" , func (t * testing.T ) {
19- t . Parallel ()
20-
21- err := spinlock . Wait ( time . Millisecond * 20 , func () bool { return false })
22- if ! errors . Is ( err , spinlock . ErrTimedOut ) {
23- t . Fatal ( "expecting to time out" )
24- }
19+ synctest . Test ( t , func ( t * testing. T ) {
20+ err := spinlock . Wait ( time . Millisecond * 20 , func () bool { return false })
21+ if ! errors . Is ( err , spinlock . ErrTimedOut ) {
22+ t . Fatal ( "expecting to time out" )
23+ }
24+ })
2525 })
2626
2727 t .Run ("condition satisfied" , func (t * testing.T ) {
28- t .Parallel ()
29-
30- spinStartTime := time .Now ()
31- condCallCount := 0
32- err := spinlock .Wait (time .Millisecond * 200 , func () bool {
33- condCallCount ++
34- return time .Since (spinStartTime ) >= time .Millisecond * 100
28+ synctest .Test (t , func (t * testing.T ) {
29+ spinStartTime := time .Now ()
30+ condCallCount := 0
31+ err := spinlock .Wait (time .Millisecond * 200 , func () bool {
32+ condCallCount ++
33+ return time .Since (spinStartTime ) >= time .Millisecond * 100
34+ })
35+ if err != nil {
36+ t .Fatal ("expecting to end wait without time out" )
37+ }
38+ if condCallCount == 0 {
39+ t .Fatal ("expecting condition function to be called" )
40+ }
3541 })
36- if err != nil {
37- t .Fatal ("expecting to end wait without time out" )
38- }
39- if condCallCount == 0 {
40- t .Fatal ("expecting condition function to be called" )
41- }
4242 })
4343}
0 commit comments