mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-22 12:43:32 +09:00
The BATS half of `make unit-tests` ran as one shell loop over ~60 files, which is a nine-minute serial tail no amount of runner CPU could touch. Each file becomes its own Make prerequisite instead, so `-j4` schedules them, and the workflow asks for `make unit-tests test-controllers -j4 --output-sync=target` in a single step: one make process owns all four runner CPUs, the Helm and Go targets share the same bounded pool rather than waiting for each other, and output stays grouped by target instead of four logs interleaving. The existence check moves into its own prerequisite rather than disappearing. It guards against the wildcard matching nothing, which would otherwise make the whole target succeed by having no work. COZYTEST_TRACE rides per target. It arrived with the serial loop it now replaces, and a target that dropped it would go back to streaming full xtrace for every suite -- so the parallelism guard requires the prefix rather than tolerating it. Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
32 lines
1.4 KiB
Bash
32 lines
1.4 KiB
Bash
#!/usr/bin/env bats
|
|
# Contract for the bounded parallel unit-test fan-out used by PR CI.
|
|
|
|
@test "every non-E2E BATS file is an independent Make prerequisite" {
|
|
expected=$(find hack -maxdepth 1 -type f -name '*.bats' ! -name 'e2e-*.bats' | wc -l)
|
|
output=$(make -n -j4 --output-sync=target bats-unit-tests)
|
|
# The COZYTEST_TRACE prefix is part of the pattern on purpose: the switch is
|
|
# per-target now that the serial loop is gone, and a target that loses it
|
|
# would go back to streaming full xtrace for every suite.
|
|
actual=$(printf '%s\n' "$output" | grep -c '^COZYTEST_TRACE=[^ ]* hack/cozytest.sh "hack/.*\.bats"$')
|
|
[ "$actual" -eq "$expected" ] || {
|
|
echo "make scheduled $actual BATS files independently, expected $expected" >&2
|
|
exit 1
|
|
}
|
|
if printf '%s\n' "$output" | grep -q 'for f in'; then
|
|
echo "bats-unit-tests still serializes the suite in a shell loop" >&2
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
@test "PR workflow shares four slots across unit and controller targets" {
|
|
grep -qF 'run: make unit-tests test-controllers -j4 --output-sync=target' \
|
|
.github/workflows/pull-requests.yaml || {
|
|
echo "PR checks do not use the bounded four-slot make invocation" >&2
|
|
exit 1
|
|
}
|
|
[ "$(grep -c 'run: make test-controllers' .github/workflows/pull-requests.yaml)" -eq 0 ] || {
|
|
echo "controller tests still run in a separate sequential workflow step" >&2
|
|
exit 1
|
|
}
|
|
}
|