From a8a57309426ce85d1fa2e3439766414123469391 Mon Sep 17 00:00:00 2001 From: Vlada Dusek Date: Tue, 2 Jun 2026 15:28:09 +0200 Subject: [PATCH 1/2] 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. --- tests/integration/test_webhook_dispatch.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/integration/test_webhook_dispatch.py b/tests/integration/test_webhook_dispatch.py index 4101267d..30ad4c13 100644 --- a/tests/integration/test_webhook_dispatch.py +++ b/tests/integration/test_webhook_dispatch.py @@ -69,10 +69,15 @@ async def test_webhook_dispatch_list_pagination(client: ApifyClient | ApifyClien # `desc=True` must return dispatches in non-increasing `created_at` order. created_ats = [d.created_at for d in page.items if d.created_at is not None] assert created_ats == sorted(created_ats, reverse=True) - # `offset` must move the window — second page must not start with the same id as the first - # (only meaningful when the first page is full, i.e. at least 5 items exist). - if len(page.items) == 5: - next_page = await maybe_await(client.webhook_dispatches().list(limit=5, offset=5, desc=True)) + # `offset` must move the window — the second page must not start with the same id as the first. + # Query in ascending order so the window is anchored to the oldest dispatches: with `desc=True`, + # dispatches created by other tests running in parallel land at the head and can shift the first + # page down into the second between the two calls, making both pages start with the same id. + asc_page = await maybe_await(client.webhook_dispatches().list(limit=5, offset=0, desc=False)) + assert isinstance(asc_page, ListOfWebhookDispatches) + # Only meaningful when the first page is full, i.e. at least 5 dispatches exist. + if len(asc_page.items) == 5: + next_page = await maybe_await(client.webhook_dispatches().list(limit=5, offset=5, desc=False)) assert isinstance(next_page, ListOfWebhookDispatches) if next_page.items: - assert page.items[0].id != next_page.items[0].id + assert asc_page.items[0].id != next_page.items[0].id From eced08c7f598839942ccd11b706c03b6fb51d456 Mon Sep 17 00:00:00 2001 From: Vlada Dusek Date: Wed, 3 Jun 2026 09:46:07 +0200 Subject: [PATCH 2/2] test: make comments more concise --- tests/integration/test_webhook_dispatch.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/integration/test_webhook_dispatch.py b/tests/integration/test_webhook_dispatch.py index 30ad4c13..505e6781 100644 --- a/tests/integration/test_webhook_dispatch.py +++ b/tests/integration/test_webhook_dispatch.py @@ -70,12 +70,10 @@ async def test_webhook_dispatch_list_pagination(client: ApifyClient | ApifyClien created_ats = [d.created_at for d in page.items if d.created_at is not None] assert created_ats == sorted(created_ats, reverse=True) # `offset` must move the window — the second page must not start with the same id as the first. - # Query in ascending order so the window is anchored to the oldest dispatches: with `desc=True`, - # dispatches created by other tests running in parallel land at the head and can shift the first - # page down into the second between the two calls, making both pages start with the same id. + # Use ascending order so dispatches created by parallel tests can't shift the pages between calls. asc_page = await maybe_await(client.webhook_dispatches().list(limit=5, offset=0, desc=False)) assert isinstance(asc_page, ListOfWebhookDispatches) - # Only meaningful when the first page is full, i.e. at least 5 dispatches exist. + # Only meaningful when the first page is full. if len(asc_page.items) == 5: next_page = await maybe_await(client.webhook_dispatches().list(limit=5, offset=5, desc=False)) assert isinstance(next_page, ListOfWebhookDispatches)