def test_multithreaded_runner_with_single_pipe(self): system = System( Orders | Reservations, setup_tables=True, infrastructure_class=self.infrastructure_class, ) self.set_db_uri() # with system as runner: with MultiThreadedRunner(system) as runner: order_id = create_new_order() orders_repo = runner.get(Orders).repository self.assertEqual(orders_repo[order_id].id, order_id) reservations_repo = runner.get(Reservations).repository reservation_id = Reservation.create_reservation_id(order_id) patience = 10 while True: try: self.assertEqual( reservations_repo[reservation_id].order_id, order_id ) except (RepositoryKeyError, AssertionError): if patience: patience -= 1 sleep(0.1) else: raise else: break
def test_singlethreaded_runner_with_single_pipe(self): system = System( Orders | Reservations, setup_tables=True, infrastructure_class=self.infrastructure_class, ) with system as runner: orders = runner.get(Orders) order_id = orders.create_new_order() self.assertEqual(orders.repository[order_id].id, order_id) reservation_id = Reservation.create_reservation_id(order_id) reservations = runner.get(Reservations) reservations_repo = reservations.repository self.assertEqual(reservations_repo[reservation_id].order_id, order_id)
def test_orders_policy(self): # Prepare fake repository with a real Order aggregate. order = Order.__create__() fake_repository = {order.id: order} # Check order is not reserved. assert not order.is_reserved # Reservation created. event = Reservation.Created( originator_id=uuid4(), originator_topic="", order_id=order.id ) Orders().policy(repository=fake_repository, event=event) # Check order is reserved. assert order.is_reserved