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()
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, stopped": for handler_name in all_handlers: setattr(hm, handler_name, handler) hm.stop() elif request.param == "All handlers set, running": for handler_name in all_handlers: setattr(hm, handler_name, handler) elif request.param == "Some handlers set, stopped": hm.on_message_received = handler hm.on_method_request_received = handler hm.stop() elif request.param == "Some handlers set, running": hm.on_message_received = handler hm.on_method_request_received = handler yield hm hm.stop()
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()