def handler_manager(self, request, inbox_manager, handler):
     hm = SyncHandlerManager(inbox_manager)
     if request.param == "Some handlers running":
         # Set an arbitrary handler
         hm.on_message_received = handler
     elif request.param == "All handlers running":
         # NOTE: this sets all handlers to be the same fn, but this doesn't really
         # make a difference in this context
         for handler_name in all_handlers:
             setattr(hm, handler_name, handler)
     yield hm
     hm.stop()
Ejemplo n.º 2
0
    def test_completes_pending(self, mocker, inbox_manager):
        hm = SyncHandlerManager(inbox_manager)

        # NOTE: We use two handlers arbitrarily here to show this happens for all handler runners
        mock_msg_handler = ThreadsafeMock()
        mock_mth_handler = ThreadsafeMock()
        msg_inbox = inbox_manager.get_unified_message_inbox()
        mth_inbox = inbox_manager.get_method_request_inbox()
        for _ in range(200):  # sufficiently many items so can't complete quickly
            msg_inbox._put(mocker.MagicMock())
            mth_inbox._put(mocker.MagicMock())

        hm.on_message_received = mock_msg_handler
        hm.on_method_request_received = mock_mth_handler
        assert mock_msg_handler.call_count < 200
        assert mock_mth_handler.call_count < 200
        hm.stop()
        time.sleep(0.1)
        assert mock_msg_handler.call_count == 200
        assert mock_mth_handler.call_count == 200
        assert msg_inbox.empty()
        assert mth_inbox.empty()
 def test_client_event_handler_runner(self, inbox_manager):
     hm = SyncHandlerManager(inbox_manager)
     assert hm._client_event_runner is None
 def test_receiver_handler_runners(self, inbox_manager, handler_name):
     hm = SyncHandlerManager(inbox_manager)
     assert hm._receiver_handler_runners[handler_name] is None
 def test_handlers(self, inbox_manager, handler_name):
     hm = SyncHandlerManager(inbox_manager)
     assert getattr(hm, handler_name) is None
 def handler_manager(self, inbox_manager):
     hm = SyncHandlerManager(inbox_manager)
     yield hm
     hm.stop()
    def handler_manager(self, request, inbox_manager, handler):
        # NOTE: this sets all handlers to be the same fn, but this doesn't really
        # make a difference in this context
        hm = SyncHandlerManager(inbox_manager)

        if request.param == "All handlers set, all stopped":
            for handler_name in all_handlers:
                setattr(hm, handler_name, handler)
            hm.stop()
        elif request.param == "All handlers set, receivers stopped, client events running":
            for handler_name in all_handlers:
                setattr(hm, handler_name, handler)
            hm.stop(receiver_handlers_only=True)
        elif request.param == "All handlers set, all running":
            for handler_name in all_handlers:
                setattr(hm, handler_name, handler)
        elif request.param == "Some receiver and client event handlers set, all stopped":
            hm.on_message_received = handler
            hm.on_method_request_received = handler
            hm.on_connection_state_change = handler
            hm.on_new_sastoken_required = handler
            hm.stop()
        elif (request.param ==
              "Some receiver and client event handlers set, receivers stopped, client events running"
              ):
            hm.on_message_received = handler
            hm.on_method_request_received = handler
            hm.on_connection_state_change = handler
            hm.on_new_sastoken_required = handler
            hm.stop(receiver_handlers_only=True)
        elif request.param == "Some receiver and client event handlers set, all running":
            hm.on_message_received = handler
            hm.on_method_request_received = handler
            hm.on_connection_state_change = handler
            hm.on_new_sastoken_required = handler
        elif request.param == "Some receiver handlers set, all stopped":
            hm.on_message_received = handler
            hm.on_method_request_received = handler
            hm.stop()
        elif request.param == "Some receiver handlers set, all running":
            hm.on_message_received = handler
            hm.on_method_request_received = handler
        elif request.param == "Some client event handlers set, all stopped":
            hm.on_connection_state_change = handler
            hm.on_new_sastoken_required = handler
            hm.stop()
        elif request.param == "Some client event handlers set, all running":
            hm.on_connection_state_change = handler
            hm.on_new_sastoken_required = handler

        yield hm
        hm.stop()
Ejemplo n.º 8
0
def handler_manager(inbox_manager):
    return SyncHandlerManager(inbox_manager)