-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Expand file tree
/
Copy pathftr_smart_retry.sh
More file actions
61 lines (49 loc) · 2.16 KB
/
ftr_smart_retry.sh
File metadata and controls
61 lines (49 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Sourced by ftr_configs.sh — do not execute directly.
# Reads/writes globals: exitCode, failedConfigs,
# FAILED_CONFIGS_KEY, JOB, BUILDKITE_RETRY_COUNT.
FAILED_TESTS_KEY="${BUILDKITE_STEP_ID}${FTR_CONFIG_GROUP_KEY}_failed_tests"
retry_recovered=false
# Called after attempt 1: stores failing test names so the retry can verify recovery.
store_failing_tests() {
[[ -n "${KIBANA_FLAKY_TEST_RUNNER_CONFIG:-}" ]] && return
[[ "${BUILDKITE_RETRY_COUNT:-0}" != "0" ]] && return
[[ "$exitCode" == "0" ]] && return
local junitDir="target/junit/$JOB"
[[ -d "$junitDir" ]] || return
local failedTestNames
failedTestNames=$(node scripts/ftr_check_retry_result list-failures "$junitDir" 2>/dev/null || true)
if [[ "$failedTestNames" ]]; then
buildkite-agent meta-data set "$FAILED_TESTS_KEY" "$failedTestNames"
echo "Stored $(echo "$failedTestNames" | wc -l | tr -d ' ') previously-failing test name(s) for retry evaluation"
fi
}
# Called after attempt 2: marks the step green if all previously-failing tests explicitly passed.
# On a third-or-later manual retry, logs that smart-retry is inactive.
apply_smart_retry() {
[[ -n "${KIBANA_FLAKY_TEST_RUNNER_CONFIG:-}" ]] && return
[[ "$exitCode" == "0" ]] && return
local retryCount="${BUILDKITE_RETRY_COUNT:-0}"
if [[ "$retryCount" -ge "2" ]]; then
echo "--- [smart-retry] inactive on attempt $((retryCount + 1)) — only applies to the first automatic retry"
return
fi
[[ "$retryCount" != "1" ]] && return
local prevFailedTests
prevFailedTests=$(buildkite-agent meta-data get "$FAILED_TESTS_KEY" --default '' 2>/dev/null || true)
[[ "$prevFailedTests" ]] || return
local junitDir="target/junit/$JOB"
local intersectionCode
set +e
printf '%s' "$prevFailedTests" | node scripts/ftr_check_retry_result check-intersection \
--junit-dir "$junitDir" \
--prev-failures-stdin
intersectionCode=$?
set -e
if [[ "$intersectionCode" == "0" ]]; then
echo "--- [smart-retry] All previously-failing tests recovered on retry — marking step green"
exitCode=0
failedConfigs=""
retry_recovered=true
buildkite-agent meta-data set "$FAILED_CONFIGS_KEY" "" 2>/dev/null || true
fi
}