From 0f131d39d91879678284b526844f0b6246de7137 Mon Sep 17 00:00:00 2001 From: Jeremy Maitin-Shepard Date: Wed, 21 Feb 2024 16:31:10 -0800 Subject: [PATCH] chore(python): reduce chance of test timeouts on github actions Also fixes spurious vite warnings due to the optimizeDeps dependency scanner. --- python/tests/client_test.py | 19 +++++++++++++++---- python/tests/conftest.py | 14 +++++++++++++- tox.ini | 4 +--- vite.config.ts | 10 +++++++++- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/python/tests/client_test.py b/python/tests/client_test.py index 289e05e02b..f7f9379dc3 100644 --- a/python/tests/client_test.py +++ b/python/tests/client_test.py @@ -29,7 +29,9 @@ examples_dir = os.path.join(os.path.dirname(__file__), "..", "..", "examples") -def capture_screenshot_from_dev_server(webdriver, example_dir, test_fragment): +def capture_screenshot_from_dev_server( + webdriver, example_dir, test_fragment, extra_args=None +): import nodejs if sys.platform == "win32": @@ -42,7 +44,7 @@ def capture_screenshot_from_dev_server(webdriver, example_dir, test_fragment): # new session. process_group_args = dict(start_new_session=True) p = nodejs.npm.Popen( - ["run", "dev-server"], + ["run", "dev-server"] + (extra_args or []), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, @@ -94,11 +96,15 @@ def thread_func(f): def capture_screenshot_from_build( - webdriver, example_dir, test_fragment, output_dir=None + webdriver, + example_dir, + test_fragment, + output_dir=None, + extra_args=None, ): import nodejs - nodejs.npm.run(["run", "build"], cwd=example_dir, check=True) + nodejs.npm.run(["run", "build"] + (extra_args or []), cwd=example_dir, check=True) if output_dir is None: output_dir = os.path.join(example_dir, "dist") @@ -145,6 +151,7 @@ def expected_screenshot(request, webdriver_generic): webdriver=webdriver_generic, example_dir=root_dir, test_fragment=TEST_FRAGMENT, + extra_args=["--no-typecheck", "--no-lint"], ), request, ) @@ -264,6 +271,7 @@ def compare_screenshot(screenshot, expected_screenshot, extras, threshold=20): # Flaky due to https://github.com/parcel-bundler/parcel/issues/9476 @pytest.mark.flaky(reruns=5) +@pytest.mark.timeout(timeout=60, func_only=True) def test_dev_server( request, webdriver_generic, @@ -285,6 +293,7 @@ def test_dev_server( # Flaky due to https://github.com/parcel-bundler/parcel/issues/9476 @pytest.mark.flaky(reruns=5) +@pytest.mark.timeout(timeout=60, func_only=True) def test_build( request, webdriver_generic, @@ -304,6 +313,7 @@ def test_build( ) +@pytest.mark.timeout(timeout=60, func_only=True) def test_root_build( request, webdriver_generic, @@ -314,6 +324,7 @@ def test_root_build( example_dir=root_dir, output_dir=os.path.join(root_dir, "dist", "min"), test_fragment=TEST_FRAGMENT, + extra_args=["--no-typecheck", "--no-lint"], ) compare_screenshot( diff --git a/python/tests/conftest.py b/python/tests/conftest.py index 68ddef9be0..23fcb184bc 100644 --- a/python/tests/conftest.py +++ b/python/tests/conftest.py @@ -123,7 +123,19 @@ def pytest_runtest_makereport(item, call): setattr(item, "rep_" + rep.when, rep) -@pytest.fixture(params=[pytest.param(None, marks=pytest.mark.flaky(reruns=5))]) +# browser-based tests are flaky and can hang, so set a 30 second timeout and retry up to 5 times. +# Use `func_only=true` to work around https://github.com/pytest-dev/pytest-rerunfailures/issues/99 +@pytest.fixture( + params=[ + pytest.param( + None, + marks=[ + pytest.mark.flaky(reruns=5), + pytest.mark.timeout(timeout=30, func_only=True), + ], + ) + ] +) def webdriver(_webdriver_internal, request): viewer = _webdriver_internal.viewer viewer.set_state({}) diff --git a/tox.ini b/tox.ini index dd95ce668c..3876026332 100644 --- a/tox.ini +++ b/tox.ini @@ -27,9 +27,7 @@ changedir = python/tests allowlist_externals = xvfb-run -# browser-based tests are flaky and can hang, so set a 30 second timeout and retry up to 10 times. -# Use `timeout_func_only=true` to work around https://github.com/pytest-dev/pytest-rerunfailures/issues/99 -commands = pytest -vv -s --timeout=30 -o timeout_func_only=true {posargs} +commands = pytest -vv -s {posargs} [testenv:skip-browser-tests] commands = {[testenv]commands} --skip-browser-tests diff --git a/vite.config.ts b/vite.config.ts index 468ee3da3b..23cde82c7f 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -42,7 +42,15 @@ export default defineConfig( // Prevent *.html redirecting to `index.html` on dev server, to avoid confusion. appType: "mpa", optimizeDeps: { - include: ["nifti-reader-js", "pako", "numcodecs/blosc", "numcodecs/zstd"], + // Manually specify entries to avoid including `examples/`, `python/`, + // etc. + entries: [ + "./index.html", + // Manually specify bundle entrypoints since the Vite dependency scanner + // uses esbuild and does not detect the `new URL` references to the + // worker bundles. + "./src/*.bundle.js", + ], }, plugins: [ devServerPathMapPlugin({