Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions scripts/affected-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
# scripts/affected-tests.sh --run ... and run them, sequentially
# scripts/affected-tests.sh --run --jobs N ... N shell suites at a time
# scripts/affected-tests.sh --run --budget S ... timed against an S-second budget, a
# suite over its share failing (run-plugin-tests.sh
# BUDGET)
# suite over its share failing, or warning with
# PLUGIN_TEST_SHARE_WARN_ONLY=1
# (run-plugin-tests.sh BUDGET)
# scripts/affected-tests.sh --run --write-not-run FILE
# ... and write each selected suite it did not run
# to FILE, one per line (exit 3 names them); a
Expand Down
6 changes: 4 additions & 2 deletions scripts/check-affected.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
# scripts/check-affected.sh --budget S time the selected shell suites against
# an S-second budget (default:
# $CHECK_AFFECTED_BUDGET, else 120); a
# suite over its share fails
# suite over its share is a warning,
# not a failure
# (scripts/run-plugin-tests.sh BUDGET)
# scripts/check-affected.sh --base <ref> diff against <ref> (default: origin/main)
# scripts/check-affected.sh --no-fetch skip refreshing <ref> before the
Expand Down Expand Up @@ -706,7 +707,8 @@ elif ((run_tests)); then
local -a pkgs=() exclusions=() node=() unrun=()
# Suites run only when the data tree is this tree, so CHECK_DATA_ROOT adds nothing here, and a suite
# that inherits it points its checkers at the real tree instead of its fixtures.
env -u CHECK_DATA_ROOT "$tools/scripts/affected-tests.sh" --run --jobs "$jobs" --budget "$budget" --base "$base" --write-not-run "$out.not-run" || rc=$?
# A suite that passes on a loaded host but runs past its share is a warning here.
env -u CHECK_DATA_ROOT PLUGIN_TEST_SHARE_WARN_ONLY=1 "$tools/scripts/affected-tests.sh" --run --jobs "$jobs" --budget "$budget" --base "$base" --write-not-run "$out.not-run" || rc=$?
((rc == 3)) || return "$rc"
# shellcheck source=lib/read-list.sh
. "$tools/scripts/lib/read-list.sh" &&
Expand Down
4 changes: 4 additions & 0 deletions scripts/check-affected.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ cat >"$repo/scripts/affected-tests.sh" <<'STUB'
echo "affected-tests ran" >&2
[[ -z "${STUB_ARGS_LOG:-}" ]] || printf '%s\n' "$*" >"$STUB_ARGS_LOG"
[[ -z "${STUB_ENV_LOG:-}" ]] || printf '%s' "${CHECK_DATA_ROOT-unset}" >"$STUB_ENV_LOG"
[[ -z "${STUB_SHARE_LOG:-}" ]] || printf '%s' "${PLUGIN_TEST_SHARE_WARN_ONLY-unset}" >"$STUB_SHARE_LOG"
# The real selector diffs its own tree's work tree, so the stub logs that.
[[ -z "${STUB_STATUS_LOG:-}" ]] || git -C "$(dirname "$0")/.." status --porcelain --untracked-files=all >"$STUB_STATUS_LOG"
[[ -v CHECK_DATA_ROOT ]] && { echo "affected-tests saw CHECK_DATA_ROOT" >&2; exit 1; }
Expand Down Expand Up @@ -294,6 +295,9 @@ check "CHECK_AFFECTED_JOBS and CHECK_AFFECTED_BUDGET override the defaults" \
'[[ $RC == 0 && $(cat "$args_log") == "--run --jobs 5 --budget 300 "* ]]'
run STUB_ARGS_LOG="$args_log" -- --base base --tests --budget 45
check "--budget sets the budget passed to affected-tests" '[[ $RC == 0 && $(cat "$args_log") == *" --budget 45 "* ]]'
share_log="$tmp/affected-share.log"
run -u PLUGIN_TEST_SHARE_WARN_ONLY STUB_SHARE_LOG="$share_log" -- --base base --tests
check "--tests passes PLUGIN_TEST_SHARE_WARN_ONLY=1 to the suites" '[[ $RC == 0 && $(cat "$share_log") == 1 ]]'
run CHECK_DATA_ROOT="$repo" -- --base base --tests
check "--tests keeps a caller's CHECK_DATA_ROOT from the suites" '[[ $RC == 0 && $ERR != *"saw CHECK_DATA_ROOT"* ]]'
run STUB_AFFECTED_TESTS=3 STUB_NOT_RUN=$'eco/test_x.py\neco/X.Tests.ps1\n' -- --base base --tests
Expand Down
26 changes: 22 additions & 4 deletions scripts/run-plugin-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@
# for the local affected-only run (scripts/check-affected.sh --tests). A run
# over it reports the overrun and its three slowest suites, and does not fail.
# Each suite gets a share, and a suite that takes longer than its share fails
# by name: the share is its scripts/suite-seconds.txt median times
# by name, unless PLUGIN_TEST_SHARE_WARN_ONLY=1 (below): the share is its scripts/suite-seconds.txt median times
# $PLUGIN_TEST_SHARE_MARGIN (default 3), and never less than
# $PLUGIN_TEST_SHARE_DEFAULT seconds (default 30), the share of a suite the file
# does not list. The medians are CI runner measurements, so the margin covers a
# slower host and a loaded job pool. Without --budget no suite is timed against
# a share, which is how CI runs.
# slower host and a loaded job pool. Each selected suite the file does not list
# is named on stderr with the default share it gets. With
# PLUGIN_TEST_SHARE_WARN_ONLY=1, which scripts/check-affected.sh sets for the
# local gate, a suite over its share is a warning instead, so a suite that
# passes on a loaded host does not fail the run; a suite that fails still does.
# Without --budget no suite is timed against a share, which is how CI runs.
#
# SUITE BUDGET. On GitHub Actions (GITHUB_ACTIONS=true) every suite is timed
# against a per-suite threshold and ceiling: over the threshold it prints
Expand Down Expand Up @@ -239,7 +243,12 @@ if [[ ! "$jobs" =~ ^[1-9][0-9]*$ ]]; then
fi
share_margin="${PLUGIN_TEST_SHARE_MARGIN:-3}"
share_default="${PLUGIN_TEST_SHARE_DEFAULT:-30}"
share_warn_only="${PLUGIN_TEST_SHARE_WARN_ONLY:-0}"
if ((budget_given)); then
if [[ "$share_warn_only" != [01] ]]; then
echo "error: PLUGIN_TEST_SHARE_WARN_ONLY must be 0 or 1 (got '$share_warn_only')" >&2
exit 2
fi
for v in "--budget:$budget" "PLUGIN_TEST_SHARE_MARGIN:$share_margin" "PLUGIN_TEST_SHARE_DEFAULT:$share_default"; do
if [[ ! "${v#*:}" =~ ^[1-9][0-9]*$ ]]; then
echo "error: ${v%%:*} must be a positive integer (got '${v#*:}')" >&2
Expand Down Expand Up @@ -413,6 +422,12 @@ suite_share() {
((share > share_default)) || share="$share_default"
printf '%s' "$share"
}
if [[ -n "$budget" ]]; then
for t in "${tests[@]}"; do
[[ -n "${median[$t]+x}" ]] ||
echo "note: $t has no median in $SECONDS_LIST, so it gets the default ${share_default}s share" >&2
done
fi

log_dir="$(mktemp -d)"
trap 'rm -rf "$log_dir"' EXIT
Expand Down Expand Up @@ -488,7 +503,10 @@ for i in "${!tests[@]}"; do
secs="$(<"$log.secs")"
timings+=("$secs"$'\t'"$t")
share="$(suite_share "$t")"
if ((secs > share)); then
if ((secs > share && share_warn_only)); then
echo "OVER SHARE: $t took ${secs}s, over its ${share}s share of the budget (a warning: PLUGIN_TEST_SHARE_WARN_ONLY=1)" >&2
suite_annotate warning "$t" "$t took ${secs}s, over its ${share}s share of the budget"
elif ((secs > share)); then
echo "FAIL: $t took ${secs}s, over its ${share}s share of the budget" >&2
suite_annotate error "$t" "$t took ${secs}s, over its ${share}s share of the budget"
failed=1
Expand Down
42 changes: 42 additions & 0 deletions scripts/run-plugin-tests.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
RUNNER="$ROOT/scripts/run-plugin-tests.sh"
# The test-bash lane exports this on main; each case below sets it itself.
unset PLUGIN_TEST_ADVISORY
# scripts/check-affected.sh exports this to the suites it runs; the share cases
# below set it themselves.
unset PLUGIN_TEST_SHARE_WARN_ONLY
# CI's GITHUB_ACTIONS would turn the suite budget on for every case; the
# suite-budget cases below turn it on themselves.
export PLUGIN_TEST_SUITE_BUDGET=0
Expand Down Expand Up @@ -596,6 +599,45 @@ PLUGIN_TEST_SERIAL_LIST="$empty_list" run_runner 2 "an empty --budget= is reject
PLUGIN_TEST_SHARE_MARGIN=0 PLUGIN_TEST_SERIAL_LIST="$empty_list" run_runner 2 "a zero share margin is rejected" --root "$r" --budget 60
assert_output_has "the bad margin is named" "PLUGIN_TEST_SHARE_MARGIN must be a positive integer (got '0')"

# A suite with no median is named with the default share it gets.
PLUGIN_TEST_SHARE_MARGIN=1 PLUGIN_TEST_SHARE_DEFAULT=7 PLUGIN_TEST_SECONDS_LIST="$budget_seconds" \
PLUGIN_TEST_SERIAL_LIST="$empty_list" run_runner 0 "a run with an unlisted suite still passes" --root "$r" --budget 600
assert_output_has "the unlisted suite is named with its default share" \
"note: plugins/quick/quick.test.sh has no median in $budget_seconds, so it gets the default 7s share"
assert_output_lacks "a listed suite is not named as unlisted" "note: plugins/slow/slow.test.sh"

# --- the local gate: a passing suite over its share warns, a failing one fails --
#
# The slow suite passes but runs past its fixed 1 s share, as a passing suite
# does on a loaded host.
PLUGIN_TEST_SHARE_WARN_ONLY=1 PLUGIN_TEST_SHARE_MARGIN=1 PLUGIN_TEST_SHARE_DEFAULT=1 \
PLUGIN_TEST_SECONDS_LIST="$no_seconds" PLUGIN_TEST_SERIAL_LIST="$empty_list" \
run_runner 0 "in the local gate a passing suite over its share does not fail the run" --root "$r" --jobs 2 --budget 1
assert_output_has "the over-share suite is named as a warning" "OVER SHARE: plugins/slow/slow.test.sh took "
assert_output_has "the warning annotation names the suite" \
"::warning title=plugins/slow/slow.test.sh::plugins/slow/slow.test.sh took "
assert_output_lacks "the passing over-share suite is not failed" "FAIL: plugins/slow/slow.test.sh"
assert_error_count "the passing over-share suite gets no error annotation" 0

# The per-suite budget cases below reuse the budget root, so this one has its own.
fail_root="$(make_root warn-only-fail)"
write_suite "$fail_root" plugins/slowfail/slowfail.test.sh 'sleep 2.1; echo "FAIL: slow and broken" >&2; exit 1'
PLUGIN_TEST_SHARE_WARN_ONLY=1 PLUGIN_TEST_SHARE_MARGIN=1 PLUGIN_TEST_SHARE_DEFAULT=1 \
PLUGIN_TEST_SECONDS_LIST="$no_seconds" PLUGIN_TEST_SERIAL_LIST="$empty_list" \
run_runner 1 "in the local gate a failing suite over its share still fails the run" --root "$fail_root" --budget 1
assert_output_has "the failing suite is failed by its exit" "plugins/slowfail/slowfail.test.sh failed (exit 1)"
assert_output_has "its overrun is still only a warning" "OVER SHARE: plugins/slowfail/slowfail.test.sh took "
assert_error_count "only the exit gets an error annotation" 1

PLUGIN_TEST_SHARE_WARN_ONLY=0 PLUGIN_TEST_SHARE_MARGIN=1 PLUGIN_TEST_SHARE_DEFAULT=1 \
PLUGIN_TEST_SECONDS_LIST="$no_seconds" PLUGIN_TEST_SERIAL_LIST="$empty_list" \
run_runner 1 "with the switch at 0 a passing suite over its share fails the run" --root "$r" --jobs 2 --budget 1
assert_output_has "the over-share suite is failed by name" "FAIL: plugins/slow/slow.test.sh took "

PLUGIN_TEST_SHARE_WARN_ONLY=yes PLUGIN_TEST_SERIAL_LIST="$empty_list" \
run_runner 2 "a share warn-only switch other than 0 or 1 is rejected" --root "$fail_root" --budget 60
assert_output_has "the bad switch is named" "PLUGIN_TEST_SHARE_WARN_ONLY must be 0 or 1 (got 'yes')"

# --- the per-suite budget: warn over the threshold, fail over the ceiling --------
#
# Reuses the budget root: slow takes at least 2 s, quick 0 or 1.
Expand Down
Loading