From 77bc5aed905084e0c6618e1d9a606edd15ec2e8b Mon Sep 17 00:00:00 2001 From: Jeff West Date: Sun, 17 May 2026 08:37:17 -0500 Subject: [PATCH] test(integration): poll subaccount fixture for eventual consistency POST /portfolio/subaccounts returns the new subaccount_number immediately, but GET /portfolio/subaccounts/balances lags by ~1.0-1.5s before the new account appears in the list. The ephemeral_subaccount fixture asserted the number was visible immediately after create, so it failed when the list hadn't propagated yet. Replaced the immediate return with a 10s poll loop on list_balances (0.5s interval). Soft-skips with a clear message if the new number never appears, so future demo-side issues don't masquerade as test bugs. Closes 1 of 11 integration-test failures (#124). Running tally: A (#126=4) + B (#127=1) + E (this=1) = 6 of 11. Co-Authored-By: Claude Opus 4.7 (1M context) --- tests/integration/test_subaccounts.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/integration/test_subaccounts.py b/tests/integration/test_subaccounts.py index cf619e2..9f92db5 100644 --- a/tests/integration/test_subaccounts.py +++ b/tests/integration/test_subaccounts.py @@ -16,6 +16,7 @@ from __future__ import annotations import logging +import time import uuid import pytest @@ -56,13 +57,29 @@ def ephemeral_subaccount(sync_client: KalshiClient) -> int: POST /portfolio/subaccounts has no DELETE counterpart and creates a permanent subaccount on demo. Session-scoped caching minimizes the number of orphans the suite leaves behind to one per run. + + Demo /portfolio/subaccounts/balances lags behind /portfolio/subaccounts + by roughly 1 second after create (observed ~1.0-1.5s in probes). Poll + list_balances until the new number shows up so downstream assertions + aren't racing the demo's eventual consistency. """ try: resp = sync_client.subaccounts.create() except KalshiValidationError as e: pytest.skip(f"demo refused create subaccount: {e}") - logger.info("Created demo subaccount %s for test run", resp.subaccount_number) - return resp.subaccount_number + created = resp.subaccount_number + logger.info("Created demo subaccount %s for test run", created) + + deadline = time.monotonic() + 10.0 + while time.monotonic() < deadline: + balances = sync_client.subaccounts.list_balances() + if any(b.subaccount_number == created for b in balances.subaccount_balances): + return created + time.sleep(0.5) + pytest.skip( + f"demo did not surface created subaccount {created} in list_balances " + f"within 10s — likely demo-side propagation issue" + ) @pytest.mark.integration