mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Added leader election test
Signed-off-by: Drew Erny <drew.erny@docker.com>
This commit is contained in:
parent
ffba13f435
commit
3489e76513
1 changed files with 51 additions and 0 deletions
|
@ -471,6 +471,57 @@ func (s *DockerSwarmSuite) TestApiSwarmLeaderProxy(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestApiSwarmLeaderElection(c *check.C) {
|
||||
// Create 3 nodes
|
||||
d1 := s.AddDaemon(c, true, true)
|
||||
d2 := s.AddDaemon(c, true, true)
|
||||
d3 := s.AddDaemon(c, true, true)
|
||||
|
||||
// assert that the first node we made is the leader, and the other two are followers
|
||||
c.Assert(d1.getNode(c, d1.NodeID).ManagerStatus.Leader, checker.True)
|
||||
c.Assert(d1.getNode(c, d2.NodeID).ManagerStatus.Leader, checker.False)
|
||||
c.Assert(d1.getNode(c, d3.NodeID).ManagerStatus.Leader, checker.False)
|
||||
|
||||
leader := d1
|
||||
|
||||
// stop the leader
|
||||
leader.Stop()
|
||||
|
||||
// wait for an election to occur
|
||||
var newleader *SwarmDaemon
|
||||
|
||||
for _, d := range []*SwarmDaemon{d2, d3} {
|
||||
if d.getNode(c, d.NodeID).ManagerStatus.Leader {
|
||||
newleader = d
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// assert that we have a new leader
|
||||
c.Assert(newleader, checker.NotNil)
|
||||
|
||||
// add the old leader back
|
||||
leader.Start()
|
||||
|
||||
// clear leader and reinit the followers list
|
||||
followers := make([]*SwarmDaemon, 0, 3)
|
||||
|
||||
// pick out the leader and the followers again
|
||||
for _, d := range []*SwarmDaemon{d1, d2, d3} {
|
||||
if d1.getNode(c, d.NodeID).ManagerStatus.Leader {
|
||||
leader = d
|
||||
} else {
|
||||
followers = append(followers, d)
|
||||
}
|
||||
}
|
||||
|
||||
// verify that we still only have 1 leader and 2 followers
|
||||
c.Assert(leader, checker.NotNil)
|
||||
c.Assert(followers, checker.HasLen, 2)
|
||||
// and that after we added d1 back, the leader hasn't changed
|
||||
c.Assert(leader.NodeID, checker.Equals, newleader.NodeID)
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestApiSwarmRaftQuorum(c *check.C) {
|
||||
testRequires(c, Network)
|
||||
d1 := s.AddDaemon(c, true, true)
|
||||
|
|
Loading…
Reference in a new issue