Skip to content

Commit 25cd8e9

Browse files
authored
test: fix flaky webhook dispatch pagination test (#843)
## What & why `test_webhook_dispatch_list_pagination` was flaky on CI ([failing run](https://github.com/apify/apify-client-python/actions/runs/26631332682/job/78480663231)). The offset check fetched two `desc=True` (newest-first) pages and asserted they start with different ids. But webhook dispatches created by other tests running in parallel land at the **head** of the desc-ordered list, shifting the window between the two calls. When ≥5 new dispatches appeared between the calls, page 1's first item slid to offset 5 — so both pages started with the same id and the assertion failed. ## Fix Query the offset window in **ascending** order (`desc=False`) so it's anchored to the oldest dispatches. New dispatches append at the tail, leaving the front window stable, and the global-oldest item can never reach offset 5. This is race-free while still exercising the `offset` parameter. The `desc=True` ordering assertion is kept unchanged.
1 parent d2ab2ae commit 25cd8e9

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎tests/integration/test_webhook_dispatch.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,13 @@ async def test_webhook_dispatch_list_pagination(client: ApifyClient | ApifyClien
6969
# `desc=True` must return dispatches in non-increasing `created_at` order.
7070
created_ats = [d.created_at for d in page.items if d.created_at is not None]
7171
assert created_ats == sorted(created_ats, reverse=True)
72-
# `offset` must move the window — second page must not start with the same id as the first
73-
# (only meaningful when the first page is full, i.e. at least 5 items exist).
74-
if len(page.items) == 5:
75-
next_page = await maybe_await(client.webhook_dispatches().list(limit=5, offset=5, desc=True))
72+
# `offset` must move the window — the second page must not start with the same id as the first.
73+
# Use ascending order so dispatches created by parallel tests can't shift the pages between calls.
74+
asc_page = await maybe_await(client.webhook_dispatches().list(limit=5, offset=0, desc=False))
75+
assert isinstance(asc_page, ListOfWebhookDispatches)
76+
# Only meaningful when the first page is full.
77+
if len(asc_page.items) == 5:
78+
next_page = await maybe_await(client.webhook_dispatches().list(limit=5, offset=5, desc=False))
7679
assert isinstance(next_page, ListOfWebhookDispatches)
7780
if next_page.items:
78-
assert page.items[0].id != next_page.items[0].id
81+
assert asc_page.items[0].id != next_page.items[0].id

0 commit comments

Comments
 (0)