@@ -3,13 +3,12 @@ package async
33import (
44 "errors"
55 "testing"
6+ "testing/synctest"
67 "time"
78
89 "github.com/scaleway/scaleway-sdk-go/internal/testhelpers"
910)
1011
11- const flakiness = 500 * time .Millisecond
12-
1312type value struct {
1413 doneIterations int
1514 totalDuration time.Duration
@@ -106,24 +105,36 @@ func TestWaitSync(t *testing.T) {
106105 expValue : nil ,
107106 expErr : errors .New ("timeout after 2s" ),
108107 },
108+ {
109+ name : "WithError" ,
110+ config : & WaitSyncConfig {
111+ Get : func () (any , bool , error ) {
112+ return nil , false , errors .New ("error" )
113+ },
114+ },
115+ expValue : nil ,
116+ expErr : errors .New ("error" ),
117+ },
109118 }
110119 for _ , c := range testsCases {
111120 c := c // do not remove me
112121 t .Run (c .name , func (t * testing.T ) {
113122 t .Parallel ()
114123
115- terminalValue , err := WaitSync (c .config )
124+ synctest .Test (t , func (t * testing.T ) {
125+ terminalValue , err := WaitSync (c .config )
116126
117- testhelpers .Equals (t , c .expErr , err )
127+ testhelpers .Equals (t , c .expErr , err )
118128
119- if c .expValue != nil {
120- exp := c .expValue .(* value )
121- acc := terminalValue .(* value )
122- testhelpers .Equals (t , exp .doneIterations , acc .doneIterations )
129+ if c .expValue != nil {
130+ exp := c .expValue .(* value )
131+ acc := terminalValue .(* value )
132+ testhelpers .Equals (t , exp .doneIterations , acc .doneIterations )
123133
124- ok := exp .totalDuration > acc .totalDuration - flakiness && exp .totalDuration < acc .totalDuration + flakiness
125- testhelpers .Assert (t , ok , "totalDuration don't match the target: (acc: %v, exp: %v)" , acc .totalDuration , exp .totalDuration )
126- }
134+ ok := exp .totalDuration == acc .totalDuration
135+ testhelpers .Assert (t , ok , "totalDuration doesn't match the target: (acc: %v, exp: %v)" , acc .totalDuration , exp .totalDuration )
136+ }
137+ })
127138 })
128139 }
129140}
0 commit comments