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_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]}