From 583b47ab64d5e269b0ed388ae57289a2f84462a8 Mon Sep 17 00:00:00 2001 From: Vlada Dusek Date: Thu, 4 Jun 2026 15:40:24 +0200 Subject: [PATCH] test: fix flaky Windows CI failures in statistics and browser-pool tests Give the statistics poll a generous timeout so crawler startup can reach the active state on slow CI, and run the resource-heavy Firefox launch test in isolation so it stops timing out under xdist contention. --- tests/unit/browsers/test_browser_pool.py | 7 ++++--- tests/unit/crawlers/_basic/test_basic_crawler.py | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/unit/browsers/test_browser_pool.py b/tests/unit/browsers/test_browser_pool.py index 0156073e7c..e4d4cb3cb6 100644 --- a/tests/unit/browsers/test_browser_pool.py +++ b/tests/unit/browsers/test_browser_pool.py @@ -9,7 +9,6 @@ from crawlee.browsers import BrowserPool, PlaywrightBrowserPlugin from crawlee.browsers._browser_controller import BrowserController from crawlee.browsers._types import CrawleePage -from tests.unit.utils import run_alone_on_mac if TYPE_CHECKING: from collections.abc import Mapping @@ -103,9 +102,11 @@ async def test_new_page_with_each_plugin(server_url: URL) -> None: assert browser_pool.total_pages_count == 2 -@run_alone_on_mac +@pytest.mark.run_alone async def test_with_default_plugin_constructor(server_url: URL) -> None: - # Use a generous operation timeout so that Firefox has enough time to launch on slow Windows CI. + # Launching a real Firefox browser is resource-heavy and flakes under xdist parallelism (it can time out + # even with a generous operation timeout when several workers compete for the runner). Run it alone and + # keep a generous operation timeout so that Firefox has enough time to launch on slow CI. async with BrowserPool.with_default_plugin( headless=True, browser_type='firefox', operation_timeout=timedelta(seconds=60) ) as browser_pool: diff --git a/tests/unit/crawlers/_basic/test_basic_crawler.py b/tests/unit/crawlers/_basic/test_basic_crawler.py index a3008777c3..6a39e83c12 100644 --- a/tests/unit/crawlers/_basic/test_basic_crawler.py +++ b/tests/unit/crawlers/_basic/test_basic_crawler.py @@ -1993,9 +1993,10 @@ async def test_crawler_intermediate_statistics() -> None: async def handler(_: BasicCrawlingContext) -> None: await asyncio.sleep(check_time.total_seconds() * 5) - # Start crawler and wait until statistics are initialized. + # Start crawler and wait until statistics are initialized. Use a generous timeout so that crawler startup + # has enough time to reach the active state on slow CI runners under xdist load. crawler_task = asyncio.create_task(crawler.run(['https://a.placeholder.com'])) - assert await poll_until_condition(lambda: crawler.statistics.active) + assert await poll_until_condition(lambda: crawler.statistics.active, timeout=30) # Wait some time and check that runtime is updated. await asyncio.sleep(check_time.total_seconds())