Skip to content

Commit

Permalink
chore(python): reduce chance of test timeouts on github actions
Browse files Browse the repository at this point in the history
Also fixes spurious vite warnings due to the optimizeDeps dependency scanner.
  • Loading branch information
jbms committed Feb 22, 2024
1 parent 9f79ce1 commit 0f131d3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
19 changes: 15 additions & 4 deletions python/tests/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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,
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -304,6 +313,7 @@ def test_build(
)


@pytest.mark.timeout(timeout=60, func_only=True)
def test_root_build(
request,
webdriver_generic,
Expand All @@ -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(
Expand Down
14 changes: 13 additions & 1 deletion python/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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({})
Expand Down
4 changes: 1 addition & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 0f131d3

Please sign in to comment.