'A FSM doing convergence that receives a stop input and then a status
update continues on to next convergence iteration (i.e. stop
ends up being ignored).
Note: A stop input implies that the client has changed.'

def test_convergence_stop_then_status_update(self):

    local_state = NodeState(hostname=u'192.0.2.123')
    local_state2 = NodeState(hostname=u'192.0.2.123')
    configuration = Deployment(nodes=frozenset([to_node(local_state)]))
    state = DeploymentState(nodes=[local_state])
    action = ControllableAction(result=Deferred())
    action2 = ControllableAction(result=Deferred())
    deployer = ControllableDeployer(local_state.hostname, [succeed(local_state), succeed(local_state2)], [action, action2])
    client = self.make_amp_client([local_state])
    reactor = Clock()
    loop = build_convergence_loop_fsm(reactor, deployer)
    loop.receive(_ClientStatusUpdate(client=client, configuration=configuration, state=state))
    client2 = self.make_amp_client([local_state2])
    configuration2 = Deployment(nodes=frozenset([to_node(local_state)]))
    state2 = DeploymentState(nodes=[local_state])
    loop.receive(ConvergenceLoopInputs.STOP)
    loop.receive(_ClientStatusUpdate(client=client2, configuration=configuration2, state=state2))
    action.result.callback(None)
    reactor.advance(_UNCONVERGED_DELAY)
    self.assertTupleEqual((deployer.calculate_inputs, client.calls, client2.calls), ([(local_state, configuration, state), (local_state2, configuration2, state2)], [(NodeStateCommand, dict(state_changes=(local_state,)))], [(NodeStateCommand, dict(state_changes=(local_state2,)))]))
