forked from redhat-developer/rhdh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-run-tracker.sh
More file actions
67 lines (56 loc) · 2.05 KB
/
Copy pathtest-run-tracker.sh
File metadata and controls
67 lines (56 loc) · 2.05 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
62
63
64
65
66
67
#!/bin/bash
# Prevent sourcing multiple times in the same shell.
if [[ -n "${RHDH_TEST_RUN_TRACKER_LIB_SOURCED:-}" ]]; then
return 0
fi
readonly RHDH_TEST_RUN_TRACKER_LIB_SOURCED=1
# shellcheck source=.ci/pipelines/reporting.sh
source "$(dirname "${BASH_SOURCE[0]}")/../reporting.sh"
# Sentinel value for STATUS_NUMBER_OF_TEST_FAILED when the real count
# is unknown (deploy failed, Prow timeout, JUnit file missing, or
# Playwright crashed without producing failure counts).
UNKNOWN_FAILURE_COUNT="N/A"
# Internal state
_TEST_RUN_COUNTER=0
test_run_tracker::next_id() {
_TEST_RUN_COUNTER=$((_TEST_RUN_COUNTER + 1))
echo "${_TEST_RUN_COUNTER}"
}
test_run_tracker::current_id() {
echo "${_TEST_RUN_COUNTER}"
}
test_run_tracker::register() {
local label="$1"
test_run_tracker::next_id > /dev/null
save_status_deployment_namespace "${_TEST_RUN_COUNTER}" "$label"
}
test_run_tracker::mark_deploy_success() {
save_status_failed_to_deploy "${_TEST_RUN_COUNTER}" false
}
test_run_tracker::mark_deploy_failed() {
local label="$1"
test_run_tracker::register "$label"
save_status_failed_to_deploy "${_TEST_RUN_COUNTER}" true
save_status_test_failed "${_TEST_RUN_COUNTER}" true
save_status_number_of_test_failed "${_TEST_RUN_COUNTER}" "${UNKNOWN_FAILURE_COUNT}"
save_overall_result 1
}
test_run_tracker::mark_test_result() {
local passed="$1"
local num_failures="${2:-0}"
if [[ "$passed" == "true" ]]; then
save_status_test_failed "${_TEST_RUN_COUNTER}" false
else
save_status_test_failed "${_TEST_RUN_COUNTER}" true
fi
save_status_number_of_test_failed "${_TEST_RUN_COUNTER}" "$num_failures"
}
# Export all functions for subshell compatibility.
# Note: _TEST_RUN_COUNTER is NOT exported because subshells inherit only
# the snapshot at fork time — counter updates in the parent would not propagate.
export -f test_run_tracker::next_id
export -f test_run_tracker::current_id
export -f test_run_tracker::register
export -f test_run_tracker::mark_deploy_success
export -f test_run_tracker::mark_deploy_failed
export -f test_run_tracker::mark_test_result