1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

fix race in TestApiSwarmRaftQuorum

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff 2016-07-26 21:32:56 -04:00
parent bb27d017f3
commit 4a856d7a87
2 changed files with 32 additions and 0 deletions

View file

@ -300,3 +300,26 @@ func (d *SwarmDaemon) checkControlAvailable(c *check.C) (interface{}, check.Comm
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive)
return info.ControlAvailable, nil
}
func (d *SwarmDaemon) checkLeader(c *check.C) (interface{}, check.CommentInterface) {
errList := check.Commentf("could not get node list")
status, out, err := d.SockRequest("GET", "/nodes", nil)
if err != nil {
return err, errList
}
if status != http.StatusOK {
return fmt.Errorf("expected http status OK, got: %d", status), errList
}
var ls []swarm.Node
if err := json.Unmarshal(out, &ls); err != nil {
return err, errList
}
for _, node := range ls {
if node.ManagerStatus != nil && node.ManagerStatus.Leader {
return nil, nil
}
}
return fmt.Errorf("no leader"), check.Commentf("could not find leader")
}

View file

@ -481,12 +481,18 @@ func (s *DockerSwarmSuite) TestApiSwarmRaftQuorum(c *check.C) {
c.Assert(d2.Stop(), checker.IsNil)
// make sure there is a leader
waitAndAssert(c, defaultReconciliationTimeout, d1.checkLeader, checker.IsNil)
d1.createService(c, simpleTestService, func(s *swarm.Service) {
s.Spec.Name = "top1"
})
c.Assert(d3.Stop(), checker.IsNil)
// make sure there is a leader
waitAndAssert(c, defaultReconciliationTimeout, d1.checkLeader, checker.IsNil)
var service swarm.Service
simpleTestService(&service)
service.Spec.Name = "top2"
@ -496,6 +502,9 @@ func (s *DockerSwarmSuite) TestApiSwarmRaftQuorum(c *check.C) {
c.Assert(d2.Start(), checker.IsNil)
// make sure there is a leader
waitAndAssert(c, defaultReconciliationTimeout, d1.checkLeader, checker.IsNil)
d1.createService(c, simpleTestService, func(s *swarm.Service) {
s.Spec.Name = "top3"
})