зеркало из https://github.com/microsoft/docker.git
Merge pull request #25104 from cpuguy83/fix_TestApiSwarmRaftQuorum
fix race in TestApiSwarmRaftQuorum
This commit is contained in:
Коммит
e07ff10f70
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -493,12 +493,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"
|
||||
|
@ -508,6 +514,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"
|
||||
})
|
||||
|
|
Загрузка…
Ссылка в новой задаче