def test_should_configure_two_services_without_subscribers(): spy = SpyEvents() def assert_store(event: Event) -> BoolResult: spy.append(event) return isSuccess configurer_service_1 = RabbitMqEventConfigurerMother.with_service( "service1") configurer_service_1.configure() configurer_service_2 = RabbitMqEventConfigurerMother.with_service( "service2") configurer_service_2.configure() event = EventUserCreatedMother.random() bus = RabbitMqEventBusMother.with_service("service1") bus.publish(event) consumer = RabbitMqEventConsumerMother.default() consumer.add_handler_on_store(assert_store) consumer.start() sleep(1.0) consumer.stop() configurer_service_1.clear() configurer_service_2.clear() spy.assert_number_unique_events(1) spy.assert_first_event(event) spy.assert_last_event(event) spy.assert_count_by_event_id(event.event_id, 1)
def test_should_configure_two_services_without_subscribers_and_consuming_event_from_store_queues( publish_events_service_1, publish_events_service_2, expected_unique_events, expected_total_received_events, simulated_results_store, ): spy = SpyEvents() def assert_store(event: Event) -> BoolResult: spy.append(event) result = simulated_results_store.pop(0) return result configurer_service_1 = RabbitMqEventConfigurerMother.with_service( "service1") configurer_service_1.configure() configurer_service_2 = RabbitMqEventConfigurerMother.with_service( "service2") configurer_service_2.configure() bus_service_1 = RabbitMqEventBusMother.with_service("service1") bus_service_2 = RabbitMqEventBusMother.with_service("service2") def publish_event(bus: IEventBus, times: int): for _ in range(times): event = EventUserCreatedMother.random() bus.publish(event) publish_event(bus_service_1, publish_events_service_1) publish_event(bus_service_2, publish_events_service_2) consumer = RabbitMqEventConsumerMother.with_service("service1") consumer.add_handler_on_store(assert_store) consumer.start() sleep(1.0) consumer.stop() configurer_service_1.clear() configurer_service_2.clear() spy.assert_number_unique_events(expected_unique_events) spy.assert_number_total_events(expected_total_received_events)