def handler_manager(self, mocker, request, inbox_manager): hm = AsyncHandlerManager(inbox_manager) if request.param == "Some handlers running": # Set an arbitrary handler hm.on_message_received = mocker.MagicMock() elif request.param == "All handlers running": for handler_name in all_handlers: setattr(hm, handler_name, mocker.MagicMock()) yield hm hm.stop()
def handler_manager(self, mocker, request, inbox_manager): hm = AsyncHandlerManager(inbox_manager) if request.param == "Some receiver handlers running": # Set an arbitrary receiver handler hm.on_message_received = mocker.MagicMock() elif request.param == "Some client event handlers running": # Set an arbitrary client event handler hm.on_connection_state_change = mocker.MagicMock() elif request.param == "Some receiver and some client event handlers running": # Set an arbitrary receiver and client event handler hm.on_message_received = mocker.MagicMock() hm.on_connection_state_change = mocker.MagicMock() elif request.param == "All handlers running": for handler_name in all_handlers: setattr(hm, handler_name, mocker.MagicMock()) yield hm hm.stop()
async def test_completes_pending(self, mocker, inbox_manager): hm = AsyncHandlerManager(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() await asyncio.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 handler_manager(self, mocker, request, inbox_manager): hm = AsyncHandlerManager(inbox_manager) if request.param == "All handlers set, stopped": for handler_name in all_handlers: setattr(hm, handler_name, mocker.MagicMock()) hm.stop() elif request.param == "All handlers set, running": for handler_name in all_handlers: setattr(hm, handler_name, mocker.MagicMock()) elif request.param == "Some handlers set, stopped": hm.on_message_received = mocker.MagicMock() hm.on_method_request_received = mocker.MagicMock() hm.stop() elif request.param == "Some handlers set, running": hm.on_message_received = mocker.MagicMock() hm.on_method_request_received = mocker.MagicMock() yield hm hm.stop()
def handler_manager(self, inbox_manager): hm = AsyncHandlerManager(inbox_manager) yield hm hm.stop()
def handler_manager(self, mocker, request, inbox_manager): hm = AsyncHandlerManager(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()