Example #1
0
 def setup(self):
     """
     Define StartMessage handler and PoisonPillMessage handler
     """
     self.add_handler(PoisonPillMessage,
                      PullerPoisonPillMessageHandler(self.state))
     self.add_handler(StartMessage, PullerStartHandler(self.state, 0.1))
Example #2
0
 def setup(self):
     """
     Define StartMessage handler and PoisonPillMessage handler
     """
     self.add_handler(PoisonPillMessage, PoisonPillMessageHandler())
     self.add_handler(StartMessage, PullerStartHandler())
     self.set_timeout_handler(TimeoutHandler())
Example #3
0
    def test_puller_start_handler_ctrl_socket_access(self):
        """
        handle a StartMessage with a Mocked PullerStartHandler in an other thread

        Test if :
          - each 500 ms, the handler check the control socket for message
        """

        state = PullerState(Mock(), get_fake_db(), get_fake_filter(), Mock(),
                            True, 100)
        # state.actor.socket_interface = Mock()
        state.actor.receive_control = Mock(return_value=None)
        handler = PullerStartHandler(state, 0.1)

        class TestThread(Thread):
            def run(self):
                handler.handle(StartMessage())

        nb_call = state.actor.socket_interface.receive_control.call_count
        assert nb_call == 0

        thread = TestThread()
        thread.start()

        for i in range(4):
            time.sleep(0.5)
            new_nb_call = handler.state.actor.receive_control.call_count
            assert new_nb_call > nb_call
            nb_call = new_nb_call

        state.alive = False
Example #4
0
    def test_puller_start_handler(self):
        """
        Test the StartHandler of PullerActor
        """

        # Define PullerState
        fake_database = get_fake_db()
        fake_socket_interface = get_fake_socket_interface()
        fake_filter = get_fake_filter()
        puller_state = PullerState(Mock(), fake_database, fake_filter,
                                   HWPCModel(), False, 100)
        puller_state.actor.receive_control = Mock(return_value=None)

        assert puller_state.initialized is False

        # Define StartHandler
        start_handler = PullerStartHandler(puller_state, 0.1)

        # Test Random message when state is not initialized
        to_send = [OKMessage(), ErrorMessage("Error"), create_report_root({})]
        for msg in to_send:
            start_handler.handle(msg)
            assert fake_database.method_calls == []
            assert fake_socket_interface.method_calls == []
            assert fake_filter.method_calls == []
            assert puller_state.initialized is False

        # Try to initialize the state
        start_handler.handle(StartMessage())
        assert puller_state.initialized is True
Example #5
0
    def test_puller_start_handler(self):
        """
        Test the StartHandler of PullerActor
        """

        # Define PullerState
        fake_database = get_fake_db()
        fake_socket_interface = get_fake_socket_interface()
        fake_filter = get_fake_filter()
        puller_state = PullerState(Actor._initial_behaviour,
                                   fake_socket_interface, mock.Mock(),
                                   fake_database, fake_filter)

        assert puller_state.initialized is False

        # Define StartHandler
        start_handler = PullerStartHandler()

        # Test Random message when state is not initialized
        to_send = [OKMessage(), ErrorMessage("Error"), create_report_root({})]
        for msg in to_send:
            start_handler.handle(msg, puller_state)
            assert fake_database.method_calls == []
            assert fake_socket_interface.method_calls == []
            assert fake_filter.method_calls == []
            assert puller_state.initialized is False

        # Try to initialize the state
        start_handler.handle(StartMessage(), puller_state)
        assert puller_state.initialized is True