........................................................................ [ 17%] ........................................................................ [ 35%] ........................................................................ [ 52%] ........................................................................ [ 70%] ........................................................................ [ 87%] .........................F......................... [100%] =================================== FAILURES =================================== ______________ test_checkout_guard_waits_for_a_concurrent_confirm ______________ @pytest.mark.django_db(transaction=True) def test_checkout_guard_waits_for_a_concurrent_confirm(): org = Organization.objects.create(name="Race Co", default_currency="TZS") branch = Branch.objects.create(organization=org, name="Main", code="RACE") for key in ("hotel", "restaurant"): EnabledCapability.objects.create(organization=org, capability_key=key) staff = User.objects.create_user(username="race-staff", password="x", organization=org) role = Role.objects.get(name="Administrator", organization__isnull=True) UserBranchRole.objects.create(user=staff, branch=branch, role=role) uom = UnitOfMeasure.objects.get(code="EA") dish = Product.objects.create( organization=org, name="Dish", sku="RACE-DISH", uom=uom, base_price=Decimal("1500"), is_stock_tracked=False, ) room = create_room(organization=org, branch=branch, number="9", base_rate=Decimal("1000")) arrive = date(2026, 10, 10) res = create_reservation( organization=org, branch=branch, room=room, guest_name="Race Guest", arrival_date=arrive, departure_date=date(2026, 10, 12), business_date=arrive, ) check_in(reservation=res, business_date=arrive) order = create_room_service_order( reservation=res, lines_data=[{"product_id": dish.id, "quantity": Decimal("1"), "station_id": None}], actor_user=staff, ) expected_version = order.transaction.version confirmed = threading.Event() release = threading.Event() errors = [] def confirm_holding_lock(): try: with transaction.atomic(): confirm_and_post_transaction( order.transaction, expected_version=expected_version, actor_user=staff ) confirmed.set() release.wait(timeout=30) except Exception as exc: # pragma: no cover - surfaced by the assertion below errors.append(exc) finally: connection.close() outcome = {} def checkout_guard(): try: from apps.capabilities.hotel.models import Reservation _assert_room_service_settled(Reservation.objects.get(pk=res.pk)) outcome["result"] = "settled" except RoomServiceUnresolved: outcome["result"] = "unresolved" except Exception as exc: # pragma: no cover outcome["result"] = repr(exc) finally: connection.close() a = threading.Thread(target=confirm_holding_lock) a.start() assert confirmed.wait(timeout=30) b = threading.Thread(target=checkout_guard) b.start() time.sleep(1.0) > assert b.is_alive(), "checkout guard should block on the order's row lock" E AssertionError: checkout guard should block on the order's row lock E assert False E + where False = is_alive() E + where is_alive = .is_alive tests/test_hotel_concurrency.py:104: AssertionError =========================== short test summary info ============================ FAILED tests/test_hotel_concurrency.py::test_checkout_guard_waits_for_a_concurrent_confirm 1 failed, 410 passed in 339.33s (0:05:39) EXIT=1