test(spend): wait for the scheduled reset to commit before reading the reset row (#52128)

Co-authored-by: mateo <277851410+mateo-berri@users.noreply.github.com>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
devin-ai-integration[bot] 2026-11-16 21:55:56 +00:00 • committed by GitHub
parent 8ba2b23818
commit 2f08fef695
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -121,6 +121,17 @@ def _blocked_reset_updates(table: str) -> int:
return int(str(rows[0]["blocked"]))
def _reset_committed(table: str, column: str, identity: str) -> bool:
with psycopg.connect(os.environ["DATABASE_URL"]) as observer:
row: Final = observer.execute(
sql.SQL("SELECT budget_reset_at > now() FROM {} WHERE {} = %s").format(
sql.Identifier(table), sql.Identifier(column)
),
(identity,),
).fetchone()
return row is not None and row[0] is True
@pytest.mark.parametrize("entity", ("key", "user", "team"))
@pytest.mark.parametrize(
("workers", "spend", "increment", "rollover", "reset_timezone"),
@ -213,6 +224,9 @@ def test_scheduled_reset_preserves_new_spend_and_never_leaves_roundoff(
)
gate.commit()
eventually(lambda: _blocked_reset_updates(table), lambda count: count == 0, seconds=30)
eventually(
lambda: _reset_committed(table, column, identity), lambda committed: committed, seconds=30
)
with psycopg.connect(os.environ["DATABASE_URL"]) as observer:
result: Final = observer.execute(
sql.SQL(