Full run with requests and a dying leader succeeds.
(self)
| 104 | "got %r" % (results,)) |
| 105 | |
| 106 | def test_failed_leader(self): |
| 107 | """Full run with requests and a dying leader succeeds.""" |
| 108 | N = 10 |
| 109 | # use a bit-setting function so that we can easily ignore requests made |
| 110 | # by the failed node |
| 111 | def identity(state, input): |
| 112 | return state, input |
| 113 | nodes = self.setupNetwork(7, execute_fn=identity) |
| 114 | results = [] |
| 115 | for n in range(1, N+1): |
| 116 | req = Requester(nodes[n % 6], n, results.append) |
| 117 | self.network.set_timer(None, n+1, req.start) |
| 118 | |
| 119 | # kill the leader node at N/2 seconds (it should be stable by then). Some of the |
| 120 | # Requester roles were attached to this node, so we fake success of those requests |
| 121 | # since we don't know what state they're in right now. |
| 122 | def is_leader(n): |
| 123 | try: |
| 124 | leader_role = [c for c in n.roles if isinstance(c, Leader)][0] |
| 125 | return leader_role.active |
| 126 | except IndexError: |
| 127 | return False |
| 128 | def kill_leader(): |
| 129 | active_leader_nodes = [n for n in nodes if is_leader(n)] |
| 130 | if active_leader_nodes: |
| 131 | active_leader = active_leader_nodes[0] |
| 132 | active_idx = nodes.index(active_leader) |
| 133 | # append the N's that this node was requesting |
| 134 | for n in range(1, N+1): |
| 135 | if n % 6 == active_idx: |
| 136 | results.append(n) |
| 137 | self.kill(active_leader) |
| 138 | self.network.set_timer(None, N/2, kill_leader) |
| 139 | |
| 140 | self.network.set_timer(None, 15, self.network.stop) |
| 141 | self.network.run() |
| 142 | self.assertEqual(set(results), set(xrange(1, N+1))) |
nothing calls this directly
no test coverage detected