def test_messagedriven_service_start(self, mock_init_broker): services = { "s1": { 'queue': "q1", 'handler': MagicMock(), 'report': { 'exchange': "e1", 'key': "k1" } }, "s2": { 'queue': "q2", 'handler': MagicMock(), RUNS_IN_OWN_THREAD: True, 'report': { 'exchange': "e2", 'key': "k2" } }, "s3": { 'queue': "q3", 'handler': MagicMock(), RUNS_IN_OWN_THREAD: False, 'report': { 'exchange': "e3", 'key': "k3" } }, } messagedriven_service = MessagedrivenService( services, 'Some name', {'thread_per_service': True}) messagedriven_service._init = MagicMock() messagedriven_service._heartbeat_loop = MagicMock() messagedriven_service.keep_running = False messagedriven_service._start_threads = MagicMock() messagedriven_service._start_thread = MagicMock() messagedriven_service.start() messagedriven_service._start_threads.assert_called_with( ['q1', 'q2', 'q3']) messagedriven_service._start_thread.assert_not_called() messagedriven_service = MessagedrivenService(services, 'Some name') messagedriven_service._init = MagicMock() messagedriven_service._heartbeat_loop = MagicMock() messagedriven_service.keep_running = False messagedriven_service._start_threads = MagicMock() messagedriven_service._start_thread = MagicMock() messagedriven_service.start() messagedriven_service._start_threads.assert_called_with(['q2']) messagedriven_service._start_thread.assert_called_with(['q1', 'q3'])
def test_messagedriven_service(self, mocked_connection, mock_init_broker): global return_method return_method = fixtures.random_string() service_definition = fixtures.get_service_fixture(handler) single_service = [v for v in service_definition.values()][0] expected_queue = single_service['queue'] messagedriven_service = MessagedrivenService(service_definition, 'Any name') messagedriven_service._init = MagicMock() messagedriven_service._start_threads = MagicMock() messagedriven_service._heartbeat_loop = MagicMock() messagedriven_service.keep_running = False messagedriven_service.start() mock_init_broker.assert_called_with() mocked_connection.assert_called_with(CONNECTION_PARAMS, {}) mocked_connection.return_value.__enter__.return_value.subscribe\ .assert_called_with([expected_queue], mock.ANY) # Inner function messagedriven_service._heartbeat_loop.assert_called_once() messagedriven_service._start_threads.assert_not_called()
def test_messagedriven_service_multithreaded(self, mock_init_broker): service_definition = fixtures.get_service_fixture(handler) messagedriven_service = MessagedrivenService( service_definition, 'Some name', {'thread_per_service': True}) messagedriven_service._init = MagicMock() messagedriven_service._start_threads = MagicMock() messagedriven_service._heartbeat_loop = MagicMock() messagedriven_service.keep_running = False messagedriven_service.start() mock_init_broker.assert_called_with() messagedriven_service._heartbeat_loop.assert_called_once() messagedriven_service._start_threads.assert_called_once()