@@ -7,6 +7,7 @@ package spinlock_test
77import (
88 "errors"
99 "testing"
10+ "testing/synctest"
1011 "time"
1112
1213 "github.com/ethersphere/bee/v2/pkg/spinlock"
@@ -17,27 +18,29 @@ func TestWait(t *testing.T) {
1718
1819 t .Run ("timed out" , func (t * testing.T ) {
1920 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- }
21+ synctest .Test (t , func (t * testing.T ) {
22+ err := spinlock .Wait (time .Millisecond * 20 , func () bool { return false })
23+ if ! errors .Is (err , spinlock .ErrTimedOut ) {
24+ t .Fatal ("expecting to time out" )
25+ }
26+ })
2527 })
2628
2729 t .Run ("condition satisfied" , func (t * testing.T ) {
2830 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
31+ synctest .Test (t , func (t * testing.T ) {
32+ spinStartTime := time .Now ()
33+ condCallCount := 0
34+ err := spinlock .Wait (time .Millisecond * 200 , func () bool {
35+ condCallCount ++
36+ return time .Since (spinStartTime ) >= time .Millisecond * 100
37+ })
38+ if err != nil {
39+ t .Fatal ("expecting to end wait without time out" )
40+ }
41+ if condCallCount == 0 {
42+ t .Fatal ("expecting condition function to be called" )
43+ }
3544 })
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- }
4245 })
4346}
0 commit comments