Skip to content

Commit 170600a

Browse files
committed
test: fix flaky webhook dispatch pagination test
The offset assertion compared two desc-ordered pages; dispatches created by parallel tests shifted the window between calls, making both pages start with the same id. Query in ascending order so the window is anchored to the stable oldest dispatches.
1 parent beab127 commit 170600a

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

tests/integration/test_webhook_dispatch.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,15 @@ 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+
# Query in ascending order so the window is anchored to the oldest dispatches: with `desc=True`,
74+
# dispatches created by other tests running in parallel land at the head and can shift the first
75+
# page down into the second between the two calls, making both pages start with the same id.
76+
asc_page = await maybe_await(client.webhook_dispatches().list(limit=5, offset=0, desc=False))
77+
assert isinstance(asc_page, ListOfWebhookDispatches)
78+
# Only meaningful when the first page is full, i.e. at least 5 dispatches exist.
79+
if len(asc_page.items) == 5:
80+
next_page = await maybe_await(client.webhook_dispatches().list(limit=5, offset=5, desc=False))
7681
assert isinstance(next_page, ListOfWebhookDispatches)
7782
if next_page.items:
78-
assert page.items[0].id != next_page.items[0].id
83+
assert asc_page.items[0].id != next_page.items[0].id

0 commit comments

Comments
 (0)