@@ -35,7 +35,7 @@ func TestMasterAgentAccept(t *testing.T) {
3535 _ , err = c .client .Post ("/api/machines/accept-v1" , bytes .NewBufferString (`{"host":"mycooltestagent"}` ))
3636 assert .NoError (t , err )
3737
38- time . Sleep ( 200 * time . Millisecond )
38+ c . waitForAccepted ( )
3939 resp , err = c .client .Get ("/machines" )
4040 assert .NoError (t , err )
4141 body = getBody (t , resp .Body )
@@ -115,17 +115,22 @@ spec:
115115 _ , err = c .client .Post ("/api/machines/accept-v1" , bytes .NewBufferString (`{"host":"mycooltestagent"}` ))
116116 assert .NoError (t , err )
117117
118- time . Sleep ( 2 * time . Second )
118+ c . waitForAccepted ( )
119119
120120 // make sure we fetched file from http server with sha256 hash
121- content , err := os .ReadFile ("/tmp/testfromurl" )
121+ var content []byte
122+ WaitFor (t , time .Second * 3 , "wait for file" , func () bool {
123+ content , err = os .ReadFile ("/tmp/testfromurl" )
124+ return len (content ) != 0
125+ })
122126 assert .NoError (t , err )
123127 assert .EqualValues (t , "the file content" , content )
124128
125129 content , err = os .ReadFile ("/tmp/test.systemd" )
126130 assert .NoError (t , err )
127131 assert .EqualValues (t , "filecontentishere\n " , content )
128132
133+ time .Sleep (time .Second )
129134 cancel ()
130135 c .wg .Wait ()
131136}
@@ -184,12 +189,17 @@ spec:
184189 _ , err = c .client .Post ("/api/machines/accept-v1" , bytes .NewBufferString (`{"host":"mycooltestagent"}` ))
185190 assert .NoError (t , err )
186191
187- time . Sleep ( 2 * time . Second )
192+ c . waitForAccepted ( )
188193
189- content , err := os .ReadFile ("/tmp/test.systemd" )
194+ var content []byte
195+ WaitFor (t , time .Second * 3 , "wait for file" , func () bool {
196+ content , err = os .ReadFile ("/tmp/test.systemd" )
197+ return len (content ) != 0
198+ })
190199 assert .NoError (t , err )
191200 assert .EqualValues (t , "filecontentishere\n " , content )
192201
202+ time .Sleep (time .Second )
193203 cancel ()
194204 c .wg .Wait ()
195205}
@@ -223,7 +233,7 @@ spec:
223233 _ , err = c .client .Post ("/api/machines/accept-v1" , bytes .NewBufferString (`{"host":"mycooltestagent"}` ))
224234 assert .NoError (t , err )
225235
226- time . Sleep ( 2 * time . Second )
236+ c . waitForAccepted ( )
227237
228238 err = os .WriteFile ("./adminConfig" , []byte (fmt .Sprintf (`
229239 {"masters":[{"name":"http://127.0.0.1:%s","zone":"zone1"}],
@@ -269,8 +279,7 @@ spec:
269279
270280 _ , err = c .client .Post ("/api/machines/accept-v1" , bytes .NewBufferString (`{"host":"mycooltestagent"}` ))
271281 assert .NoError (t , err )
272-
273- time .Sleep (2 * time .Second )
282+ c .waitForAccepted ()
274283
275284 err = os .WriteFile ("./adminConfig" , []byte (fmt .Sprintf (`
276285 {"masters":[{"name":"http://127.0.0.1:%s","zone":"zone1"}],
@@ -315,8 +324,7 @@ spec:
315324
316325 _ , err = c .client .Post ("/api/machines/accept-v1" , bytes .NewBufferString (`{"host":"mycooltestagent"}` ))
317326 assert .NoError (t , err )
318-
319- time .Sleep (2 * time .Second )
327+ c .waitForAccepted ()
320328
321329 buf := & bytes.Buffer {}
322330 logrus .SetOutput (buf )
@@ -361,16 +369,15 @@ spec:
361369
362370 _ , err = c .client .Post ("/api/machines/accept-v1" , bytes .NewBufferString (`{"host":"mycooltestagent"}` ))
363371 assert .NoError (t , err )
364-
365- time .Sleep (1 * time .Second )
372+ c .waitForAccepted ()
366373
367374 err = os .WriteFile ("./adminConfig" , []byte (fmt .Sprintf (`
368375 {"masters":[{"name":"http://127.0.0.1:%s","zone":"zone1"}],
369376 "token":"%s"}` , c .master .WsPort , c .client .Token )), 0666 )
370377 assert .NoError (t , err )
371378
372379 var content []byte
373- WaitFor (t , 1 * time .Second , "file to have content from git" , func () bool {
380+ WaitFor (t , 2 * time .Second , "file to have content from git" , func () bool {
374381 content , err = os .ReadFile ("./newfile.txt" )
375382 return err == nil
376383 })
@@ -406,7 +413,7 @@ spec:
406413 out := stdout ()
407414 assert .Contains (t , out , "apply file: newspec.yml" )
408415
409- WaitFor (t , 1 * time .Second , "file to have content from apply" , func () bool {
416+ WaitFor (t , 2 * time .Second , "file to have content from apply" , func () bool {
410417 content , err = os .ReadFile ("./newfile.txt" )
411418 assert .NoError (t , err )
412419 return string (content ) == "filecontentishere\n "
@@ -441,7 +448,7 @@ spec:
441448 err = a .Apply (ctx , []string {"newspec.yml" })
442449 assert .NoError (t , err )
443450
444- WaitFor (t , 1 * time .Second , "file to have content from git again" , func () bool {
451+ WaitFor (t , 2 * time .Second , "file to have content from git again" , func () bool {
445452 content , err = os .ReadFile ("./newfile.txt" )
446453 assert .NoError (t , err )
447454 return string (content ) == "itsfromgit\n "
0 commit comments