From c2a9d6a284c1d95708f64b04991a298f8c7a9058 Mon Sep 17 00:00:00 2001 From: Taewoon Kim Date: Fri, 27 Nov 2026 20:02:49 +0900 Subject: [PATCH 1/2] ci: a pull request tests one platform and one Python, in shards, with a cached native library A push to a pull request made me wait a median of 34 minutes. The stages ran one after the other, each could wait for a shared runner, and the two long ones (the native image build and each test suite) were single jobs. A pull request now tests Linux x86-64 on Python 3.14 only. Each suite is cut into shards that run side by side (2 for arcadedb-jvm, 3 for arcadedb; scripts/shard_tests.py), the native library of linux-x86_64 is restored from a cache keyed on everything it is built from, the examples run in the full tier only, and the summary and crash report jobs that would queue again after the last leg are skipped in the fast tier. Dependabot and ci:full pull requests, main, the nightly run, manual runs and releases keep their legs; a release never reads or writes the cache. Closes #517 --- .github/workflows/report-red-main.yml | 4 +- .github/workflows/test-jvm.yml | 40 +++--- .github/workflows/test-native.yml | 119 +++++++++++++----- .github/workflows/test-python-examples.yml | 33 +++-- CONTRIBUTING.md | 10 +- docs/modules/ROOT/pages/development/ci.adoc | 49 +++++--- native/wheel/parity_wheel.py | 22 ++++ scripts/ci_tier.py | 63 ++-------- scripts/select_matrix.py | 63 +++++----- scripts/select_native_matrix.py | 40 +++--- scripts/shard_tests.py | 82 ++++++++++++ tests/conftest.py | 41 ++++++ tests/test_ci_tier.py | 122 ++++-------------- tests/test_select_matrix.py | 69 ++++++---- tests/test_select_native_matrix.py | 133 +++++++++++++++----- tests/test_shard_tests.py | 61 +++++++++ 16 files changed, 614 insertions(+), 337 deletions(-) create mode 100644 scripts/shard_tests.py create mode 100644 tests/test_shard_tests.py diff --git a/.github/workflows/report-red-main.yml b/.github/workflows/report-red-main.yml index fa1ceec3..25fcffee 100644 --- a/.github/workflows/report-red-main.yml +++ b/.github/workflows/report-red-main.yml @@ -1,7 +1,7 @@ # Opens or updates one issue when a test workflow is red on `main` or in a nightly run (ArcadeData/arcadedb-python#447). # -# A pull request runs only the fast tier (Linux x86-64, #443), so a failure that only macOS, Windows, arm64 or an example leg shows is first seen -# on `main` after the merge. The badges in the README show it, but nobody has to look at them. This workflow is the push that does not wait for a look. +# A pull request runs only the fast tier (Linux x86-64, one Python, #443 and #517), so a failure that only macOS, Windows, arm64, another +# Python or an example leg shows is first seen on `main` after the merge. The badges in the README show it, but nobody has to look at them. This workflow is the push that does not wait for a look. # # It reacts to the end of `Test JVM (arcadedb-jvm)`, `Test native (arcadedb)`, `Test native (engine snapshot)` (the weekly native run # against upstream's engine snapshot) and `Test Python Examples`, and only when the run was diff --git a/.github/workflows/test-jvm.yml b/.github/workflows/test-jvm.yml index 7431bbda..15543d4f 100644 --- a/.github/workflows/test-jvm.yml +++ b/.github/workflows/test-jvm.yml @@ -251,14 +251,17 @@ jobs: arcadedb-tag: ${{ steps.jars.outputs.arcadedb-tag }} matrix: ${{ steps.matrix.outputs.matrix }} wheel-matrix: ${{ steps.matrix.outputs.wheel-matrix }} + # "true" for a pull request of the fast tier: its test leg is sharded and the summary job does not run + fast-pr: ${{ steps.matrix.outputs.fast-pr }} steps: - name: Checkout code uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 # The platform x Python legs of this run (scripts/select_matrix.py). A pull request runs - # the fast tier (linux/amd64 only); every other event runs the legs of the full tier. The - # organisation shares one runner cap with ArcadeData/arcadedb, so a pull request does not - # wait for the macOS and Windows runners. A pull request with the label ci:full, and one + # the fast tier (linux/amd64 on the newest Python, in two shards that run side by side, so + # that its checks finish in about 10 minutes); every other event runs the legs of the full + # tier. The organisation shares one runner cap with ArcadeData/arcadedb, so a pull request + # does not wait for the macOS and Windows runners. A pull request with the label ci:full, and one # Dependabot opened, runs the legs of a push to main: scripts/ci_tier.py turns its event # into pull_request_full (it reads the labels again from the API, so a re-run after adding # the label is enough). @@ -284,6 +287,8 @@ jobs: echo "$wheel_matrix" echo "matrix=$matrix" >> "$GITHUB_OUTPUT" echo "wheel-matrix=$wheel_matrix" >> "$GITHUB_OUTPUT" + if [ "$EVENT_NAME" = pull_request ]; then fast_pr=true; else fast_pr=false; fi + echo "fast-pr=$fast_pr" >> "$GITHUB_OUTPUT" - name: Set up Docker Buildx uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 @@ -448,7 +453,7 @@ jobs: # Third job: install the wheel of the platform into each Python and run the suite. Nothing is built here: the wheel is the file the # build job made (py3-none-), so each Python is tested against the same file that is published. test: - name: Test arcadedb (${{ matrix.platform }}, Python ${{ matrix.python-version }}) + name: Test arcadedb (${{ matrix.platform }}, Python ${{ matrix.python-version }}${{ matrix.shard && format(', shard {0}', matrix.shard) || '' }}) runs-on: ${{ matrix.runs-on }} needs: [download-jars, build] if: github.event_name != 'pull_request' || github.event.pull_request.draft == false @@ -457,10 +462,10 @@ jobs: fail-fast: false # Chosen by the "Select the test matrix" step of download-jars from the event that # started the run (scripts/select_matrix.py holds the platform and Python lists): - # linux/amd64 on the oldest and the newest Python on a pull request (the fast tier), 10 legs + # linux/amd64 on the newest Python, in shards, on a pull request (the fast tier), 10 legs # on a push to main and the nightly run, the full 4 platforms x 4 Pythons on a release and a manual run. # Every leg carries platform, runs-on and python-version, so the job names stay - # "Test arcadedb (, Python )". + # "Test arcadedb (, Python )"; a sharded leg also carries shard ("I/N") and suffix. matrix: ${{ fromJSON(needs.download-jars.outputs.matrix) }} steps: @@ -502,8 +507,9 @@ jobs: # work: a manylinux_2_28 container (glibc 2.28, AlmaLinux 8, the oldest system the Linux wheels are tagged for). # uv (like pip) refuses a wheel tagged above 2.28 there, so a JRE that raises the floor again fails here as well as in # scripts/verify_wheel_platform_tag.py. The wheel's own JRE does the work: no Java in the container. + # Once for a sharded leg: every shard installs the same wheel, so the first one checks it. - name: Install and run the wheel in manylinux_2_28 (Linux only) - if: startsWith(matrix.platform, 'linux/') + if: startsWith(matrix.platform, 'linux/') && (!matrix.shard || startsWith(matrix.shard, '1/')) shell: bash env: PLATFORM: ${{ matrix.platform }} @@ -550,6 +556,8 @@ jobs: shell: bash env: PYVER: ${{ matrix.python-version }} + # "I/N" on a sharded leg (tests/conftest.py then collects the files of that shard only); empty = the whole suite + SHARD: ${{ matrix.shard }} run: | echo "🧪 Testing arcadedb (with bundled JRE)..." @@ -571,7 +579,7 @@ jobs: # to the console on Windows by default (ARCADEDB_LOG_CONSOLE, src/arcadedb/_logdir.py), # which removes the cause; tests/test_log_redirect.py redirects fd 1 and 2 on purpose. set +e # Don't exit on test failures - "${UVRUN[@]}" python -m pytest tests/ -v --tb=short --color=yes --junitxml=test-results.xml + "${UVRUN[@]}" python -m pytest tests/ -v --tb=short --color=yes --junitxml=test-results.xml --shard="$SHARD" PYTEST_EXIT_CODE=$? set -e @@ -762,21 +770,25 @@ jobs: if: always() uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: - name: test-results-${{ matrix.platform == 'linux/amd64' && 'linux-amd64' || matrix.platform == 'linux/arm64' && 'linux-arm64' || matrix.platform == 'darwin/amd64' && 'darwin-amd64' || matrix.platform == 'darwin/arm64' && 'darwin-arm64' || matrix.platform == 'windows/amd64' && 'windows-amd64' || 'windows-arm64' }}-py${{ matrix.python-version }} + name: test-results-${{ matrix.platform == 'linux/amd64' && 'linux-amd64' || matrix.platform == 'linux/arm64' && 'linux-arm64' || matrix.platform == 'darwin/amd64' && 'darwin-amd64' || matrix.platform == 'darwin/arm64' && 'darwin-arm64' || matrix.platform == 'windows/amd64' && 'windows-amd64' || 'windows-arm64' }}-py${{ matrix.python-version }}${{ matrix.suffix }} path: | pytest-output.txt .coverage retention-days: 7 # Summary job that checks every leg this run started. `build` and `test` are matrices, so the result of each is "success" only when - # every leg of it passed, whatever their number: 1 build and 2 test legs on a pull request (the fast tier), 4 and 10 or 16 on the - # other events. A leg that failed, was cancelled or never started (its build failed) makes the result something else, and this job red. + # every leg of it passed, whatever their number: 4 build and 10 or 16 test legs. A leg that failed, was cancelled or never started + # (its build failed) makes the result something else, and this job red. + # A pull request of the fast tier skips it: it would wait for a runner of its own after the last leg (up to 8 minutes on a busy + # day), and every leg of that run is a check of the pull request already. It still runs when the first job failed (no output). test-summary: name: Test Summary - needs: [build, test] + needs: [download-jars, build, test] runs-on: ubuntu-24.04 # Skipped (not red) when the matrix was skipped for a draft PR. - if: always() && (github.event_name != 'pull_request' || github.event.pull_request.draft == false) + if: >- + always() && (github.event_name != 'pull_request' || github.event.pull_request.draft == false) + && needs.download-jars.outputs.fast-pr != 'true' steps: - name: Check test results run: | @@ -790,7 +802,7 @@ jobs: echo "" >> $GITHUB_STEP_SUMMARY echo "**Package**: arcadedb" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY - echo "**Legs**: a pull request runs linux/amd64 only (the fast tier). A push to main, the nightly run, a manual run and a pull request with the label ci:full run every platform. The jobs of this run list its legs." >> $GITHUB_STEP_SUMMARY + echo "**Legs**: a push to main, the nightly run, a manual run, a release and a pull request with the label ci:full run every platform. The jobs of this run list its legs." >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY echo "ℹ️ **Note**: Some platform/Python combinations are excluded from testing on every event:" >> $GITHUB_STEP_SUMMARY echo "- Windows ARM64 (GitHub-hosted windows-11-arm runners exist, but jpype1 1.7.1 ships no win_arm64 wheel and GraalVM CE 25.4.4.1.1 has no Windows ARM64 build, so neither package can be built there)" >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/test-native.yml b/.github/workflows/test-native.yml index 7b68f3d4..ae6e496b 100644 --- a/.github/workflows/test-native.yml +++ b/.github/workflows/test-native.yml @@ -4,23 +4,27 @@ # # A native image build takes about 5 to 30 minutes per platform and the ArcadeData organisation shares a runner cap with # upstream ArcadeDB, so the load is selective (scripts/select_native_matrix.py holds the legs, tests/test_select_native_matrix.py pins them): -# pull request only when a native path changed (the `paths` filter below); linux-x86_64, Python 3.12, no example leg (the fast tier); -# not for a draft. The example leg runs when the pull request changes the examples or their runner. With the label -# ci:full, or opened by Dependabot: the legs of a push to main (scripts/ci_tier.py decides all three) +# pull request only when a native path changed (the `paths` filter below); linux-x86_64 and the newest Python (3.14), the parity +# suite in shards, no `pyver` and no example leg (the fast tier: its checks finish in about 10 minutes, #517); not +# for a draft. With the label ci:full, or opened by Dependabot: the legs of a push to main (scripts/ci_tier.py decides) # push to main only when a native path changed; all four platforms, Python 3.12 and 3.14 # nightly all four platforms, Python 3.12 and 3.14, but only when something besides docs changed in the last 25 hours (a full run on Mondays) # dispatch all four platforms, Python 3.12 and 3.14 # workflow_call from release-native.yml with `release: true`: all four platforms, Python 3.11 to 3.14 # weekly from test-native-snapshot.yml with `engine-snapshot: true`: the legs of a pull request against upstream's engine snapshot +# +# The native library (the image build, about 11 minutes) is cached for linux-x86_64 under a key of everything it is built from: the +# files of native/ outside native/wheel/, this workflow, the engine release, GraalVM and the build settings. A pull request of the fast +# tier that changes none of them restores it and builds the wheel only. Every other run builds it, and a release never reads the cache. # This workflow never publishes: it has no id-token permission and no environment. # # Beside the full parity runs, the `pyver` job installs the already built linux-x86_64 wheel (py3-none: no rebuild) into the Pythons the full -# runs of the event leave out (main, nightly, dispatch: 3.11, 3.13; a release: none; a pull request runs only 3.11 and 3.14 of this job), into 3.15 (the full suite +# runs of the event leave out (main, nightly, dispatch: 3.11, 3.13; a release: none; a pull request runs no leg of this job), into 3.15 (the full suite # needs jpype1 and ladybug, which have no cp315 wheel yet, so 3.15 runs without the test files that need jpype1) and into the free-threaded 3.14t, and runs a small subset of the tests there (about 20 s of tests per Python). A release needs it: a leg that passes uploads a marker (native-passed-pyver-py), and release-native.yml # publishes nothing unless the legs of a release (3.15 and the free-threaded 3.14t) passed. Only linux-x86_64 is checked on them. # scripts/select_native_matrix.py decides its legs. # -# The `examples` job runs every script of examples/ against the installed wheel of each platform (Python 3.12 and 3.14; a pull request: none, or linux-x86_64 on 3.12 when it changes the examples), through +# The `examples` job runs every script of examples/ against the installed wheel of each platform (Python 3.12 and 3.14; a pull request of the fast tier: none), through # scripts/run_examples.sh, the runner test-python-examples.yml uses too. scripts/native_examples_skip.txt lists, with a reason, the examples that need the JVM package. # `examples-summary` is the one check for all its legs. They do not decide what a release publishes (release-native.yml reads the markers and the wheels only). # @@ -56,6 +60,7 @@ on: - "tests/**" - "scripts/select_native_matrix.py" - "scripts/ci_tier.py" + - "scripts/shard_tests.py" - "scripts/smoke_wheel.py" - "scripts/run_examples.sh" - "scripts/native_examples_skip.txt" @@ -115,7 +120,7 @@ on: default: "" type: string legs: - description: "full = all four platforms, Python 3.12 and 3.14; pull-request = linux-x86_64 and Python 3.12 only (what a pull request runs)" + description: "full = all four platforms, Python 3.12 and 3.14; pull-request = linux-x86_64 and Python 3.14 only, in shards (what a pull request runs)" required: false default: "full" type: choice @@ -168,6 +173,8 @@ jobs: test: ${{ steps.plan.outputs.test }} pyver: ${{ steps.plan.outputs.pyver }} examples: ${{ steps.plan.outputs.examples }} + # "true" for a pull request of the fast tier: it may restore the cached library, and the summary and report jobs do not run + fast-pr: ${{ steps.plan.outputs.fast-pr }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -250,9 +257,8 @@ jobs: set -euo pipefail run=true # A pull request runs the fast tier (one platform, one Python, no examples). scripts/ci_tier.py turns its event into - # pull_request_examples when it changes the examples or their runner (the example leg too), and into pull_request_full with the - # label ci:full or a Dependabot author (the legs of a push to main; it reads the labels again from the API, so a re-run after - # adding the label is enough). Every other event passes through unchanged. + # pull_request_full with the label ci:full or a Dependabot author (the legs of a push to main; it reads the labels again from + # the API, so a re-run after adding the label is enough). Every other event passes through unchanged. event="$(python3 -I scripts/ci_tier.py "$EVENT")" echo "legs of the event: $event" if [ "$RELEASE" = true ]; then event=release; fi @@ -269,6 +275,9 @@ jobs: fi fi echo "run=$run" >> "$GITHUB_OUTPUT" + # the pull request itself, on the fast tier: not a manual run or the weekly run that ask for the legs of a pull request + if [ "$EVENT" = pull_request ] && [ "$event" = pull_request ] && [ "${ENGINE_SNAPSHOT:-}" != true ]; then fast_pr=true; else fast_pr=false; fi + echo "fast-pr=$fast_pr" >> "$GITHUB_OUTPUT" python3 -I scripts/select_native_matrix.py "$event" >> "$GITHUB_OUTPUT" build: @@ -320,9 +329,42 @@ jobs: Invoke-RestMethod "https://astral.sh/uv/$env:UV_VERSION/install.ps1" | Invoke-Expression Add-Content -Path $env:GITHUB_PATH -Value "$env:USERPROFILE\.local\bin" + # The library of linux-x86_64 depends only on what the key below names: the files of native/ that the build reads (not + # native/wheel/, which only packs the wheel), this workflow, the engine release, GraalVM and the build settings of the leg. The + # key is computed once, before the build, for the restore and the save step. + - name: Key of the native library + id: library-key + env: + KEY_TEXT: native-lib-${{ matrix.key }}-${{ needs.plan.outputs.maven-engine }}-${{ matrix.graalvm_sha256 }}-${{ matrix.xmx }}${{ matrix.ni_extra }}-${{ hashFiles('native/pom.xml', 'native/mvnw', 'native/.mvn/**', 'native/src/**', 'native/scripts/**', '.github/workflows/test-native.yml') }} + run: echo "key=$KEY_TEXT" | tee -a "$GITHUB_OUTPUT" + + # A pull request of the fast tier that cannot change the library restores the one an earlier run built from the same inputs (of + # main, or of this pull request) and builds the wheel only. There is no restore-keys: another key is another library. A SNAPSHOT + # engine moves, so it is never read from or written to the cache, and a release neither reads nor writes it. The paths are the + # two directories the build step leaves: the library with its build log, and the Maven repository whose jars the notices check + # reads. + - name: Restore the native library + id: library + if: ${{ needs.plan.outputs.fast-pr == 'true' && matrix.key == 'linux-x86_64' && !endsWith(needs.plan.outputs.maven-engine, '-SNAPSHOT') }} + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: | + ${{ runner.temp }}/lib + ${{ runner.temp }}/m2 + key: ${{ steps.library-key.outputs.key }} + + - name: Show the restored library + if: ${{ steps.library.outputs.cache-hit == 'true' }} + run: | + set -euo pipefail + echo "::notice::the native library is restored from the cache, no image is built in this run" + cat "$T/lib/build.done" + cat "$T/lib/sha256.txt" + ls -l "$T/lib" + # The builder heap is 12g (8g ran out of memory on the laptop, 2026-10-25): swap keeps a 16 GB runner from being killed. - name: Add swap - if: ${{ matrix.kind == 'linux' }} + if: ${{ matrix.kind == 'linux' && steps.library.outputs.cache-hit != 'true' }} run: | set -euo pipefail sudo fallocate -l 8G /swapfile.native @@ -390,7 +432,7 @@ jobs: # -march=compatibility, -J-Xmx12g, -H:-VectorAPISupport, fastops.mode 1, inside the manylinux_2_28 container (glibc 2.28) so the # glibc floor of libarcadedb.so is a guarantee, not a property of the runner. - name: Build the native image in manylinux_2_28 - if: ${{ matrix.kind == 'linux' }} + if: ${{ matrix.kind == 'linux' && steps.library.outputs.cache-hit != 'true' }} env: ENGINE: ${{ needs.plan.outputs.maven-engine }} MANYLINUX_IMAGE: ${{ matrix.container }} @@ -417,7 +459,7 @@ jobs: bash native/scripts/build-image.sh /out ' || { tail -n 80 "$T/lib/build.log" || true; exit 1; } # the container ran as root: give the files back to the runner user - sudo chown -R "$(id -u):$(id -g)" "$T/lib" "$GITHUB_WORKSPACE" + sudo chown -R "$(id -u):$(id -g)" "$T/lib" "$T/m2" "$GITHUB_WORKSPACE" cat "$T/lib/build.done" cat "$T/lib/sha256.txt" ls -l "$T/lib" @@ -621,8 +663,20 @@ jobs: if-no-files-found: ignore retention-days: 30 + # Last, and only after every gate above passed (a failed step skips it). A push to main and the nightly run save the library + # that every pull request can read; a pull request that built its own saves it for its next push. A key that exists already is + # left as it is. + - name: Save the native library + if: ${{ steps.library.outputs.cache-hit != 'true' && matrix.key == 'linux-x86_64' && !inputs.release && !endsWith(needs.plan.outputs.maven-engine, '-SNAPSHOT') && github.event_name != 'workflow_dispatch' }} + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: | + ${{ runner.temp }}/lib + ${{ runner.temp }}/m2 + key: ${{ steps.library-key.outputs.key }} + test: - name: Parity against the installed wheel (${{ matrix.key }}, Python ${{ matrix.python }}) + name: Parity against the installed wheel (${{ matrix.key }}, Python ${{ matrix.python }}${{ matrix.shard && format(', shard {0}', matrix.shard) || '' }}) needs: [plan, build] # A platform whose build failed has no wheel to download and shows red here; the other platforms still run. if: ${{ !cancelled() && needs.plan.outputs.run == 'true' }} @@ -679,6 +733,8 @@ jobs: - name: Run the parity suite env: FINAL: ${{ needs.plan.outputs.final }} + # "I/N" on a sharded leg (a pull request); empty = every test file + SHARD: ${{ matrix.shard }} run: | set -euo pipefail w="$(ls "$T"/wheel/*.whl)" @@ -695,7 +751,7 @@ jobs: --with polars --with pandas --with duckdb --with networkx --with "psycopg[binary]" --with adbc-driver-postgresql \ --with redis --with neo4j --with ladybug \ python native/wheel/parity_wheel.py --repo "$GITHUB_WORKSPACE" \ - --out "$T/parity/parity-wheel.tsv" --cores "0-$((cores - 1))" ${limit[@]+"${limit[@]}"} ${retry[@]+"${retry[@]}"} | tee "$T/parity/parity-wheel.run.log" + --out "$T/parity/parity-wheel.tsv" --cores "0-$((cores - 1))" --shard "$SHARD" ${limit[@]+"${limit[@]}"} ${retry[@]+"${retry[@]}"} | tee "$T/parity/parity-wheel.run.log" - name: "Gate: no failure, error, crash, timeout or uncounted skip" run: | @@ -721,7 +777,9 @@ jobs: }' "$tsv" | tee -a "$GITHUB_STEP_SUMMARY" # Reached only when the gate passed: release-native.yml reads these markers (one per platform and Python, holding the wheel file name). + # A shard ran only part of the suite, so it marks nothing (a release is never sharded). - name: Mark this leg as passed + if: ${{ !matrix.shard }} run: | set -euo pipefail mkdir -p "$T/passed" @@ -729,6 +787,7 @@ jobs: cat "$T/passed/$KEY-py$PY.ok" - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + if: ${{ !matrix.shard }} with: name: native-passed-${{ matrix.key }}-py${{ matrix.python }} path: ${{ runner.temp }}/passed/${{ matrix.key }}-py${{ matrix.python }}.ok @@ -738,7 +797,7 @@ jobs: - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 if: ${{ !cancelled() }} with: - name: native-parity-${{ matrix.key }}-py${{ matrix.python }} + name: native-parity-${{ matrix.key }}-py${{ matrix.python }}${{ matrix.suffix }} path: | ${{ runner.temp }}/parity/parity-wheel.tsv ${{ runner.temp }}/parity/parity-wheel.meta.json @@ -752,10 +811,12 @@ jobs: # issue 295 (native/wheel/report_flaky_crash.py decides: never on a pull request, only in ArcadeData/arcadedb-python). A log is not a gate: a token # that cannot write issues, a missing artifact or a gh failure print a warning and the job still ends green. release-native.yml grants the # issues permission to its call of this workflow, because a called workflow cannot hold more permission than its caller gives it. + # A pull request of the fast tier skips it: one Linux platform, no retry, and a crash is a red leg already; the job would wait for a + # runner of its own after the last leg (up to 19 minutes on a busy day). crash-report: name: Report parity crashes needs: [plan, test] - if: ${{ !cancelled() && needs.plan.outputs.run == 'true' }} + if: ${{ !cancelled() && needs.plan.outputs.run == 'true' && needs.plan.outputs.fast-pr != 'true' }} runs-on: ubuntu-24.04 timeout-minutes: 10 continue-on-error: true @@ -790,8 +851,8 @@ jobs: name: Examples on the installed wheel (${{ matrix.key }}, Python ${{ matrix.python }}) needs: [plan, build] # A platform whose build failed has no wheel to download and shows red here; the other platforms still run. - # A pull request (the fast tier) has no example leg unless it changes the examples or their runner (scripts/ci_tier.py): the list is - # empty then and the job is skipped, because an empty matrix is an error. `Examples summary` below knows that case. + # A pull request (the fast tier) has no example leg: the list is empty then and the job is skipped, because an empty matrix is an + # error. `Examples summary` below is skipped with it. if: ${{ !cancelled() && needs.plan.outputs.run == 'true' && needs.plan.outputs.examples != '[]' }} runs-on: ${{ matrix.runner }} timeout-minutes: 240 @@ -977,34 +1038,30 @@ jobs: retention-days: 3 # One check for the examples of every platform and Python: red when any leg of the `examples` job failed or the job did not run to the end. - # When the plan has no example leg on purpose (the list is `[]`: a pull request, the fast tier) it is green only if the job was skipped. - # An empty list text (the plan step failed half way) is not that case: the job must then have succeeded, so the check is red. + # When the plan has no example leg on purpose (the list is `[]`: a pull request, the fast tier) it is skipped too: it has nothing to + # check and would wait for a runner of its own. An empty list text (the plan step failed half way) is not that case: the job runs, the + # examples job did not succeed, and the check is red. examples-summary: name: Examples summary needs: [plan, examples] - if: ${{ always() && needs.plan.outputs.run == 'true' }} + if: ${{ always() && needs.plan.outputs.run == 'true' && needs.plan.outputs.examples != '[]' }} runs-on: ubuntu-24.04 timeout-minutes: 5 steps: - name: Check the examples legs env: RESULT: ${{ needs.examples.result }} - LEGS: ${{ needs.plan.outputs.examples }} run: | - want=success - if [ "$LEGS" = '[]' ]; then want=skipped; fi { echo "## Examples on the installed wheel" echo - if [ "$RESULT" != "$want" ]; then - echo "The examples job ended with: $RESULT (expected: $want). See the legs of the job \"Examples on the installed wheel\"." - elif [ "$want" = skipped ]; then - echo "No example leg in this run: a pull request runs the examples only when it changes them or their runner, or carries the label ci:full." + if [ "$RESULT" != success ]; then + echo "The examples job ended with: $RESULT (expected: success). See the legs of the job \"Examples on the installed wheel\"." else echo "All example legs passed." fi } >> "$GITHUB_STEP_SUMMARY" - [ "$RESULT" = "$want" ] + [ "$RESULT" = success ] # The cheap Python-version coverage of the wheel of linux-x86_64 (py3-none: the same file for every Python, nothing is rebuilt): a subset of # the test files, not the whole suite. The legs are the supported Pythons the full parity runs of this event leave out, plus the @@ -1019,8 +1076,8 @@ jobs: name: Python ${{ matrix.python }} on the wheel (linux-x86_64) needs: [plan, build] # The linux-x86_64 build may have failed: then there is no wheel to download and this shows red, as the test job does. - # Skipped when the list is empty, because an empty matrix is an error (every event has legs today: a pull request the oldest and the - # newest Python). No other job needs this one, so a skipped pyver job changes no summary. + # Skipped when the list is empty, because an empty matrix is an error (a pull request of the fast tier has no leg: it runs one + # Python). No other job needs this one, so a skipped pyver job changes no summary. if: ${{ !cancelled() && needs.plan.outputs.run == 'true' && needs.plan.outputs.pyver != '[]' }} runs-on: ubuntu-latest timeout-minutes: 20 diff --git a/.github/workflows/test-python-examples.yml b/.github/workflows/test-python-examples.yml index 1b0ba83c..803d4f6a 100644 --- a/.github/workflows/test-python-examples.yml +++ b/.github/workflows/test-python-examples.yml @@ -141,12 +141,10 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 # The platform x Python legs of this run (scripts/select_matrix.py). A pull request runs - # the fast tier, which has NO example leg: the examples are the slowest jobs (20 to 30 - # minutes), so they run on a push to main, in the nightly run and on a manual run. The - # matrix is then empty, `run` is false, the rest of this job and the two jobs below are - # skipped, and the summary job says so and stays green. A pull request that changes the - # examples or their runner runs the leg of linux/amd64 on the newest Python - # (pull_request_examples). A pull request with the label ci:full, and one Dependabot + # the fast tier, which has NO example leg, also when it changes the examples: the examples + # are the slowest jobs (20 to 30 minutes), so they run on a push to main, in the nightly run + # and on a manual run. The matrix is then empty, `run` is false, the rest of this job and + # the three jobs below are skipped. A pull request with the label ci:full, and one Dependabot # opened, runs the legs of a push to main (pull_request_full). scripts/ci_tier.py decides: # it reads the labels again from the API, so a re-run after adding the label is enough. # The wheel matrix is the platforms of those legs, one build each: the wheel is @@ -596,19 +594,20 @@ jobs: if-no-files-found: ignore retention-days: 14 - # Summary job that checks every leg this run started, and the one check that always reports for this workflow. - # - The run has example legs (`run` is true): green only when the build and the example legs both ended with "success". They are - # matrix jobs, so the result is one word for the whole matrix whatever the number of legs; a leg that failed, was cancelled or - # never started (its build failed) makes it something else, and this job red. - # - The run has no example leg on purpose (`run` is false: a pull request, the fast tier): green only when the first job - # succeeded and both jobs were skipped. - # - Anything else is red: the first job failed, `run` is empty, or a job that should have been skipped ran. + # Summary job that checks every leg this run started: green only when the first job, the build and the example legs all ended with + # "success". They are matrix jobs, so the result is one word for the whole matrix whatever the number of legs; a leg that failed, + # was cancelled or never started (its build failed) makes it something else, and this job red. So is a first job that failed or + # that left `run` empty. + # A run with no example leg on purpose (`run` is false: a pull request, the fast tier) skips this job too: it has nothing to check + # and would wait for a runner of its own. test-examples-summary: name: Examples Test Summary needs: [download-jars, build, test-examples] runs-on: ubuntu-latest # Skipped (not red) when the matrix was skipped for a draft PR. - if: always() && (github.event_name != 'pull_request' || github.event.pull_request.draft == false) + if: >- + always() && (github.event_name != 'pull_request' || github.event.pull_request.draft == false) + && needs.download-jars.outputs.run != 'false' steps: - name: Check test results shell: bash @@ -622,11 +621,7 @@ jobs: echo "" >> "$GITHUB_STEP_SUMMARY" echo "first job: $PLAN, example legs in this run: ${RUN:-unknown}, build: $BUILD, examples: $LEGS" - if [ "$PLAN" = success ] && [ "$RUN" = false ] && [ "$BUILD" = skipped ] && [ "$LEGS" = skipped ]; then - echo "⏭️ **No example leg in this run**" >> "$GITHUB_STEP_SUMMARY" - echo "" >> "$GITHUB_STEP_SUMMARY" - echo "A pull request runs the examples only when it changes them or their runner, or carries the label ci:full. A push to main, the nightly run and a manual run run them on every platform." >> "$GITHUB_STEP_SUMMARY" - elif [ "$PLAN" = success ] && [ "$RUN" = true ] && [ "$BUILD" = success ] && [ "$LEGS" = success ]; then + if [ "$PLAN" = success ] && [ "$RUN" = true ] && [ "$BUILD" = success ] && [ "$LEGS" = success ]; then echo "✅ **Every leg of this run passed example testing!**" >> "$GITHUB_STEP_SUMMARY" echo "" >> "$GITHUB_STEP_SUMMARY" echo "All examples ran successfully on every leg this run started, against one wheel built for each platform. The jobs of this run list its legs." >> "$GITHUB_STEP_SUMMARY" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bd4f65e8..c1515605 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -146,13 +146,13 @@ shellcheck and hadolint run as `docker_image` hooks (Docker pulls the images aut CI has two tiers, so that a pull request does not wait for the macOS and Windows runners that the organisation shares with ArcadeData/arcadedb. -- **A pull request runs the fast tier.** The static checks (pre-commit, Bandit, the dependency audits) run as before. The builds and tests run on Linux x86-64 only: the `arcadedb-jvm` wheel with the tests on Python 3.11 and 3.14 and, when a native path changed, the native image and wheel with the parity suite on Python 3.12 and a short subset on Python 3.11 and 3.14. The examples do not run, unless the pull request changes a file under `examples/` or what runs them (`scripts/run_examples.sh`, `scripts/native_examples_skip.txt`, `test-python-examples.yml`). A pull request that changes only documentation runs no platform job. -- **`main` runs the full tier.** A push to `main` and the nightly run (03:00 to 04:00 UTC) test all four platforms (Linux x86-64, Linux arm64, macOS arm64 and Windows x86-64) and run the examples on each. A release tests every platform on every Python version. -- **To run the full tier on a pull request**, add the label `ci:full`, then push a commit or choose "Re-run all jobs" on its test workflows. The pull request then runs what a push to `main` runs. Use it for a change that can behave differently on another platform: file paths, processes and signals, the wheel build, the native library, a workflow file. If you cannot add labels, ask for it in the pull request. Dependabot pull requests always run the full tier. +- **A pull request runs the fast tier**, which is meant to finish in about 10 minutes. The static checks (pre-commit, Bandit, the dependency audits) run as before. The builds and tests run on one platform and one Python, Linux x86-64 and Python 3.14: the `arcadedb-jvm` wheel with its tests in two shards and, when a native path changed, the native wheel with the parity suite in three shards. The native library is taken from a cache unless the pull request changes what it is built from. The examples and the other Python versions do not run. A pull request that changes only documentation runs no platform job. +- **`main` runs the full tier.** A push to `main` and the nightly run (03:00 to 04:00 UTC) test all four platforms (Linux x86-64, Linux arm64, macOS arm64 and Windows x86-64), more Python versions, and run the examples on each platform. A release tests every platform on every Python version. +- **To run the full tier on a pull request**, add the label `ci:full`, then push a commit or choose "Re-run all jobs" on its test workflows. The pull request then runs what a push to `main` runs. Use it for a change that can behave differently on another platform or Python: file paths, processes and signals, the wheel build, the native library, the examples, a workflow file. If you cannot add labels, ask for it in the pull request. Dependabot pull requests always run the full tier. -The wait of a pull request is set by the native image build and the parity suite that follows it. A pull request that changes no native path waits for the `arcadedb-jvm` tests only. +The wait of a pull request is the longer of the `arcadedb-jvm` tests and the native workflow. A pull request that changes the native library waits for its image build too. Time spent waiting for a shared runner comes on top. -A problem that only another platform or an example shows is found on `main` after the merge: the badges at the top of the README turn red, and the fix or the revert comes before the next release. A red full run on `main` or in the nightly runs also opens an issue, `Full CI is red on main: ` (`report-red-main.yml`): one issue for each test workflow, a later red run adds a comment to it, a green run adds "Green again", and a person closes it. A known flaky failure goes under its own issue, such as #409 for the vector read-your-writes race, and the issue of the run is closed as a duplicate. [Continuous integration](docs/modules/ROOT/pages/development/ci.adoc) lists the legs of each event. +A problem that only another platform, another Python or an example shows is found on `main` after the merge: the badges at the top of the README turn red, and the fix or the revert comes before the next release. A red full run on `main` or in the nightly runs also opens an issue, `Full CI is red on main: ` (`report-red-main.yml`): one issue for each test workflow, a later red run adds a comment to it, a green run adds "Green again", and a person closes it. A known flaky failure goes under its own issue, such as #409 for the vector read-your-writes race, and the issue of the run is closed as a duplicate. [Continuous integration](docs/modules/ROOT/pages/development/ci.adoc) lists the legs of each event. A commit message starts with a short subject that says what changes and where, for example `Native find_nearest: send the query vector as one float32 array, not a Python list`. The body says why. Link the issue with `Closes #N` in the pull request. diff --git a/docs/modules/ROOT/pages/development/ci.adoc b/docs/modules/ROOT/pages/development/ci.adoc index fb1cf3e5..a5e529d1 100644 --- a/docs/modules/ROOT/pages/development/ci.adoc +++ b/docs/modules/ROOT/pages/development/ci.adoc @@ -1,5 +1,5 @@ = Continuous integration -:description: Which platforms and Python versions the CI runs for a pull request (the fast tier), and which for main, the nightly run and a release (the full tier). +:description: Which platforms and Python versions the CI runs for a pull request (the fast tier, about 10 minutes), and which for main, the nightly run and a release (the full tier). Each package has one test workflow and one release workflow: @@ -26,18 +26,37 @@ The package supports four platforms and four Python versions (3.11 to 3.14). Tha The CI has two tiers. -* The fast tier runs on every pull request: the static checks, and the builds and tests on Linux x86-64 only. It waits for no macOS, Windows or arm64 runner. It runs no example job: the examples are the slowest jobs (they build the vectors of a dataset and run 30 scripts), so they run in the full tier. A pull request that changes a file under `examples/` (not `examples/README.md`), `scripts/run_examples.sh`, `scripts/native_examples_skip.txt` or `test-python-examples.yml` runs the example legs of Linux x86-64 too. A change to the example job of `test-native.yml` does not: use the label `ci:full` for it. +* The fast tier runs on every pull request: the static checks, and the builds and tests of both packages on one platform and one Python, Linux x86-64 with the newest Python the full suites run on (3.14). It waits for no macOS, Windows or arm64 runner, and it runs no example job, also when the pull request changes the examples: they are the slowest jobs (they build the vectors of a dataset and run 30 scripts), so they run in the full tier. * The full tier runs on a push to `main`, on the nightly run, on a manual run and on a release. It tests all four platforms. A release tests every platform on every Python version. -A pull request runs the legs of a push to `main` when it carries the label `ci:full`. Add the label, then push a commit or choose "Re-run all jobs" on the test workflows of the pull request: `scripts/ci_tier.py` reads the labels again at the start of each run, so no new commit is needed. Use the label for a change that can behave differently on another platform: file paths, processes and signals, the wheel build, the native library, a workflow file. To go back to the fast tier, remove the label and push a commit. A pull request that Dependabot opened always runs the full tier, because the hourly job merges it without a reader. When the labels cannot be read, the pull request runs the full tier. +A pull request runs the legs of a push to `main` when it carries the label `ci:full`. Add the label, then push a commit or choose "Re-run all jobs" on the test workflows of the pull request: `scripts/ci_tier.py` reads the labels again at the start of each run, so no new commit is needed. Use the label for a change that can behave differently on another platform or Python: file paths, processes and signals, the wheel build, the native library, the examples or their runner, a workflow file. To go back to the fast tier, remove the label and push a commit. A pull request that Dependabot opened always runs the full tier, because the hourly job merges it without a reader; nobody waits for it. When the labels cannot be read, the pull request runs the full tier. The nightly runs start between 03:00 and 04:00 UTC, when the shared runners are least busy (issue 442 has the measurement of the queue for each hour). -A problem that only another platform shows is found on `main`, after the merge, or in the nightly run. The badges of `test-jvm.yml`, `test-native.yml` and `test-python-examples.yml` at the top of the README show the last run of each workflow on `main`, and GitHub sends a mail to the person who merged. Fix or revert before the next release. The release workflows run the full matrix again and publish nothing when a leg is red. +A problem that only another platform, another Python or an example shows is found on `main`, after the merge, or in the nightly run. The badges of `test-jvm.yml`, `test-native.yml` and `test-python-examples.yml` at the top of the README show the last run of each workflow on `main`, GitHub sends a mail to the person who merged, and `report-red-main.yml` opens or updates an issue. Fix or revert before the next release. The release workflows run the full matrix again and publish nothing when a leg is red. -The summary jobs (`Test Summary`, `Examples Test Summary`, `Examples summary`) check the legs that the run started. A leg that failed or was cancelled makes them red in both tiers. A leg that the tier does not start is not in the run, so nothing waits for it. When a pull request has no example leg, the example jobs are skipped on purpose. The two example summaries are green for exactly that case (the plan has no leg and the job was skipped) and say so. They are red when a planned leg did not run. +The summary jobs (`Test Summary`, `Examples Test Summary`, `Examples summary`) check the legs that a run of the full tier started: a leg that failed or was cancelled makes them red. A leg that the tier does not start is not in the run, so nothing waits for it. A pull request of the fast tier shows the three as skipped, and also the job `Report parity crashes`: each would wait for a runner of its own after the last leg, and every leg is a check of the pull request already. `Test Summary` runs in the fast tier too when the first job of its workflow failed. -With the examples out of the fast tier, the wait of a pull request is set by the native workflow: the native image build, then the parity suite against the wheel that was just built (issue 442 has the timings of each job). A pull request that changes no native path does not start that workflow and waits for the `arcadedb-jvm` tests only. +== How long a pull request waits + +The checks of a pull request are meant to finish in about 10 minutes, and in 15 at the very most, counted from the creation of the runs to the end of the last job (issue 517 has the timings). Work that takes longer belongs on a push to `main`, the nightly or weekly run, or a run on demand. These things keep the fast tier short: + +* One platform and one Python for both packages. +* Each suite is cut into shards that run side by side: two for `arcadedb-jvm` (the option `--shard I/N` of `tests/conftest.py`) and three for `arcadedb` (the same option of `native/wheel/parity_wheel.py`). `scripts/shard_tests.py` makes the split from the list of test files, so every file runs in exactly one shard, and balances it with the seconds of the longest files. A new test file needs no entry there. A run that is not sharded (`main`, nightly, a manual run of all legs, a release) runs each suite whole in one job. +* The native library is cached (see <>). Without a hit, the wait is set by the image build, about 11 minutes, and the shards after it. + +The time a job waits for a runner comes on top and can be longer than the job: the runners are shared with ArcadeData/arcadedb. + +[[native-library-cache]] +== The cached native library + +Most pull requests change no file that the native image is built from, so a new build gives the same library. `test-native.yml` keeps the library of `linux-x86_64`, with its build log and the Maven jars that the notices check reads, in the GitHub Actions cache. The key names everything the image is built from: the files of `native/` outside `native/wheel/` (`pom.xml`, the Maven wrapper, `src/`, `scripts/`), `test-native.yml` itself, the engine release, the GraalVM archive and the heap and extra options of the leg. The wheel is built from the checkout in every run, so a change of the Python sources, the tests or `native/wheel/` is in it. + +* Only a pull request of the fast tier restores the cache. There is no partial match: a different key means a new image build. +* A push to `main`, the nightly run, a pull request with `ci:full` and a release always build the image. A release neither reads nor writes the cache. A `SNAPSHOT` engine (the weekly run) is never cached, because it moves. +* A push to `main` and the nightly run save the library for all pull requests. A pull request that had to build one saves it for its own next push. The library is saved after all gates of the build job passed. +* A wheel built from a restored library records the commit of its checkout as `SOURCE_COMMIT`. The Java glue in the library is the same, because the key covers it. +* A new build input outside the files above must be added to the key. `tests/test_select_native_matrix.py` fails when a new file or directory appears under `native/`. == One wheel for each platform @@ -57,8 +76,8 @@ The script `scripts/select_matrix.py` chooses the combinations. The first job of | Event | Unit tests (`Test arcadedb`) | Examples (`Test Python Examples`) | Pull request (the fast tier) -| 2 legs: `linux/amd64` on Python 3.11 and 3.14. -| None. `linux/amd64` on Python 3.14 when the pull request changes the examples or their runner. +| 1 leg in 2 shards: `linux/amd64` on Python 3.14. +| None. | Push to `main`, the nightly run, a pull request with the label `ci:full`, a Dependabot pull request | 10 legs: `linux/amd64` on all four Python versions. `linux/arm64`, `darwin/arm64` and `windows/amd64` on Python 3.11 and 3.14. @@ -69,9 +88,9 @@ The script `scripts/select_matrix.py` chooses the combinations. The first job of | All 16 combinations. |=== -The unit tests run 2 legs on a pull request (the oldest and the newest Python on `linux/amd64`), 10 legs on a push to `main` and the nightly run (all Python versions on one Linux platform, the oldest and the newest elsewhere), and all 16 combinations on a release and a manual run, like the native package: what is published is tested on every platform and Python it claims. `release-jvm.yml` calls the workflow with `release: true`, which the matrix step turns into the event `release`, because in a called workflow `github.event_name` is the caller's tag push. A pull request runs 9 jobs in these two workflows: 2 test jobs, 1 wheel build, the two `Download ArcadeDB JARs` jobs (the one of `test-python-examples.yml` only chooses the legs, and downloads nothing when there is none), the two summary jobs, `Bandit security scan` and `Dependency floor audit`. The build and the example job of `test-python-examples.yml` show as skipped, and `Examples Test Summary` is green and says that the run has no example leg. A push, the nightly run and a pull request that asks for the full tier run 40: 26 test jobs (10 and 16), 8 wheel builds (4 for each workflow) and the same six other jobs. A manual run and a release run 46, with the 6 extra unit-test legs. +The unit tests run one leg in two shards on a pull request (the newest Python on `linux/amd64`), 10 legs on a push to `main` and the nightly run (all Python versions on one Linux platform, the oldest and the newest elsewhere), and all 16 combinations on a release and a manual run, like the native package: what is published is tested on every platform and Python it claims. `release-jvm.yml` calls the workflow with `release: true`, which the matrix step turns into the event `release`, because in a called workflow `github.event_name` is the caller's tag push. A pull request runs 7 jobs in these two workflows: 2 test jobs, 1 wheel build, the two `Download ArcadeDB JARs` jobs (the one of `test-python-examples.yml` only chooses the legs, and downloads nothing when there is none), `Bandit security scan` and `Dependency floor audit`. The build and the example job of `test-python-examples.yml` and the two summary jobs show as skipped. A push, the nightly run and a pull request that asks for the full tier run 40: 26 test jobs (10 and 16), 8 wheel builds (4 for each workflow), the same four other jobs and the two summary jobs. A manual run and a release run 46, with the 6 extra unit-test legs. -The names of the test jobs do not change: `Test arcadedb (, Python )`. A check keeps its history when a pull request runs fewer of them. No check is required by a branch rule today. If one becomes required, choose a job of the fast tier or a summary job: a required check that only the full tier starts would never report on a pull request. +The names of the test jobs are `Test arcadedb (, Python )`, with `, shard I/N` after the Python on a sharded leg. A check of the full tier keeps its history. No check is required by a branch rule today. If one becomes required, choose a job that runs on every pull request: a required check that only the full tier starts would never report on a pull request, and a skipped summary job counts as passed. `release-jvm.yml` expects exactly four wheels, one for each platform, all `py3-none`. It checks the count, the tags, the sizes and the names before it publishes. The nightly run also tests against the newest `arcadedata/arcadedb:latest` image. @@ -85,7 +104,7 @@ The two packages get their engine from different places, so between releases the A JVM wheel that must carry the same engine as a release, such as the wheel of an A/B or of a release gate, comes from a manual run of `test-jvm.yml` with the release's engine tag: `gh workflow run "Test JVM (arcadedb-jvm)" -R ArcadeData/arcadedb-python --ref -f arcadedb-tag=26.11.1` (the engine of `26.11.1` and its `.postN` releases). Without the input the jars come from `latest`, the wheel carries another engine than the release, and a comparison with the release measures the engine as well as the change. The native build needs no such input, because it links a release engine by default. -A manual run of `test-native.yml` with a `devN` version may set `engine` to `A.B.C-SNAPSHOT`: `native/pom.xml` then resolves the engine jars from the Sonatype snapshot repository (snapshots on, releases off, so a release version still comes from Maven Central alone). The notices comparison of `build_wheel.py` is skipped for such a run, because `THIRD_PARTY_NOTICES.md` names a release and its jars. The plan job refuses a SNAPSHOT engine for a final or post version. A release run links a snapshot only for a `.devN` tag, and only the one pinned in `scripts/dev_engine_pin.json` (see xref:development/release.adoc[Release]); every other snapshot is refused, so a final or post release never depends on one. The `legs` input of a manual run chooses all four platforms (`full`, the default) or the one platform and one Python of a pull request (`pull-request`). +A manual run of `test-native.yml` with a `devN` version may set `engine` to `A.B.C-SNAPSHOT`: `native/pom.xml` then resolves the engine jars from the Sonatype snapshot repository (snapshots on, releases off, so a release version still comes from Maven Central alone). The notices comparison of `build_wheel.py` is skipped for such a run, because `THIRD_PARTY_NOTICES.md` names a release and its jars. The plan job refuses a SNAPSHOT engine for a final or post version. A release run links a snapshot only for a `.devN` tag, and only the one pinned in `scripts/dev_engine_pin.json` (see xref:development/release.adoc[Release]); every other snapshot is refused, so a final or post release never depends on one. The `legs` input of a manual run chooses all four platforms (`full`, the default) or the one platform and one Python of a pull request, in shards (`pull-request`). A sharded leg uploads no `native-passed-*` marker. The dev-engine bump after each release, described in xref:development/release.adoc[Release], moves `DEV_ENGINE` to the new release and closes the gap until upstream publishes the next one. @@ -140,14 +159,14 @@ To handle the issue, decide for each line whether the bindings need a change, op The workflow `test-native.yml` builds the native image of the `arcadedb` package and runs the test suite against the installed wheel. It does not follow the table above. It never publishes; `release-native.yml` calls it on a version tag. -* A pull request runs it only when native paths change: `+native/**+`, `+src/arcadedb/**+`, `+tests/**+`, `+examples/**+` (not `examples/README.md`), `pyproject.toml`, `setup.py`, `scripts/select_native_matrix.py`, `scripts/smoke_wheel.py`, `scripts/run_examples.sh`, `scripts/native_examples_skip.txt` or `test-native.yml` itself. Changes under `tests/` and `src/arcadedb/` are included because both backends share those files, so a shared test or source can break native parity without touching a native file; docs outside those paths do not run it. It then runs on `linux-x86_64` only (the fast tier): the image and the wheel, the parity suite on Python 3.12 and the `pyver` subset on Python 3.11 and 3.14. The examples run only when the pull request changes them or their runner. With the label `ci:full`, and for a Dependabot pull request, it runs the legs of a push to `main`. +* A pull request runs it only when native paths change: `+native/**+`, `+src/arcadedb/**+`, `+tests/**+`, `+examples/**+` (not `examples/README.md`), `pyproject.toml`, `setup.py`, `scripts/select_native_matrix.py`, `scripts/ci_tier.py`, `scripts/shard_tests.py`, `scripts/smoke_wheel.py`, `scripts/run_examples.sh`, `scripts/native_examples_skip.txt` or `test-native.yml` itself. Changes under `tests/` and `src/arcadedb/` are included because both backends share those files, so a shared test or source can break native parity without touching a native file; docs outside those paths do not run it. It then runs on `linux-x86_64` only (the fast tier): the library (restored from the <> or built), the wheel, and the parity suite on Python 3.14 in three shards. It runs no `pyver` and no example leg. With the label `ci:full`, and for a Dependabot pull request, it runs the legs of a push to `main`. * A push to `main` (only when a native path changed, same filter as a pull request), the nightly run (skipped when nothing changed in the last 25 hours, except on Mondays) and a manual run (dispatch) run all four platforms: `linux-x86_64`, `linux-aarch64`, `macos-arm64` and `windows-x64` (Python 3.12 and 3.14). A release (`release-native.yml` calls the workflow with `release: true`) runs the same four platforms on all four Python versions, 16 legs. -* The `pyver` job installs the already built `linux-x86_64` wheel (no rebuild) into the Pythons that the full parity runs of the event leave out (3.11 and 3.13 on a push to `main`, the nightly run and a dispatch; none on a release) into 3.15 and into the free-threaded 3.14t, and runs 13 test files there (14 where polars installs; 3.15 has no jpype1 wheel, so it leaves out the two files that need jpype1), about 20 seconds of tests per Python. A release needs it: a `pyver` leg that passes uploads the marker `native-passed-pyver-py` (it holds the file name of the wheel the leg installed), and `Verify what may be published` in `release-native.yml` requires the markers of 3.15 and 3.14t, the two legs of a release, and that both tested the `linux-x86_64` wheel that is published. A red leg stops a release before anything reaches PyPI. A pull request runs only two legs of this job, Python 3.11 and 3.14 (the oldest and the newest): 3.13, 3.15 and 3.14t run in the full tier. In the 30 days before issue 442 no `pyver` leg was red on a commit where the parity suite on Linux x86-64 was green. Only `linux-x86_64` is checked on these two Pythons: the other platforms are not tested on 3.15 and 3.14t, and the JVM package has no such job. The 3.14t leg has no polars (no free-threaded wheel exists), so it skips `test_dataframe_ingest.py`. `scripts/select_native_matrix.py` decides its legs, and `tests/test_select_native_matrix.py` and `tests/test_release_native_verify.py` pin the gate. +* The `pyver` job installs the already built `linux-x86_64` wheel (no rebuild) into the Pythons that the full parity runs of the event leave out (3.11 and 3.13 on a push to `main`, the nightly run and a dispatch; none on a release) into 3.15 and into the free-threaded 3.14t, and runs 13 test files there (14 where polars installs; 3.15 has no jpype1 wheel, so it leaves out the two files that need jpype1), about 20 seconds of tests per Python. A release needs it: a `pyver` leg that passes uploads the marker `native-passed-pyver-py` (it holds the file name of the wheel the leg installed), and `Verify what may be published` in `release-native.yml` requires the markers of 3.15 and 3.14t, the two legs of a release, and that both tested the `linux-x86_64` wheel that is published. A red leg stops a release before anything reaches PyPI. A pull request of the fast tier runs no leg of this job: every Python but 3.14 runs in the full tier. In the 30 days before issue 442 no `pyver` leg was red on a commit where the parity suite on Linux x86-64 was green. Only `linux-x86_64` is checked on these two Pythons: the other platforms are not tested on 3.15 and 3.14t, and the JVM package has no such job. The 3.14t leg has no polars (no free-threaded wheel exists), so it skips `test_dataframe_ingest.py`. `scripts/select_native_matrix.py` decides its legs, and `tests/test_select_native_matrix.py` and `tests/test_release_native_verify.py` pin the gate. * Every test file runs in its own process (`native/wheel/parity_wheel.py`). A process that dies without writing its result is a `CRASH` row in `parity-wheel.tsv` with its exit code, for example `CRASH(rc=0xC0000005,3221225477)`, and it fails the leg. On the Windows legs only (the crashes of issue 295 happen there), the harness runs such a file once more in a fresh process (`--retry-crash`). A retry that produces a result is a `FLAKY-CRASH` row: the gate lets the leg pass, the job summary lists the file with the first exit code, and on a release or a dispatch the `crash-report` job adds one comment to issue 295 (run URL, Python, wheel version, exit codes). A second crash, a failing test, a timeout and every crash on Linux or macOS stay failures. A process that wrote its result and then died in shutdown is a `DIRTY-EXIT` record (exit code, file, attempt) in the metadata, the job summary and the issue comment: it is not retried and does not fail the leg. Each Windows test process also writes a faulthandler trace, `parity-wheel-xml/.attemptN.fault.txt`, into the parity artifact of the leg. Only a retry hides a crash, so treat a `FLAKY-CRASH` as an open bug: read the trace in the artifact before a release is announced. * The four tests of `tests/test_vector_read_your_writes.py` run again when they hit a known engine race, on both packages (issue 409). The engine of 26.11.1 can miss a vector that a commit has just returned: a graph rebuild trims it between the two phases of its commit. The fix is pull request 12087 of ArcadeData/arcadedb, which is in no release yet, and the test must keep detecting the race, so it is not skipped. The rerun is in the tests (`run_with_known_race_rerun` in `tests/conftest.py`), not in a workflow, so every job that runs the file has it: the parity harness and the plain runs of the JVM build. A test body runs again on a fresh database, at most twice, and only when it failed with one of the three messages of the race (`committed vectors were not found`, `Vector search failed`, `+Record # not found+`). Any other failure, and a test that fails all three runs, fails the job. Each rerun is a `UserWarning` that names issue 409 in the warnings summary of the log. A test that passed only after a rerun carries the junit property `flaky_race`: the `TOTAL` row of `parity-wheel.tsv` counts it as `flaky_race=N`, the gate step prints a `FLAKY-RACE` line, and the `crash-report` job lists the tests in the job summary. A count never fails a leg. The rerun goes when the engine release that contains the fix is out and the file has passed 100 consecutive scheduled runs; then issue 409 is closed. -* The `examples` job runs every script of `examples/` against the installed wheel of each platform (Python 3.12 and 3.14; a pull request: no leg, or `linux-x86_64` on Python 3.12 when it changes the examples or their runner) through `scripts/run_examples.sh`, the runner that `test-python-examples.yml` uses too. `scripts/native_examples_skip.txt` lists, with a reason, the examples that need the JVM package. `Examples summary` is the one check for all its legs. These legs do not decide what a release publishes. +* The `examples` job runs every script of `examples/` against the installed wheel of each platform (Python 3.12 and 3.14; a pull request of the fast tier: no leg) through `scripts/run_examples.sh`, the runner that `test-python-examples.yml` uses too. `scripts/native_examples_skip.txt` lists, with a reason, the examples that need the JVM package. `Examples summary` is the one check for all its legs. These legs do not decide what a release publishes. * A native image build takes about 5 to 30 minutes for each platform (macOS is the slowest). The organisation shares one runner limit with upstream ArcadeDB, so do not add runs lightly. Change the paths or the matrix of `test-native.yml` only for a reason that you can write down. == Change the selection -Edit `JVM_LEGS` (unit tests on the events in `JVM_REDUCED_EVENTS`: a push and the nightly run; every other event but a pull request runs the full matrix) or `PULL_REQUEST_LEGS` (the fast tier: unit tests and examples on a pull request) in `scripts/select_matrix.py`. The legs of the native workflow are in `scripts/select_native_matrix.py`. `scripts/ci_tier.py` holds the name of the label and the paths that start the example legs, and decides whether a pull request runs the fast tier, the fast tier with the example legs, or the legs of a push. The tests `tests/test_select_matrix.py`, `tests/test_select_native_matrix.py` and `tests/test_ci_tier.py` fix the legs, so a change that shrinks them fails. When you add a Python version, add it to `PYTHONS` in the script and to the classifiers in `pyproject.toml`. A test checks that both lists are the same, that `requires-python` starts at the oldest of them and stops before the minor after the newest. When you drop one, remove it from the same places and update the counts in the test. +Edit `JVM_LEGS` (unit tests on the events in `JVM_REDUCED_EVENTS`: a push and the nightly run; every other event but a pull request runs the full matrix) or `PULL_REQUEST_LEGS` and `PULL_REQUEST_SHARDS` (the fast tier) in `scripts/select_matrix.py`. The legs and the shards of the native workflow are in `scripts/select_native_matrix.py`, and the split of the test files into shards is in `scripts/shard_tests.py`. `scripts/ci_tier.py` holds the name of the label and decides whether a pull request runs the fast tier or the legs of a push. The tests `tests/test_select_matrix.py`, `tests/test_select_native_matrix.py`, `tests/test_shard_tests.py` and `tests/test_ci_tier.py` fix the legs, so a change that shrinks them fails. When you add a Python version, add it to `PYTHONS` in the script and to the classifiers in `pyproject.toml`. A test checks that both lists are the same, that `requires-python` starts at the oldest of them and stops before the minor after the newest. When you drop one, remove it from the same places and update the counts in the test. diff --git a/native/wheel/parity_wheel.py b/native/wheel/parity_wheel.py index a68b758b..ea520f11 100644 --- a/native/wheel/parity_wheel.py +++ b/native/wheel/parity_wheel.py @@ -3,6 +3,8 @@ python native/wheel/parity_wheel.py --repo --python --out parity-native.tsv +--shard I/N runs one shard of the files (scripts/shard_tests.py): a pull request cuts the suite into N jobs that run side by side. + A run per test file in its own process (a hang or crash costs one file), junit XML per file, then one table: passed / failed / error / NOTYET (the test needs a Java-object API, reported by tests/conftest.py as a skip whose reason starts with NOTYET, raised as NotOnNativeYet) / NA-JVM (a row of NATIVE_NA_JVM_TESTS: the test reaches into the JVM on purpose) / other skips / TIMEOUT-or-crash. Files in tests/conftest.py's NATIVE_NOT_APPLICABLE are not collected (JVM-only). @@ -20,6 +22,7 @@ import argparse import ast import glob +import importlib.util import json import os import shutil @@ -51,6 +54,11 @@ def parse_args(argv=None): help="taskset core list (Linux only; ignored where taskset does not exist)", ) p.add_argument("--files", default="") + p.add_argument( + "--shard", + default="", + help="run only the files of shard I/N (scripts/shard_tests.py), after the other filters", + ) p.add_argument( "--max-notyet", type=int, @@ -168,6 +176,16 @@ def total_row(tot): ) +def shard_of(repo, files, shard): + """The files of the shard "I/N" of `files` (paths), by scripts/shard_tests.py of the checkout.""" + path = os.path.join(repo, "scripts", "shard_tests.py") + spec = importlib.util.spec_from_file_location("shard_tests", path) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + keep = set(module.select([os.path.basename(f) for f in files], shard, "native")) + return [f for f in files if os.path.basename(f) in keep] + + def main(argv=None): a = parse_args(argv) pkg = os.path.abspath(a.repo) @@ -192,6 +210,10 @@ def main(argv=None): if a.files: want = set(a.files.split(",")) files = [f for f in files if os.path.basename(f) in want] + if a.shard: + whole = len(files) + files = shard_of(pkg, files, a.shard) + print(f"SHARD {a.shard}: {len(files)} of {whole} test files", flush=True) env = dict(os.environ, PYTHONUNBUFFERED="1") env.pop( "PYTHONPATH", None diff --git a/scripts/ci_tier.py b/scripts/ci_tier.py index 16d2ac18..58655b2d 100644 --- a/scripts/ci_tier.py +++ b/scripts/ci_tier.py @@ -3,26 +3,26 @@ CI has two tiers (docs page development/ci.adoc): -- fast: a pull request. Linux x86-64 only and no example legs, the legs of the event `pull_request` in scripts/select_matrix.py and - scripts/select_native_matrix.py. A pull request that changes the examples or their runner (EXAMPLE_PATHS) also runs the example - legs of Linux x86-64: the event `pull_request_examples`. +- fast: a pull request. One platform (Linux x86-64), one Python (the newest) and no example legs, also when it changes the examples: + the legs of the event `pull_request` in scripts/select_matrix.py and scripts/select_native_matrix.py. Its checks are meant to + finish in about 10 minutes (ArcadeData/arcadedb-python#517). - full: a push to main, the nightly run, a manual run and a release, each with the legs of its own event. A pull request gets the legs of a push to main (the event `pull_request_full`) when it carries the label `ci:full` or when Dependabot opened it (nobody reads a Dependabot pull request before the hourly job merges it, so the full matrix is its only review). usage: ci_tier.py EVENT EVENT: the event that started the workflow -Prints EVENT unchanged unless it is `pull_request`. For a pull request it prints `pull_request`, `pull_request_examples` or -`pull_request_full`, and says why on stderr. It reads: +Prints EVENT unchanged unless it is `pull_request`. For a pull request it prints `pull_request` or `pull_request_full`, and says +why on stderr. It reads: PR_AUTHOR the login of the author (github.event.pull_request.user.login) PR_LABELS the label names in the event, a JSON list (toJSON(github.event.pull_request.labels.*.name)) PR_NUMBER, GITHUB_REPOSITORY, GH_TOKEN - to read the labels the pull request has now and the files it changes, through `gh api` + to read the labels the pull request has now, through `gh api` The labels are read again from the API because a re-run keeps the event of the first attempt: with the label added afterwards, "Re-run all jobs" is enough to get the full matrix, no new commit is needed. The choice fails open, never to less: when the labels -cannot be read the pull request runs the full tier, and when the changed files cannot be read it runs the example legs. +cannot be read the pull request runs the full tier. """ from __future__ import annotations @@ -38,21 +38,8 @@ FULL_AUTHORS = ("dependabot[bot]",) FAST_EVENT = "pull_request" -EXAMPLES_EVENT = "pull_request_examples" FULL_EVENT = "pull_request_full" -# A pull request that changes one of these runs the example legs: a file under examples/ (the scripts, their data loader), the -# runner both example jobs call, the list of examples the native wheel leaves out, or the workflow whose only work is to run the -# examples. examples/README.md is prose only. test-native.yml and test-jvm.yml are not here: they change for many other reasons, -# and a change to the example job of test-native.yml can ask for the full tier with the label. -EXAMPLE_DIRS = ("examples/",) -EXAMPLE_FILES = ( - "scripts/run_examples.sh", - "scripts/native_examples_skip.txt", - ".github/workflows/test-python-examples.yml", -) -NOT_EXAMPLES = ("examples/README.md",) - def _gh_lines(path: str, jq: str) -> list[str] | None: """The lines `gh api --paginate PATH --jq JQ` prints (one value on each line), or None when the call fails.""" @@ -77,25 +64,6 @@ def live_labels(repo: str, number: str) -> list[str] | None: return _gh_lines(f"repos/{repo}/issues/{number}/labels?per_page=100", ".[].name") -def changed_files(repo: str, number: str) -> list[str] | None: - """The paths the pull request changes (for a rename: the new and the old path), or None when they cannot be read.""" - if not repo or not number: - return None - return _gh_lines( - f"repos/{repo}/pulls/{number}/files?per_page=100", - ".[] | .filename, (.previous_filename // empty)", - ) - - -def touches_examples(paths: list[str]) -> bool: - """True when one of the paths is an example, its data loader or the runner of the example jobs.""" - return any( - path not in NOT_EXAMPLES - and (path in EXAMPLE_FILES or path.startswith(EXAMPLE_DIRS)) - for path in paths - ) - - def payload_labels(text: str) -> list[str]: """The label names of the event from PR_LABELS; anything that is not a JSON list of strings counts as no label.""" try: @@ -112,9 +80,8 @@ def planner_event( author: str, labels: list[str], read_live: Callable[[], list[str] | None], - read_files: Callable[[], list[str] | None], ) -> tuple[str, str]: - """(the event for the planners, why). `read_live` and `read_files` are called only when nothing else has already decided.""" + """(the event for the planners, why). `read_live` is called only when nothing else has already decided.""" if event != FAST_EVENT: return ( event, @@ -135,18 +102,7 @@ def planner_event( FULL_EVENT, f"full tier: the label {FULL_LABEL} was added after the event", ) - files = read_files() - if files is None: - return ( - EXAMPLES_EVENT, - "fast tier with the example legs: the changed files could not be read (fails open)", - ) - if touches_examples(files): - return ( - EXAMPLES_EVENT, - "fast tier with the example legs: the pull request changes the examples or their runner", - ) - return FAST_EVENT, f"fast tier: no label {FULL_LABEL}, no example changed" + return FAST_EVENT, f"fast tier: no label {FULL_LABEL}" def main(argv: list[str] | None = None) -> int: @@ -161,7 +117,6 @@ def main(argv: list[str] | None = None) -> int: env.get("PR_AUTHOR", ""), payload_labels(env.get("PR_LABELS", "")), lambda: live_labels(repo, number), - lambda: changed_files(repo, number), ) print(why, file=sys.stderr) print(event) diff --git a/scripts/select_matrix.py b/scripts/select_matrix.py index 2de768d2..0d639b31 100644 --- a/scripts/select_matrix.py +++ b/scripts/select_matrix.py @@ -3,14 +3,14 @@ The wheels support four platforms and four Python versions. -CI has two tiers. A pull request runs the fast tier: linux/amd64 only and no example legs, so it does not wait for -the macOS and Windows runners the organisation shares with ArcadeData/arcadedb, nor for the examples (the slowest -jobs). Every other event runs the full tier, and a pull request that asks for it (the label `ci:full`, or a -Dependabot author; scripts/ci_tier.py decides and passes the event `pull_request_full`) runs the legs of a push to -main. A pull request that changes the examples or their runner gets the event `pull_request_examples`: the fast -tier and the example leg of linux/amd64. - -- `jvm` (test-jvm.yml) runs 2 legs on a pull request (linux/amd64, the oldest and the newest Python), 10 legs on +CI has two tiers. A pull request runs the fast tier: one platform (linux/amd64), one Python (the newest) and no +example legs, so that its checks finish in about 10 minutes (ArcadeData/arcadedb-python#517) and it does not wait +for the macOS and Windows runners the organisation shares with ArcadeData/arcadedb. Every other event runs the full +tier, and a pull request that asks for it (the label `ci:full`, or a Dependabot author; scripts/ci_tier.py decides +and passes the event `pull_request_full`) runs the legs of a push to main. + +- `jvm` (test-jvm.yml) runs one leg on a pull request (linux/amd64, the newest Python), cut into + PULL_REQUEST_SHARDS shards that run side by side (scripts/shard_tests.py), 10 legs on a push to main and the nightly schedule, and all 16 for a release (release-jvm.yml calls the workflow with `release: true`, which test-jvm.yml passes as the event `release`) and a manual dispatch. The JVM wheel is one file for each platform (py3-none-, built once by the `build` job), so a Python version is a test leg, @@ -19,8 +19,7 @@ platform shows on any version of it. What is published, and a run started by hand before a release, gets every combination, like test-native.yml. - `examples` (test-python-examples.yml) runs no leg on a pull request (the matrix is empty and the workflow skips - its jobs), the newest Python on linux/amd64 on a pull request that changes the examples, and every combination - (16 legs) on every other event. + its jobs), also when it changes the examples, and every combination (16 legs) on every other event. The selection fails open to the full matrix: an event name this script does not know runs everything, never less (for `jvm` too: only a pull request, a push and the nightly schedule get fewer than 16 legs). @@ -33,9 +32,10 @@ `--event` defaults to $GITHUB_EVENT_NAME. The output is one line of JSON for `strategy.matrix`: {"include": [{"platform": ..., "runs-on": ..., "python-version": ...}, ...]}, and with -`--wheels` {"include": [{"platform": ..., "runs-on": ...}, ...]}. -The names of the jobs stay "Test arcadedb (, Python )", so the history of a -check is comparable before and after the selection. +`--wheels` {"include": [{"platform": ..., "runs-on": ...}, ...]}. A sharded leg (a pull request) also has +"shard" ("I/N", for pytest --shard) and "suffix" ("-shardI", for the name of its artifact). +The names of the jobs stay "Test arcadedb (, Python )", with ", shard I/N" after the Python +on a sharded leg. """ from __future__ import annotations @@ -76,26 +76,22 @@ # script does not know) runs every platform x Python combination, so the selection fails open. JVM_REDUCED_EVENTS = ("push", "schedule") -# The fast tier: the legs of a pull request, linux/amd64 only (ArcadeData/arcadedb-python#442). The other -# platforms run after the merge (the push to main) and every night, and before the merge when the pull request -# carries the label `ci:full`. +# The fast tier: the legs of a pull request, one platform (linux/amd64) and one Python, the newest +# (ArcadeData/arcadedb-python#517). The other Pythons and platforms run after the merge (the push to main) and every +# night, and before the merge when the pull request carries the label `ci:full`. # -# jvm: the oldest and the newest Python, the ends of the range. +# jvm: the newest Python, in shards that run side by side, so that no job of a pull request is long. # examples: no leg. The examples are the slowest jobs (about 20 to 30 minutes: they build the vectors of a dataset -# and run 30 scripts), so they run in the full tier. A pull request that changes the examples or their runner -# (the event `pull_request_examples`, scripts/ci_tier.py) runs them on the newest Python; their platform-specific -# code (`os.name == "nt"` branches in examples 07 to 12) and the per-platform steps of the workflow (a CPU torch -# index on macOS, UTF-8 on Windows) are covered by the full tier. +# and run 30 scripts), so they run in the full tier only, also for a pull request that changes them; their +# platform-specific code (`os.name == "nt"` branches in examples 07 to 12) and the per-platform steps of the +# workflow (a CPU torch index on macOS, UTF-8 on Windows) are covered there too. FAST_PLATFORM = "linux/amd64" PULL_REQUEST_LEGS = { - "jvm": {FAST_PLATFORM: (OLDEST, NEWEST)}, + "jvm": {FAST_PLATFORM: (NEWEST,)}, "examples": {}, } -PULL_REQUEST_EXAMPLES = "pull_request_examples" -PULL_REQUEST_EXAMPLES_LEGS = { - "jvm": PULL_REQUEST_LEGS["jvm"], - "examples": {FAST_PLATFORM: (NEWEST,)}, -} +# The shards of the one unit-test leg of a pull request: the suite takes about 9 minutes in one job. +PULL_REQUEST_SHARDS = 2 # The event scripts/ci_tier.py passes for a pull request that asks for the full tier: the legs of a push to main. PULL_REQUEST_FULL = "pull_request_full" @@ -110,6 +106,14 @@ def _legs(per_platform: dict[str, tuple[str, ...]]) -> list[dict[str, str]]: ] +def _sharded(legs: list[dict[str, str]], count: int) -> list[dict[str, str]]: + return [ + {**leg, "shard": f"{i}/{count}", "suffix": f"-shard{i}"} + for leg in legs + for i in range(1, count + 1) + ] + + def select(workflow: str, event: str) -> dict[str, list[dict[str, str]]]: """The `strategy.matrix` of `workflow` ("jvm" or "examples") for `event`.""" if workflow not in WORKFLOWS: @@ -119,9 +123,8 @@ def select(workflow: str, event: str) -> dict[str, list[dict[str, str]]]: if event == PULL_REQUEST_FULL: event = "push" if event == "pull_request": - return {"include": _legs(PULL_REQUEST_LEGS[workflow])} - if event == PULL_REQUEST_EXAMPLES: - return {"include": _legs(PULL_REQUEST_EXAMPLES_LEGS[workflow])} + legs = _legs(PULL_REQUEST_LEGS[workflow]) + return {"include": _sharded(legs, PULL_REQUEST_SHARDS)} if workflow == "jvm" and event in JVM_REDUCED_EVENTS: return {"include": _legs(JVM_LEGS)} return {"include": _legs({platform: PYTHONS for platform in RUNNERS})} diff --git a/scripts/select_native_matrix.py b/scripts/select_native_matrix.py index 581ad602..65b3f5d5 100644 --- a/scripts/select_native_matrix.py +++ b/scripts/select_native_matrix.py @@ -2,14 +2,15 @@ """Choose the legs of the native test workflow (.github/workflows/test-native.yml) for one event. A native image build takes about 5 to 30 minutes per platform and the ArcadeData organisation shares a runner cap with -upstream ArcadeDB, so a pull request (the fast tier) builds one platform (linux-x86_64), runs the parity suite on one Python (3.12) and the -`pyver` subset on the oldest and the newest Python (3.11, 3.14), and only when native paths changed (the workflow's `paths` filter). It runs -no example leg, unless it changes the examples or their runner (the event `pull_request_examples`, scripts/ci_tier.py). Push to main, the nightly run and a dispatch build all four +upstream ArcadeDB, so a pull request (the fast tier) builds one platform (linux-x86_64) and runs the parity suite on one Python, the +newest (3.14), cut into PULL_REQUEST_SHARDS shards that run side by side (scripts/shard_tests.py), and only when native paths changed +(the workflow's `paths` filter). It runs no `pyver` leg and no example leg: its checks are meant to finish in about 10 minutes +(ArcadeData/arcadedb-python#517). Push to main, the nightly run and a dispatch build all four platforms and test Python 3.12 and 3.14 on each. A release (release-native.yml calls the workflow with `release: true`) tests every supported Python (3.11 to 3.14) on all four. A pull request that asks for the full tier (the label `ci:full`, or a Dependabot author; scripts/ci_tier.py decides and passes the event `pull_request_full`) runs the legs of a push to main. -usage: select_native_matrix.py EVENT EVENT: pull_request | pull_request_examples | pull_request_full | push | schedule | workflow_dispatch | release +usage: select_native_matrix.py EVENT EVENT: pull_request | pull_request_full | push | schedule | workflow_dispatch | release Prints `build=`, `test=`, `pyver=` and `examples=` lines (GITHUB_OUTPUT format). Publishing is not decided here: release-native.yml does it. `pyver` is the cheap Python-version job (see PYVER_NOTE): a subset of the tests against the built @@ -105,9 +106,11 @@ PYVER_NOTE = "gates a release: release-native.yml requires a native-passed-pyver-py marker for each leg of a release" PULL_REQUEST_PLATFORMS = ["linux-x86_64"] -PULL_REQUEST_PYTHONS = ["3.12"] -# The legs of the `pyver` job on a pull request: the oldest and the newest supported Python. -PULL_REQUEST_PYVER = [ALL_PYTHONS[0], ALL_PYTHONS[-1]] +# The newest Python the full parity suite runs on (3.15 has no jpype1 wheel yet and gets the `pyver` subset in the full tier). +PULL_REQUEST_PYTHONS = [ALL_PYTHONS[-1]] +# The shards of the parity run of a pull request: the suite takes about 9 minutes in one job, and after a native image build +# (about 11 minutes, when the pull request changes the library) the shards must be short. +PULL_REQUEST_SHARDS = 3 MAIN_PYTHONS = ["3.12", "3.14"] # The Pythons of the `examples` job (the examples of examples/ against the installed wheel): the parity Pythons of a push, the nightly run and a # dispatch. A release runs the parity suite on every supported Python, but the examples only on these two. @@ -131,7 +134,7 @@ def pyver_legs(covered: list[str]) -> list[dict]: def select(event: str) -> dict: if event == "pull_request_full": event = "push" - if event in ("pull_request", "pull_request_examples"): + if event == "pull_request": platforms, pythons = PULL_REQUEST_PLATFORMS, PULL_REQUEST_PYTHONS elif event in ("push", "schedule", "workflow_dispatch"): platforms, pythons = ALL_PLATFORMS, MAIN_PYTHONS @@ -152,14 +155,20 @@ def select(event: str) -> dict: ] examples = [leg for leg in test if leg["python"] in EXAMPLES_PYTHONS] pyver = pyver_legs(pythons) - if event in ("pull_request", "pull_request_examples"): - # The fast tier: the Python-version subset on the ends of the supported range only (the parity suite runs the Python between - # them). 3.13, 3.15 and the free-threaded 3.14t run on main, every night and for a release (where 3.15 and 3.14t are a gate). - pyver = [leg for leg in pyver if leg["python"] in PULL_REQUEST_PYVER] if event == "pull_request": - # The examples are the slowest job (about 20 minutes): the full tier runs them, and a pull request only when it changes them. - # test-native.yml skips the job when this list is empty. - examples = [] + # The fast tier is one platform and one Python: the other Pythons (the `pyver` job) and the examples, the slowest job (about + # 20 minutes), run on main, every night, on a manual run and for a release (where 3.15 and 3.14t are a gate). + # test-native.yml skips a job when its list is empty. + pyver, examples = [], [] + test = [ + { + **leg, + "shard": f"{i}/{PULL_REQUEST_SHARDS}", + "suffix": f"-shard{i}", + } + for leg in test + for i in range(1, PULL_REQUEST_SHARDS + 1) + ] return { "build": build, "test": test, @@ -174,7 +183,6 @@ def main(argv: list[str] | None = None) -> int: "event", choices=[ "pull_request", - "pull_request_examples", "pull_request_full", "push", "schedule", diff --git a/scripts/shard_tests.py b/scripts/shard_tests.py new file mode 100644 index 00000000..e0110478 --- /dev/null +++ b/scripts/shard_tests.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 +"""Split the test files into shards, so a pull request runs one suite on several runners side by side. + +A pull request tests one platform and one Python, and each suite there is cut into N shards (scripts/select_matrix.py and +scripts/select_native_matrix.py say how many). A shard is "I/N" with I from 1 to N. Every runner computes the same split from the same +list of files, so each file runs in exactly one shard. A push to main, the nightly run, a manual run of all legs and a release are not +sharded. + +Two callers: + +- `pytest --shard I/N` (tests/conftest.py), the JVM build: one process for the shard, the other files are not collected; +- `native/wheel/parity_wheel.py --shard I/N`, the native build: one process for each file of the shard. + +The split is greedy: the files are taken from the heaviest to the lightest and each goes to the shard with the smallest total so far. +A weight is the seconds a file takes in CI. Only the files that matter for the balance are listed; a stale or missing number makes one +shard slower and never loses a file. +""" + +from __future__ import annotations + +import re +from collections.abc import Iterable + +# Seconds in the run of 2026-11-27 (linux-x86_64 / linux/amd64). Every file that is not listed counts DEFAULT_WEIGHT. +WEIGHTS: dict[str, dict[str, float]] = { + "native": { + "test_vector_product_quantization.py": 93, + "test_log_redirect.py": 69, + "test_native_vindex_bin.py": 15, + "test_column_frames.py": 15, + "test_vector_read_your_writes.py": 12, + "test_ingest_integrity.py": 11, + "test_native_column_frames_reference.py": 10, + "test_vector.py": 8, + }, + "jvm": { + "test_ingest_integrity.py": 29, + "test_column_frames.py": 20, + "test_resultset.py": 13, + "test_sigint.py": 12, + "test_typed_batch_guard.py": 12, + "test_vertex_vector_loads.py": 12, + "test_nonfinite_floats.py": 11, + "test_log_redirect.py": 11, + "test_graph_batch_single_pass.py": 10, + "test_dataframe_ingest.py": 10, + "test_bulk_insert.py": 9, + "test_columnar_readers.py": 8, + "test_typed_rows.py": 8, + "test_insert_many_typed_columns.py": 7, + "test_graph_batch_typed_jvm.py": 7, + "test_python_function_interrupt.py": 7, + "test_jar_closure.py": 7, + }, +} +DEFAULT_WEIGHT = 1.5 + + +def parse_shard(text: str) -> tuple[int, int]: + """(I, N) of "I/N" with 1 <= I <= N; anything else raises ValueError.""" + match = re.fullmatch(r"([1-9][0-9]*)/([1-9][0-9]*)", text) + if not match or int(match.group(1)) > int(match.group(2)): + raise ValueError(f"a shard is I/N with 1 <= I <= N, not {text!r}") + return int(match.group(1)), int(match.group(2)) + + +def split(files: Iterable[str], count: int, backend: str) -> list[list[str]]: + """The `count` shards of `files` (file names), each sorted; `backend` ("native" or "jvm") chooses the weights.""" + weights = WEIGHTS["native" if backend == "native" else "jvm"] + shards: list[list[str]] = [[] for _ in range(count)] + loads = [0.0] * count + for name in sorted(set(files), key=lambda n: (-weights.get(n, DEFAULT_WEIGHT), n)): + lightest = loads.index(min(loads)) + shards[lightest].append(name) + loads[lightest] += weights.get(name, DEFAULT_WEIGHT) + return [sorted(shard) for shard in shards] + + +def select(files: Iterable[str], shard: str, backend: str) -> list[str]: + """The files of the shard "I/N".""" + index, count = parse_shard(shard) + return split(files, count, backend)[index - 1] diff --git a/tests/conftest.py b/tests/conftest.py index 6bcc98cb..0919d5e7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,11 +2,14 @@ Shared pytest fixtures and configuration for ArcadeDB tests. """ +import functools +import importlib.util import os import re import shutil import sys import threading +from pathlib import Path import pytest @@ -294,6 +297,44 @@ def _native(): return BACKEND == "native" +# `--shard I/N` runs one shard of the test files (scripts/shard_tests.py): a pull request cuts the suite of the JVM build into +# N jobs that run side by side. The files of the other shards are not collected, so nothing is reported as skipped. The native +# parity harness (native/wheel/parity_wheel.py) does not use this option: it picks the files of a shard itself. +def pytest_addoption(parser): + parser.addoption( + "--shard", + default="", + help="run one shard of the test files, I/N (scripts/shard_tests.py)", + ) + + +_TESTS_DIR = Path(__file__).resolve().parent + + +@functools.lru_cache(maxsize=None) +def _shard_files(shard): + """The names of the test files of the shard "I/N".""" + path = _TESTS_DIR.parent / "scripts" / "shard_tests.py" + spec = importlib.util.spec_from_file_location("shard_tests", path) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + names = [p.name for p in _TESTS_DIR.glob("test_*.py")] + try: + return frozenset(module.select(names, shard, BACKEND)) + except ValueError as err: + raise pytest.UsageError(f"--shard: {err}") from None + + +def pytest_ignore_collect(collection_path, config): + shard = config.getoption("--shard", default="") + name = collection_path.name + is_test_file = name.startswith("test_") and name.endswith(".py") + if not shard or not is_test_file or collection_path.parent != _TESTS_DIR: + return None + # None, not False: the other rules (collect_ignore above) still apply to a file of this shard + return None if name in _shard_files(shard) else True + + def pytest_collection_modifyitems(config, items): if not _native(): return diff --git a/tests/test_ci_tier.py b/tests/test_ci_tier.py index ea105a52..8183e2e3 100644 --- a/tests/test_ci_tier.py +++ b/tests/test_ci_tier.py @@ -21,25 +21,19 @@ def _never(): raise AssertionError("the API was asked") -def _no_files(): - return ["src/arcadedb/core.py", "tests/test_core.py"] - - @pytest.mark.parametrize( "event", ["push", "schedule", "workflow_dispatch", "release", "", "some_new_event"], ) def test_every_event_but_a_pull_request_passes_through_unchanged(event): - # the label, the author and the changed files matter for a pull request only, and no other event costs an API call - chosen, _why = ct.planner_event( - event, "dependabot[bot]", ["ci:full"], _never, _never - ) + # the label and the author matter for a pull request only, and no other event costs an API call + chosen, _why = ct.planner_event(event, "dependabot[bot]", ["ci:full"], _never) assert chosen == event def test_a_pull_request_without_the_label_runs_the_fast_tier(): chosen, why = ct.planner_event( - "pull_request", "someone", ["bug"], lambda: ["bug", "native"], _no_files + "pull_request", "someone", ["bug"], lambda: ["bug", "native"] ) assert chosen == "pull_request" assert "fast tier" in why @@ -47,7 +41,7 @@ def test_a_pull_request_without_the_label_runs_the_fast_tier(): def test_the_label_in_the_event_asks_for_the_full_tier_without_an_api_call(): chosen, _why = ct.planner_event( - "pull_request", "someone", ["bug", "ci:full"], _never, _never + "pull_request", "someone", ["bug", "ci:full"], _never ) assert chosen == "pull_request_full" @@ -55,91 +49,38 @@ def test_the_label_in_the_event_asks_for_the_full_tier_without_an_api_call(): def test_the_label_added_after_the_event_asks_for_the_full_tier_on_a_rerun(): # a re-run keeps the event of the first attempt, so the labels are read again from the API chosen, why = ct.planner_event( - "pull_request", "someone", ["bug"], lambda: ["bug", "ci:full"], _never + "pull_request", "someone", ["bug"], lambda: ["bug", "ci:full"] ) assert chosen == "pull_request_full" assert "after the event" in why def test_labels_that_cannot_be_read_fail_open_to_the_full_tier(): - chosen, why = ct.planner_event("pull_request", "someone", [], lambda: None, _never) + chosen, why = ct.planner_event("pull_request", "someone", [], lambda: None) assert chosen == "pull_request_full" assert "fails open" in why def test_a_dependabot_pull_request_runs_the_full_tier(): # the hourly job merges it without a reader, so the full matrix is its only review - chosen, _why = ct.planner_event( - "pull_request", "dependabot[bot]", [], _never, _never - ) + chosen, _why = ct.planner_event("pull_request", "dependabot[bot]", [], _never) assert chosen == "pull_request_full" def test_only_the_exact_label_counts(): near = ["ci:fullish", "not ci:full", "CI:FULL", "ci"] - chosen, _why = ct.planner_event( - "pull_request", "someone", near, lambda: near, _no_files - ) + chosen, _why = ct.planner_event("pull_request", "someone", near, lambda: near) assert chosen == "pull_request" -@pytest.mark.parametrize( - "path", - [ - "examples/03_vector_search.py", - "examples/download_data.py", - "examples/scripts/anything.sh", - "scripts/run_examples.sh", - "scripts/native_examples_skip.txt", - ".github/workflows/test-python-examples.yml", - ], -) -def test_a_pull_request_that_changes_the_examples_or_their_runner_runs_the_example_legs( - path, -): - chosen, why = ct.planner_event( - "pull_request", "someone", [], lambda: [], lambda: ["README.md", path] - ) - assert chosen == "pull_request_examples" - assert "example" in why - - -@pytest.mark.parametrize( - "path", - [ - "examples/README.md", - "src/arcadedb/examples/x.py", - "docs/examples/x.adoc", - "scripts/run_examples.sh.bak", - "tests/test_examples.py", - "examples", - ".github/workflows/test-native.yml", - ".github/workflows/test-jvm.yml", - ], -) -def test_other_paths_do_not_start_the_example_legs(path): - chosen, _why = ct.planner_event( - "pull_request", "someone", [], lambda: [], lambda: [path] - ) +def test_a_change_to_the_examples_does_not_leave_the_fast_tier(): + # the examples are the slowest jobs: a pull request that changes them runs them on main, or before the merge with the label. + # The tier does not read the changed files at all. + assert not hasattr(ct, "changed_files") + chosen, _why = ct.planner_event("pull_request", "someone", [], lambda: []) assert chosen == "pull_request" -def test_changed_files_that_cannot_be_read_fail_open_to_the_example_legs(): - chosen, why = ct.planner_event( - "pull_request", "someone", [], lambda: [], lambda: None - ) - assert chosen == "pull_request_examples" - assert "fails open" in why - - -def test_the_full_tier_wins_over_the_example_legs(): - # the full tier has the example legs of every platform, so the changed files are not even read - chosen, _why = ct.planner_event( - "pull_request", "someone", ["ci:full"], _never, _never - ) - assert chosen == "pull_request_full" - - @pytest.mark.parametrize( ("text", "labels"), [ @@ -164,29 +105,19 @@ def __init__(self, returncode, stdout): self.stdout = stdout -def test_the_live_labels_and_the_changed_files_come_from_gh_api_one_value_on_each_line( +def test_the_live_labels_come_from_gh_api_one_value_on_each_line( monkeypatch, ): calls = [] def run(cmd, **kwargs): calls.append(cmd) - if "/labels" in cmd[3]: - return _Proc(0, "bug\nci:full\n") - return _Proc(0, "examples/new_name.py\nexamples/old_name.py\nREADME.md\n") + return _Proc(0, "bug\nci:full\n") monkeypatch.setattr(ct.subprocess, "run", run) assert ct.live_labels("ArcadeData/arcadedb-python", "7") == ["bug", "ci:full"] - assert ct.changed_files("ArcadeData/arcadedb-python", "7") == [ - "examples/new_name.py", - "examples/old_name.py", - "README.md", - ] - assert [cmd[:3] for cmd in calls] == [["gh", "api", "--paginate"]] * 2 + assert [cmd[:3] for cmd in calls] == [["gh", "api", "--paginate"]] assert "repos/ArcadeData/arcadedb-python/issues/7/labels" in calls[0][3] - assert "repos/ArcadeData/arcadedb-python/pulls/7/files" in calls[1][3] - # a renamed file counts under both names: moving a file out of examples/ changes the examples too - assert "previous_filename" in calls[1][5] def test_the_api_answers_are_unknown_when_gh_fails_is_missing_or_has_nothing_to_ask( @@ -198,20 +129,18 @@ def missing(cmd, **kwargs): def never(cmd, **kwargs): raise AssertionError("gh was called without a repository or a number") - for read in (ct.live_labels, ct.changed_files): - monkeypatch.setattr(ct.subprocess, "run", lambda cmd, **kwargs: _Proc(1, "")) - assert read("ArcadeData/arcadedb-python", "7") is None - monkeypatch.setattr(ct.subprocess, "run", missing) - assert read("ArcadeData/arcadedb-python", "7") is None - monkeypatch.setattr(ct.subprocess, "run", never) - assert read("", "7") is None - assert read("ArcadeData/arcadedb-python", "") is None + monkeypatch.setattr(ct.subprocess, "run", lambda cmd, **kwargs: _Proc(1, "")) + assert ct.live_labels("ArcadeData/arcadedb-python", "7") is None + monkeypatch.setattr(ct.subprocess, "run", missing) + assert ct.live_labels("ArcadeData/arcadedb-python", "7") is None + monkeypatch.setattr(ct.subprocess, "run", never) + assert ct.live_labels("", "7") is None + assert ct.live_labels("ArcadeData/arcadedb-python", "") is None -def test_no_label_and_no_changed_file_are_answers_not_failures(monkeypatch): +def test_no_label_is_an_answer_not_a_failure(monkeypatch): monkeypatch.setattr(ct.subprocess, "run", lambda cmd, **kwargs: _Proc(0, "")) assert ct.live_labels("ArcadeData/arcadedb-python", "7") == [] - assert ct.changed_files("ArcadeData/arcadedb-python", "7") == [] def _run(args, **env): @@ -245,8 +174,7 @@ def test_both_planners_know_the_events_this_script_prints(): # the names are written in three scripts; a rename in one of them would send a pull request to the wrong legs for name in ("select_matrix.py", "select_native_matrix.py"): text = (ROOT / "scripts" / name).read_text(encoding="utf-8") - for event in (ct.EXAMPLES_EVENT, ct.FULL_EVENT): - assert f'"{event}"' in text, (name, event) + assert f'"{ct.FULL_EVENT}"' in text, name assert ct.FAST_EVENT == "pull_request" diff --git a/tests/test_select_matrix.py b/tests/test_select_matrix.py index 42bc3c66..4153ed5b 100644 --- a/tests/test_select_matrix.py +++ b/tests/test_select_matrix.py @@ -53,13 +53,17 @@ def _load(): def _pairs(matrix): + """The platform x Python pairs of the legs; the shards of one pair count once.""" legs = matrix["include"] - pairs = [(leg["platform"], leg["python-version"]) for leg in legs] - assert len(pairs) == len(set(pairs)), "a leg is listed twice" + listed = [ + (leg["platform"], leg["python-version"], leg.get("shard")) for leg in legs + ] + assert len(listed) == len(set(listed)), "a leg is listed twice" for leg in legs: - assert set(leg) == {"platform", "runs-on", "python-version"} + keys = {"platform", "runs-on", "python-version"} + assert set(leg) in (keys, keys | {"shard", "suffix"}) assert leg["runs-on"] == PLATFORMS[leg["platform"]] - return set(pairs) + return {(platform, python) for platform, python, _shard in listed} @pytest.mark.parametrize("event", NON_PULL_REQUEST_EVENTS) @@ -95,11 +99,15 @@ def test_jvm_tests_every_platform_and_python_for_a_release_a_dispatch_and_any_ot def test_a_pull_request_runs_the_fast_tier_of_the_jvm_tests(): - # linux/amd64 only, the oldest and the newest Python: no macOS, Windows or arm64 runner is waited for - assert _pairs(sm.select("jvm", "pull_request")) == { - ("linux/amd64", "3.11"), - ("linux/amd64", "3.14"), - } + # one platform and one Python, the newest (#517): no macOS, Windows or arm64 runner is waited for + assert _pairs(sm.select("jvm", "pull_request")) == {("linux/amd64", "3.14")} + # in shards that run side by side, every one from 1 to N + legs = sm.select("jvm", "pull_request")["include"] + count = sm.PULL_REQUEST_SHARDS + assert count > 1 + assert [(leg["shard"], leg["suffix"]) for leg in legs] == [ + (f"{i}/{count}", f"-shard{i}") for i in range(1, count + 1) + ] assert sm.select_wheels("jvm", "pull_request") == { "include": [{"platform": "linux/amd64", "runs-on": "ubuntu-24.04"}] } @@ -124,23 +132,26 @@ def test_jvm_builds_one_wheel_for_each_platform_whatever_the_python(event): } -def test_pull_request_examples_matrix(): - # the fast tier has no example leg and builds no wheel for one: the examples are the slowest jobs +def test_a_pull_request_has_no_example_leg(): + # the fast tier has no example leg and builds no wheel for one, whatever the pull request changes: the examples are the + # slowest jobs assert sm.select("examples", "pull_request") == {"include": []} assert sm.select_wheels("examples", "pull_request") == {"include": []} - # a pull request that changes the examples or their runner (scripts/ci_tier.py): the newest Python on linux/amd64, one build - pairs = _pairs(sm.select("examples", "pull_request_examples")) - assert pairs == {("linux/amd64", "3.14")} - assert sm.select_wheels("examples", "pull_request_examples") == { - "include": [{"platform": "linux/amd64", "runs-on": "ubuntu-24.04"}] - } - # its unit tests are those of every pull request - assert sm.select("jvm", "pull_request_examples") == sm.select("jvm", "pull_request") -def test_the_examples_workflow_skips_its_jobs_when_the_matrix_is_empty_and_the_summary_knows_it(): - # An empty matrix is an error for a job. The first job says whether the run has legs, the two jobs that take the matrix are - # skipped when it has none, and the summary is green for exactly that case (the bash is run in the pull request of issue 442). +@pytest.mark.parametrize( + "event", ["push", "schedule", "release", "workflow_dispatch", "pull_request_full"] +) +@pytest.mark.parametrize("workflow", ["jvm", "examples"]) +def test_only_the_fast_tier_is_sharded(workflow, event): + # main, the nightly run, a manual run and a release run each suite whole, in one job for each leg + assert all("shard" not in leg for leg in sm.select(workflow, event)["include"]) + + +def test_the_examples_workflow_skips_its_jobs_when_the_matrix_is_empty_and_the_summary_with_them(): + # An empty matrix is an error for a job. The first job says whether the run has legs, and the two jobs that take the matrix are + # skipped when it has none, as is the summary: it has nothing to check. A first job that failed leaves `run` empty, so the + # summary runs and is red. text = WORKFLOWS["examples"].read_text(encoding="utf-8") one_line = subprocess.run( # nosec B603 - fixed argument list, no untrusted input [sys.executable, "-I", str(SCRIPT_PATH), "examples", "--event", "pull_request"], @@ -160,7 +171,8 @@ def test_the_examples_workflow_skips_its_jobs_when_the_matrix_is_empty_and_the_s condition = job.split(" if: ", 1)[1].split("\n", 1)[0] assert condition.endswith("&& needs.download-jars.outputs.run == 'true'") assert "needs: [download-jars, build, test-examples]" in summary - assert "if: always() &&" in summary + assert "always() &&" in summary + assert "&& needs.download-jars.outputs.run != 'false'\n" in summary for line in ( "PLAN: ${{ needs.download-jars.result }}", "RUN: ${{ needs.download-jars.outputs.run }}", @@ -269,6 +281,17 @@ def test_the_jvm_workflow_builds_each_platform_once_and_tests_that_wheel(): assert 'scripts/select_matrix.py jvm --event "$EVENT_NAME" --wheels' in text assert "matrix: ${{ fromJSON(needs.download-jars.outputs.wheel-matrix) }}" in text build, test = text.split("\n build:\n")[1].split("\n test:\n") + # a sharded leg hands its shard to pytest and names its artifact after it + assert '--shard="$SHARD"' in test and "SHARD: ${{ matrix.shard }}" in test + assert "py${{ matrix.python-version }}${{ matrix.suffix }}" in test + # the summary of a pull request of the fast tier would be one more job to wait for; a failed first job still runs it + summary = test.split("\n test-summary:\n")[1] + assert "needs: [download-jars, build, test]" in summary + assert "&& needs.download-jars.outputs.fast-pr != 'true'\n" in summary + assert ( + 'if [ "$EVENT_NAME" = pull_request ]; then fast_pr=true; else fast_pr=false; fi' + in text + ) # no Python in the build matrix, and the test job builds nothing: it installs the wheel the build job uploaded assert "python-version: ${{ matrix.python-version }}" not in build assert ( diff --git a/tests/test_select_native_matrix.py b/tests/test_select_native_matrix.py index 56b6eb36..dc0ef5b5 100644 --- a/tests/test_select_native_matrix.py +++ b/tests/test_select_native_matrix.py @@ -19,9 +19,27 @@ def test_pull_request_builds_one_platform_and_tests_one_python(): chosen = sel.select("pull_request") assert [b["key"] for b in chosen["build"]] == ["linux-x86_64"] - assert [(t["key"], t["python"]) for t in chosen["test"]] == [ - ("linux-x86_64", "3.12") + # one Python, the newest the full suite runs on (#517), in shards that run side by side, every one from 1 to N + count = sel.PULL_REQUEST_SHARDS + assert count > 1 + assert [ + (t["key"], t["python"], t["shard"], t["suffix"]) for t in chosen["test"] + ] == [ + ("linux-x86_64", "3.14", f"{i}/{count}", f"-shard{i}") + for i in range(1, count + 1) ] + assert chosen["pyver"] == [] and chosen["examples"] == [] + + +def test_only_the_fast_tier_is_sharded(): + for event in ( + "pull_request_full", + "push", + "schedule", + "workflow_dispatch", + "release", + ): + assert all("shard" not in leg for leg in sel.select(event)["test"]), event def test_a_pull_request_that_asks_for_the_full_tier_runs_the_legs_of_a_push_to_main(): @@ -36,16 +54,14 @@ def test_the_workflow_asks_ci_tier_for_the_event_and_skips_an_empty_python_versi assert tier < plan.index('scripts/select_native_matrix.py "$event"') # a change to the script that picks the tier starts this workflow assert ' - "scripts/ci_tier.py"\n' in workflow.split("\njobs:\n", 1)[0] - # the fast tier has no example leg, and an empty matrix is an error: the job is skipped then, and the summary expects that + # the fast tier has no example leg, and an empty matrix is an error: the job is skipped then, and the summary with it assert sel.select("pull_request")["examples"] == [] - assert ( - "needs.plan.outputs.examples != '[]'" - in _job(workflow, "examples").split("steps:", 1)[0] - ) - summary = _job(workflow, "examples-summary") - assert "LEGS: ${{ needs.plan.outputs.examples }}" in summary - assert """if [ "$LEGS" = '[]' ]; then want=skipped; fi""" in summary - assert '[ "$RESULT" = "$want" ]' in summary + for name in ("examples", "examples-summary"): + assert ( + "needs.plan.outputs.examples != '[]'" + in _job(workflow, name).split("steps:", 1)[0] + ), name + assert '[ "$RESULT" = success ]' in _job(workflow, "examples-summary") # the same guard on the pyver job, which no other job needs assert ( "needs.plan.outputs.pyver != '[]'" @@ -106,11 +122,8 @@ def test_the_script_prints_github_output_lines(): "examples", ] assert json.loads(out[0].split("=", 1)[1])[0]["key"] == "linux-x86_64" - # the fast tier: the pyver subset on the oldest and the newest Python, and no example leg (the text the workflow compares with '[]') - assert [leg["python"] for leg in json.loads(out[2].split("=", 1)[1])] == [ - "3.11", - "3.14", - ] + # the fast tier: no pyver leg and no example leg (the text the workflow compares with '[]') + assert out[2] == "pyver=[]" assert out[3] == "examples=[]" full = subprocess.run( # nosec B603 - fixed argv, no shell [sys.executable, str(SCRIPT), "pull_request_full"], @@ -134,13 +147,8 @@ def _pyver(event): def test_the_python_version_job_covers_what_the_full_parity_run_leaves_out(): - # a pull request (the fast tier) runs the parity suite on 3.12 and the subset on the ends of the supported range; 3.13, 3.15 and - # the free-threaded build wait for the full tier - for event in ("pull_request", "pull_request_examples"): - assert _pyver(event) == [ - ("3.11", False, True, True), - ("3.14", False, True, True), - ] + # a pull request (the fast tier) runs one Python, the parity suite on 3.14: every other Python waits for the full tier + assert _pyver("pull_request") == [] # the selection itself still knows what one full Python leaves out: the other three Pythons, 3.15 (no jpype1 wheel yet) and the # free-threaded one assert [ @@ -148,8 +156,8 @@ def test_the_python_version_job_covers_what_the_full_parity_run_leaves_out(): for leg in sel.pyver_legs(sel.PULL_REQUEST_PYTHONS) ] == [ ("3.11", False, True, True), + ("3.12", False, True, True), ("3.13", False, True, True), - ("3.14", False, True, True), ("3.15", False, True, False), ("3.14t", True, False, True), ] @@ -262,14 +270,8 @@ def test_the_linux_legs_build_in_the_manylinux_container_of_the_tag_and_the_work def test_the_examples_job_runs_on_the_parity_pythons_3_12_and_3_14_of_every_platform_it_builds(): - # a pull request has no example leg, unless it changes the examples or their runner (scripts/ci_tier.py): then one, on the parity Python + # a pull request of the fast tier has no example leg assert sel.select("pull_request")["examples"] == [] - pr = sel.select("pull_request_examples")["examples"] - assert [(leg["key"], leg["python"]) for leg in pr] == [("linux-x86_64", "3.12")] - for key in ("build", "test", "pyver"): - assert ( - sel.select("pull_request_examples")[key] == sel.select("pull_request")[key] - ) for event in ( "pull_request_full", "push", @@ -283,6 +285,75 @@ def test_the_examples_job_runs_on_the_parity_pythons_3_12_and_3_14_of_every_plat assert len(legs) == 2 * len(sel.ALL_PLATFORMS), event +def _step(job, name): + """The text of one named step of a job.""" + return job.split(f" - name: {name}\n", 1)[1].split("\n - ", 1)[0] + + +def test_only_a_pull_request_of_the_fast_tier_restores_the_library_and_a_release_never_touches_the_cache(): + workflow = (ROOT / ".github" / "workflows" / "test-native.yml").read_text() + plan = _job(workflow, "plan") + assert ( + 'if [ "$EVENT" = pull_request ] && [ "$event" = pull_request ] && [ "${ENGINE_SNAPSHOT:-}" != true ]; then fast_pr=true;' + in plan + ) + build = _job(workflow, "build") + restore = _step(build, "Restore the native library") + assert "needs.plan.outputs.fast-pr == 'true'" in restore + assert "!endsWith(needs.plan.outputs.maven-engine, '-SNAPSHOT')" in restore + assert "restore-keys" not in restore.split("uses:", 1)[1] + save = _step(build, "Save the native library") + assert "!inputs.release" in save + assert "!endsWith(needs.plan.outputs.maven-engine, '-SNAPSHOT')" in save + # restore and save use the one key and the one pair of directories + for step in (restore, save): + assert "key: ${{ steps.library-key.outputs.key }}" in step + assert "${{ runner.temp }}/lib\n" in step + assert "${{ runner.temp }}/m2\n" in step + # a cache hit skips the image build and nothing else of the gates; the library is saved after every gate + assert "steps.library.outputs.cache-hit != 'true'" in _step( + build, "Build the native image in manylinux_2_28" + ) + assert build.index("Gate: twine check") < build.index("Save the native library") + assert workflow.count("actions/cache/restore@") == 1 + assert workflow.count("actions/cache/save@") == 1 + + +def test_the_key_of_the_cached_library_covers_every_file_the_image_is_built_from(): + # native/wheel/ only packs the wheel, which every run builds from its own checkout; everything else under native/ decides + # what the image is + workflow = (ROOT / ".github" / "workflows" / "test-native.yml").read_text() + key = _step(_job(workflow, "build"), "Key of the native library") + hashed = key.split("hashFiles(", 1)[1].split(")", 1)[0] + patterns = re.findall(r"'([^']+)'", hashed) + for part in ( + "matrix.key", + "needs.plan.outputs.maven-engine", + "matrix.graalvm_sha256", + "matrix.xmx", + "matrix.ni_extra", + ): + assert part in key, part + assert ".github/workflows/test-native.yml" in patterns + native = ROOT / "native" + sources = [native / "pom.xml", native / "mvnw"] + [ + p + for d in (".mvn", "src", "scripts") + for p in (native / d).rglob("*") + if p.is_file() + ] + for path in sources: + name = path.relative_to(ROOT).as_posix() + assert any( + name == p or (p.endswith("/**") and name.startswith(p[:-2])) + for p in patterns + ), name + # a new directory or file directly under native/ must be added to the key (or to this list, when the build does not read it) + known = {".gitignore", ".mvn", "mvnw", "mvnw.cmd", "pom.xml", "scripts", "src"} + built = {"target", "reports"} + assert {p.name for p in native.iterdir()} - built <= known | {"wheel"} + + def test_the_examples_job_installs_the_wheel_of_the_build_job_and_shares_the_runner_with_the_jvm_job(): workflows = ROOT / ".github" / "workflows" test_native = (workflows / "test-native.yml").read_text() diff --git a/tests/test_shard_tests.py b/tests/test_shard_tests.py new file mode 100644 index 00000000..99f81f80 --- /dev/null +++ b/tests/test_shard_tests.py @@ -0,0 +1,61 @@ +"""The shards of a pull request (scripts/shard_tests.py): every test file runs in exactly one of them.""" + +import importlib.util +from pathlib import Path + +import pytest + +ROOT = Path(__file__).resolve().parents[1] +spec = importlib.util.spec_from_file_location( + "shard_tests", ROOT / "scripts" / "shard_tests.py" +) +shards = importlib.util.module_from_spec(spec) +spec.loader.exec_module(shards) + +FILES = sorted(p.name for p in (ROOT / "tests").glob("test_*.py")) + + +@pytest.mark.parametrize("backend", ["jvm", "native"]) +@pytest.mark.parametrize("count", [1, 2, 3, 4, 7]) +def test_every_test_file_is_in_exactly_one_shard(backend, count): + parts = [shards.select(FILES, f"{i}/{count}", backend) for i in range(1, count + 1)] + assert sorted(name for part in parts for name in part) == FILES + assert all(parts) + + +@pytest.mark.parametrize("backend", ["jvm", "native"]) +def test_the_split_does_not_depend_on_the_order_of_the_files(backend): + assert shards.split(reversed(FILES), 3, backend) == shards.split(FILES, 3, backend) + + +def test_the_two_longest_native_files_run_in_different_shards(): + heavy = ("test_vector_product_quantization.py", "test_log_redirect.py") + parts = shards.split(FILES, 3, "native") + assert [sum(name in part for name in heavy) for part in parts].count(1) == 2 + + +@pytest.mark.parametrize("backend", ["jvm", "native"]) +def test_every_weighted_file_exists(backend): + # a renamed file would silently lose its weight and unbalance the shards + assert set(shards.WEIGHTS[backend]) <= set(FILES) + + +@pytest.mark.parametrize("text", ["", "1", "0/2", "3/2", "1/0", "a/b", "1/2/3", " 1/2"]) +def test_a_shard_that_is_not_i_of_n_is_refused(text): + with pytest.raises(ValueError): + shards.parse_shard(text) + + +def test_both_suites_get_the_shard_of_the_leg(): + workflows = ROOT / ".github" / "workflows" + assert '--shard="$SHARD"' in (workflows / "test-jvm.yml").read_text( + encoding="utf-8" + ) + native = (workflows / "test-native.yml").read_text(encoding="utf-8") + assert '--shard "$SHARD"' in native + # a shard ran part of the suite: it uploads no marker of a passed platform (a release is never sharded) + marker = native.split(" name: native-passed-${{ matrix.key }}-py", 1)[0] + assert marker.rstrip().endswith("with:") + assert " if: ${{ !matrix.shard }}\n with:" in marker[-200:] + # a change to the split starts the native workflow + assert ' - "scripts/shard_tests.py"\n' in native From db7718ef585400631942edd0eaf6ae5305c1fcc2 Mon Sep 17 00:00:00 2001 From: Taewoon Kim Date: Fri, 27 Nov 2026 20:14:50 +0900 Subject: [PATCH 2/2] test: the weekly run takes the new legs of a pull request The weekly engine snapshot run uses the legs of a pull request, which are now Python 3.14 in three shards with no pyver leg. Also pin that it is not treated as a pull request of the fast tier. --- tests/test_dev_engine_pin.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/test_dev_engine_pin.py b/tests/test_dev_engine_pin.py index 5bc5f229..7c8219f2 100644 --- a/tests/test_dev_engine_pin.py +++ b/tests/test_dev_engine_pin.py @@ -169,8 +169,16 @@ def test_the_weekly_run_is_never_skipped_and_builds_one_platform(tmp_path): lines = dict(line.split("=", 1) for line in out.read_text().splitlines()) assert lines["run"] == "true" assert [leg["key"] for leg in json.loads(lines["build"])] == ["linux-x86_64"] - assert [leg["python"] for leg in json.loads(lines["test"])] == ["3.12"] + # the legs of a pull request: one Python, the newest, in shards, and no pyver or example leg + assert [(leg["python"], leg["shard"]) for leg in json.loads(lines["test"])] == [ + ("3.14", "1/3"), + ("3.14", "2/3"), + ("3.14", "3/3"), + ] + assert json.loads(lines["pyver"]) == [] assert json.loads(lines["examples"]) == [] + # but not a pull request: it reads no cached library, and the report job of the crashes runs + assert lines["fast-pr"] == "false" def _hashes(**changes):