Skip to content

Commit

Permalink
Added leader election test
Browse files Browse the repository at this point in the history
Signed-off-by: Drew Erny <[email protected]>
(cherry picked from commit 3489e76)
Signed-off-by: Tibor Vass <[email protected]>
  • Loading branch information
dperny authored and Tibor Vass committed Jul 26, 2016
1 parent 178b687 commit fd23156
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions integration-cli/docker_api_swarm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,57 @@ func (s *DockerSwarmSuite) TestApiSwarmServicesStateReporting(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)
Expand Down

0 comments on commit fd23156

Please sign in to comment.