def test_controller_stop_when_is_not_processing():
    mappers_manager = MapperManager()
    pending_actions = Queue()
    controller = ModelController(mappers_manager, pending_actions)
    assert controller.processing is False
    assert controller._must_stop is False
    controller.start()
    assert controller.is_alive()
    controller.stop()
    controller.join()
    assert controller._must_stop is True
    assert controller.is_alive() is False
def test_controller_cant_be_stopped_when_is_processing():
    """
        If someone tells the controller to stop and it is processing then it
        will stop when the processing finishes
    """

    mappers_manager = MapperManager()
    pending_actions = Queue()
    controller = ModelController(mappers_manager, pending_actions)
    assert controller.processing is False
    assert controller._must_stop is False
    controller.start()
    controller.processing = True
    controller.active_plugins_count = 1
    assert controller.is_alive()
    controller.stop()
    assert controller._must_stop is True
    assert controller.processing
    controller.join(timeout=2)
    assert controller.is_alive()
    controller.processing = False
    controller.join()
    assert controller.is_alive() is False
def test_controller_plugin_start_action_updates_internal_state():
    mappers_manager = MapperManager()
    pending_actions = Queue()
    controller = ModelController(mappers_manager, pending_actions)
    controller.start()
    controller.add_action((Modelactions.PLUGINSTART, "test", None))
    time.sleep(1)
    assert controller.active_plugins_count == 1
    assert controller.processing
    controller.add_action((Modelactions.PLUGINEND, "test", None))
    time.sleep(1)
    assert controller.active_plugins_count == 0
    assert controller.processing is False
    controller.stop()
    controller.join()
    assert controller.is_alive() is False