'A FSM doing convergence that receives a stop input stops when the
convergence iteration finishes.'

def test_convergence_stop(self):

    local_state = NodeState(hostname=u'192.0.2.123')
    configuration = Deployment(nodes=frozenset([to_node(local_state)]))
    state = DeploymentState(nodes=[local_state])
    action = ControllableAction(result=Deferred())
    deployer = ControllableDeployer(local_state.hostname, [succeed(local_state)], [action])
    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))
    loop.receive(ConvergenceLoopInputs.STOP)
    action.result.callback(None)
    reactor.advance(_UNCONVERGED_DELAY)
    expected = ([(local_state, configuration, state)], [(NodeStateCommand, dict(state_changes=(local_state,)))], ConvergenceLoopStates.STOPPED, [])
    actual = (deployer.calculate_inputs, client.calls, loop.state, reactor.getDelayedCalls())
    self.assertTupleEqual(expected, actual)
