Skip to content

Commit

Permalink
Add more complicated demotion testcases
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
  • Loading branch information
tonistiigi committed Jul 8, 2016
1 parent 8a50315 commit a3f1577
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion integration-cli/docker_api_swarm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package main

import (
"fmt"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -298,7 +299,36 @@ func (s *DockerSwarmSuite) TestApiSwarmPromoteDemote(c *check.C) {
time.Sleep(100 * time.Millisecond)
}

// todo: test raft qourum stability
// Demoting last node should fail
node := d1.getNode(c, d1.NodeID)
node.Spec.Role = swarm.NodeRoleWorker
url := fmt.Sprintf("/nodes/%s/update?version=%d", node.ID, node.Version.Index)
status, out, err := d1.SockRequest("POST", url, node.Spec)
c.Assert(err, checker.IsNil)
c.Assert(status, checker.Equals, http.StatusInternalServerError, check.Commentf("output: %q", string(out)))
c.Assert(string(out), checker.Contains, "last manager of the swarm")
info, err = d1.info()
c.Assert(err, checker.IsNil)
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive)
c.Assert(info.ControlAvailable, checker.Equals, true)

// Promote already demoted node
d1.updateNode(c, d2.NodeID, func(n *swarm.Node) {
n.Spec.Role = swarm.NodeRoleManager
})

for i := 0; ; i++ {
info, err := d2.info()
c.Assert(err, checker.IsNil)
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive)
if info.ControlAvailable {
break
}
if i > 100 {
c.Errorf("node did not turn into manager")
}
time.Sleep(100 * time.Millisecond)
}
}

func (s *DockerSwarmSuite) TestApiSwarmServicesCreate(c *check.C) {
Expand Down

0 comments on commit a3f1577

Please sign in to comment.