Merge pull request #676 from seaweedfs/ci/process-shards-on-668

ci: run the process-level tests in 4 parallel shards
This commit is contained in:
Ping Qiu authored and GitHub committed 2026-11-27 11:54:46 -08:00
commit 5a66531663
4 files changed
+193 -4

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
# Seconds each process-level test took on the CI runner (main 032eb197, run 45972669823),
# used only to balance the parallel shards (.github/scripts/shard-named-tests.py). A test
# missing here counts as 60 s; a stale time unbalances the shards but never skips a test.
TestAVolumeThatServedBeforeItsFirstGateTickFailsOver 31.4
TestClaimedTargetAfterAMasterRestartIsNotNeverStarted 18.7
TestCutoverCreateFromSnapshot 25.4
TestCutoverWriteSnapshotKillRestartRestore 34.1
TestDoubleFailoverReadsBackEveryAckedWrite 10.2
TestFencingRoundHealContinuesThePrimary 13.4
TestFencingRoundSurvivorRejoins 17.0
TestKnownZeroAcceptance 27.1
TestKnownZeroTargetReservesBeforeHarness 0.0
TestNeverAttachedRestoreTargetIsDeletable 16.5
TestNeverStartedDeleteAfterAMasterRestart 166.8
TestNeverStartedDeleteFencesALateStart 53.6
TestNeverStartedDeleteRacesAStart 42.4
TestNeverStartedLineDeleteFencesALateStart 240.3
TestNeverStartedLineDeleteRacesAStart 458.9
TestNeverStartedLineIsDeletableWithoutARevoke 335.1
TestProcedureDeleteAVolume 79.1
TestProcedureDeleteAfterASignalStop 116.1
TestProcedureForcedMoveWithTheOldHostReturning 100.2
TestProcedureMasterKilledAfterMoveBeforeTargetStarts 23.2
TestProcedureMasterUnreachableFencesBeforeForcedMove 159.4
TestProcedurePlannedHandoffToAnotherHost 16.8
TestProcedureReturnAfterALapsedLease 81.4
TestProcedureRevokeWithoutACKThenForcedMove 79.6
TestProcedureSameHostCrashRestartInsideTheLease 17.5
TestProcedureSameHostRestartInsideTheLease 17.5
TestProcedureStartInsideTheBarrierWaitIsReGranted 80.0
TestSnapshotLadderA1OneBlockOneSnapshot 18.8
TestSnapshotLadderA2IncrementalSnapshot 20.9
TestSnapshotLadderA3WritesDuringASnapshot 26.1
TestSnapshotLadderA4ContentReturnsToAnOldValue 23.6
TestSnapshotLadderB1SnapshotQuery 19.1
TestSnapshotLadderC1FullRestore 18.8
TestSnapshotLadderC2IncrementalRestore 21.3
TestSnapshotLadderC3KilledHydrating 35.6
TestSnapshotLadderC3RestoreThenWriteThenSnapshotIt 21.3
TestSnapshotLadderD1DeleteTheNewest 21.4
TestSnapshotLadderD2DeleteAMiddleOne 23.9
TestSnapshotLadderD3DeleteWhenContentRecurs 21.3
TestSnapshotLadderD4DeleteAllButOneThenCollect 19.4
TestSnapshotLadderE1CrashDuringASnapshot 31.1
TestSnapshotLadderF1VolumesOneHost 528.4
TestStandaloneCleanMoveWithoutTheACKIsRefused 16.6
TestStandalonePlannedHandoffToTheSameHost 17.7
+55
View File
@@ -0,0 +1,55 @@
"""Tests shard-named-tests.py: every name in exactly one shard, longest first
into the least-loaded shard, the same split on every run, unknown names
counted, and a duplicate or empty list refused."""
import importlib.util
import os
import subprocess
import sys
import tempfile
HERE = os.path.dirname(os.path.abspath(__file__))
SCRIPT = os.path.join(HERE, "shard-named-tests.py")
spec = importlib.util.spec_from_file_location("shard", SCRIPT)
shard = importlib.util.module_from_spec(spec)
spec.loader.exec_module(shard)
fail = 0
def check(name, ok):
global fail
print(("ok " if ok else "FAIL ") + name)
if not ok:
fail = 1
secs = {"A": 500, "B": 400, "C": 300, "D": 100, "E": 100}
parts, load = shard.shard(list(secs), secs, 2)
check("every name once", sorted(sum(parts, [])) == sorted(secs))
check("longest first, least loaded", parts == [["A", "D", "E"], ["B", "C"]] and load == [700, 700])
check("same split on every run", shard.shard(list(secs), secs, 2) == (parts, load))
parts, load = shard.shard(["A", "Z"], {"A": 10}, 2)
check("an unknown name counts as the default", load == [shard.DEFAULT, 10.0])
parts, _ = shard.shard(["A", "B"], {}, 4)
check("more shards than names leaves some empty", sum(len(p) for p in parts) == 2 and [] in parts)
with tempfile.TemporaryDirectory() as d:
names = os.path.join(d, "names.txt")
seconds = os.path.join(d, "seconds.txt")
with open(seconds, "w") as f:
f.write("# times\nTestA 30\nTestB 20\n")
with open(names, "w") as f:
f.write("# list\nTestA\nTestB # note\n\nTestC\n")
rc = subprocess.run([sys.executable, "-I", SCRIPT, names, seconds, "2", os.path.join(d, "out")], capture_output=True, text=True).returncode
got = sorted(open(os.path.join(d, "out", f)).read().split() for f in ("1.txt", "2.txt"))
check("the files hold every name once", rc == 0 and sorted(sum(got, [])) == ["TestA", "TestB", "TestC"])
with open(names, "w") as f:
f.write("TestA\nTestA\n")
rc = subprocess.run([sys.executable, "-I", SCRIPT, names, seconds, "2", os.path.join(d, "o2")], capture_output=True, text=True).returncode
check("a name listed twice is refused", rc == 2)
with open(names, "w") as f:
f.write("# nothing\n")
rc = subprocess.run([sys.executable, "-I", SCRIPT, names, seconds, "2", os.path.join(d, "o3")], capture_output=True, text=True).returncode
check("an empty list is refused", rc == 2)
sys.exit(fail)
+69
View File
@@ -0,0 +1,69 @@
"""Split the named process-level tests into N balanced shards.
Usage: shard-named-tests.py NAMES_FILE SECONDS_FILE N OUT_DIR
Writes OUT_DIR/1.txt .. OUT_DIR/N.txt, one test name per line. Every name in
NAMES_FILE (# starts a comment) lands in exactly one shard. SECONDS_FILE holds
"Name seconds" lines from an earlier run; a name missing there counts as
DEFAULT seconds. Longest first, each into the shard with the least time so
far (ties to the lowest shard), so the result is the same on every run.
Prints each shard's names count and its estimated seconds.
Exit 0, or 2 on a usage error, a duplicate name or an empty names list.
"""
import os
import sys
DEFAULT = 60.0
def names_of(path):
out = []
for line in open(path, encoding="utf-8"):
name = line.split("#", 1)[0].strip()
if name:
out.append(name)
return out
def seconds_of(path):
out = {}
for line in open(path, encoding="utf-8"):
fields = line.split("#", 1)[0].split()
if len(fields) == 2:
out[fields[0]] = float(fields[1])
return out
def shard(names, seconds, n):
load = [0.0] * n
shards = [[] for _ in range(n)]
for name in sorted(names, key=lambda x: (-seconds.get(x, DEFAULT), x)):
k = min(range(n), key=lambda i: (load[i], i))
shards[k].append(name)
load[k] += seconds.get(name, DEFAULT)
return shards, load
def main(argv):
if len(argv) != 5:
print(__doc__.strip().splitlines()[2], file=sys.stderr)
return 2
names = names_of(argv[1])
if not names or len(set(names)) != len(names):
print("shard-named-tests: empty names list or a name listed twice", file=sys.stderr)
return 2
n = int(argv[3])
if n < 1:
return 2
shards, load = shard(names, seconds_of(argv[2]), n)
os.makedirs(argv[4], exist_ok=True)
for i, part in enumerate(shards, 1):
with open(os.path.join(argv[4], "%d.txt" % i), "w", encoding="utf-8") as f:
f.write("".join(x + "\n" for x in part))
print("shard %d: %d tests, about %d s" % (i, len(part), load[i - 1]))
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv))
+22 -4
View File
@@ -37,7 +37,7 @@ jobs:
# capped at 8 cores / 8 GiB). Fork PRs never reach it: they stay on a
# GitHub-hosted runner.
runs-on: ${{ (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && 'tp04-seaweed-block' || 'ubuntu-latest' }}
# process: 44 tests in sequence, 15 to 550 s each (about 55 min in all).
# process: 44 tests in 4 parallel shards of about 13 min each (55 min in sequence).
timeout-minutes: ${{ matrix.suite == 'unit' && 40 || 90 }}
env:
# Pure-Go build: no package in the default build needs cgo, and the
@@ -131,6 +131,7 @@ jobs:
run: |
python3 -I .github/scripts/required-tests-check-test.py
bash .github/scripts/run-named-tests-test.sh
python3 -I .github/scripts/shard-named-tests-test.py
- name: Pinned SeaweedFS
if: matrix.suite == 'process' && steps.scope.outputs.docs_only != '1'
@@ -185,8 +186,25 @@ jobs:
TEST_TIMEOUT: 15m
run: |
set -euo pipefail
# SHARDS parallel shards, balanced by their last measured times
# (.github/process-level-seconds.txt). Each shard is its own sequence
# of test processes with its own slice of the test port ranges
# (SWBLOCK_TEST_PORT_SHARD) and its own TMPDIR; the gate judges every
# named test from all the shards together.
names=.github/process-level-tests.txt
bash .github/scripts/run-named-tests.sh "$SWBLOCK_TEST_BINS/blockvolume.test" "$names" \
"$RUNNER_TEMP/process-level.json" "$RUNNER_TEMP/process-level.status" "$TEST_TIMEOUT" cmd/blockvolume
shards=4
python3 -I .github/scripts/shard-named-tests.py "$names" .github/process-level-seconds.txt "$shards" "$RUNNER_TEMP/shard"
pids=()
for k in $(seq 1 "$shards"); do
mkdir -p "$RUNNER_TEMP/tmp-$k"
SWBLOCK_TEST_PORT_SHARD=$k SWBLOCK_TEST_PORT_SHARDS=$shards TMPDIR="$RUNNER_TEMP/tmp-$k" \
bash .github/scripts/run-named-tests.sh "$SWBLOCK_TEST_BINS/blockvolume.test" "$RUNNER_TEMP/shard/$k.txt" \
"$RUNNER_TEMP/process-level-$k.json" "$RUNNER_TEMP/process-level-$k.status" "$TEST_TIMEOUT" cmd/blockvolume \
>"$RUNNER_TEMP/process-level-$k.log" 2>&1 &
pids+=($!)
done
for p in "${pids[@]}"; do wait "$p" || true; done
for k in $(seq 1 "$shards"); do sed "s/^/[shard $k] /" "$RUNNER_TEMP/process-level-$k.log"; done
cat "$RUNNER_TEMP"/process-level-*.status >"$RUNNER_TEMP/process-level.status"
python3 -I .github/scripts/required-tests-check.py --status "$RUNNER_TEMP/process-level.status" \
"$names" "$RUNNER_TEMP/process-level.json"
"$names" "$RUNNER_TEMP"/process-level-*.json