@@ -1303,9 +1303,21 @@ func (s *DockerSwarmSuite) TestSwarmRotateUnlockKey(c *check.C) {
13031303
13041304 c .Assert (getNodeStatus (c , d ), checker .Equals , swarm .LocalNodeStateActive )
13051305
1306- outs , err = d .Cmd ("node" , "ls" )
1307- assert .NilError (c , err )
1308- c .Assert (outs , checker .Not (checker .Contains ), "Swarm is encrypted and needs to be unlocked" )
1306+ retry := 0
1307+ for {
1308+ // an issue sometimes prevents leader to be available right away
1309+ outs , err = d .Cmd ("node" , "ls" )
1310+ if err != nil && retry < 5 {
1311+ if strings .Contains (err .Error (), "swarm does not have a leader" ) {
1312+ retry ++
1313+ time .Sleep (3 * time .Second )
1314+ continue
1315+ }
1316+ }
1317+ assert .NilError (c , err )
1318+ c .Assert (outs , checker .Not (checker .Contains ), "Swarm is encrypted and needs to be unlocked" )
1319+ break
1320+ }
13091321
13101322 unlockKey = newUnlockKey
13111323 }
@@ -1383,9 +1395,21 @@ func (s *DockerSwarmSuite) TestSwarmClusterRotateUnlockKey(c *check.C) {
13831395
13841396 c .Assert (getNodeStatus (c , d ), checker .Equals , swarm .LocalNodeStateActive )
13851397
1386- outs , err = d .Cmd ("node" , "ls" )
1387- c .Assert (err , checker .IsNil , check .Commentf ("%s" , outs ))
1388- c .Assert (outs , checker .Not (checker .Contains ), "Swarm is encrypted and needs to be unlocked" )
1398+ retry := 0
1399+ for {
1400+ // an issue sometimes prevents leader to be available right away
1401+ outs , err = d .Cmd ("node" , "ls" )
1402+ if err != nil && retry < 5 {
1403+ if strings .Contains (err .Error (), "swarm does not have a leader" ) {
1404+ retry ++
1405+ time .Sleep (3 * time .Second )
1406+ continue
1407+ }
1408+ }
1409+ c .Assert (err , checker .IsNil , check .Commentf ("%s" , outs ))
1410+ c .Assert (outs , checker .Not (checker .Contains ), "Swarm is encrypted and needs to be unlocked" )
1411+ break
1412+ }
13891413 }
13901414
13911415 unlockKey = newUnlockKey
0 commit comments