def test_first_ack(visitor_repository): node = GateNode(nodes[0], [nodes[1], nodes[2], nodes[3]], visitor_repository) node.state = GateNode.STATE_INITIATED assert list(node.process_message(NetworkMessage('election_voted', nodes[1], nodes[0], leader=nodes[5]))) == [] assert node.state == GateNode.STATE_INITIATED assert node.answers == {nodes[1]: nodes[5]}
def test_finishing_election(visitor_repository): node = GateNode(nodes[0], [nodes[1], nodes[2], nodes[3]], visitor_repository) node.state = GateNode.STATE_WAITING assert list(node.process_message(NetworkMessage('election_finished', nodes[1], nodes[0], leader=nodes[5]))) == \ [NetworkMessage('election_finished', nodes[0], nodes[2], leader=nodes[5]), NetworkMessage('election_finished', nodes[0], nodes[3], leader=nodes[5])] assert node.state == GateNode.STATE_IDLE assert node.leader == nodes[5]
def test_last_ack_starting_node(visitor_repository): node = GateNode(nodes[0], [nodes[1], nodes[2]], visitor_repository) node.state = GateNode.STATE_INITIATED node.answers = {nodes[1]: nodes[4]} assert list(node.process_message(NetworkMessage('election_voted', nodes[2], nodes[0], leader=nodes[5]))) == \ [NetworkMessage('election_finished', nodes[0], nodes[1], leader=nodes[5]), NetworkMessage('election_finished', nodes[0], nodes[2], leader=nodes[5])] assert node.state == GateNode.STATE_IDLE assert node.leader == nodes[5]
def test_another_election_message(visitor_repository): node = GateNode(nodes[0], [nodes[1], nodes[2], nodes[3]], visitor_repository) node.state = GateNode.STATE_ELECTING node.parent = nodes[1] assert list(node.process_message(NetworkMessage('election_started', nodes[2], nodes[0]))) == \ [NetworkMessage('election_voted', nodes[0], nodes[2], leader=None)] assert node.state == GateNode.STATE_ELECTING assert node.parent == nodes[1]
def test_last_ack_intermediate_node(visitor_repository): node = GateNode(nodes[0], [nodes[1], nodes[2], nodes[3]], visitor_repository) node.state = GateNode.STATE_ELECTING node.parent = nodes[1] node.answers = {nodes[2]: nodes[5]} assert list(node.process_message(NetworkMessage('election_voted', nodes[3], nodes[0], leader=nodes[4]))) == \ [NetworkMessage('election_voted', nodes[0], nodes[1], leader=nodes[5])] assert node.state == GateNode.STATE_WAITING assert node.answers == {nodes[2]: nodes[5], nodes[3]: nodes[4]}