Skip to content

Commit b98a55d

Browse files
committed
fix(ci): write pessimistic test status before Playwright execution
When Prow kills a job (2h timeout) or Playwright hangs, the mark_test_result call at the end of testing::run_tests never executes. This leaves STATUS_TEST_FAILED.txt and STATUS_NUMBER_OF_TEST_FAILED.txt with fewer entries than STATUS_DEPLOYMENT_NAMESPACE.txt, creating misaligned arrays that break downstream reporting (Slack notifications). Fix: write a pessimistic default (failed=true, count=N/A) immediately after registering the test run. The real result overwrites it after Playwright completes. If the job is killed mid-test, the STATUS files still have entries for all registered test runs. To support this, save_status_test_failed and save_status_number_of_test_failed now regenerate the file from the in-memory array instead of appending, making them safe to call multiple times for the same deployment ID. Assisted-by: OpenCode
1 parent 63365ed commit b98a55d

2 files changed

Lines changed: 31 additions & 12 deletions

File tree

.ci/pipelines/lib/testing.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ testing::run_tests() {
5252
test_run_tracker::register "$artifacts_subdir"
5353
test_run_tracker::mark_deploy_success
5454

55+
# Pessimistic default: assume tests failed until Playwright proves otherwise.
56+
# If the job is killed (Prow timeout) or Playwright hangs, the STATUS files
57+
# still have entries for all registered test runs — preventing misaligned
58+
# arrays that break downstream reporting (Slack notifications).
59+
test_run_tracker::mark_test_result "false" "N/A"
60+
5561
BASE_URL="${url}"
5662
export BASE_URL
5763
log::info "BASE_URL: ${BASE_URL}"

.ci/pipelines/reporting.sh

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ readonly REPORTING_LIB_SOURCED=1
1010
source "$(dirname "${BASH_SOURCE[0]}")"/lib/log.sh
1111

1212
# Variables for reporting
13-
export STATUS_DEPLOYMENT_NAMESPACE # Array that holds the namespaces of deployments.
14-
export STATUS_FAILED_TO_DEPLOY # Array that indicates if deployment failed. false = success, true = failure
15-
export STATUS_TEST_FAILED # Array that indicates if test run failed. false = success, true = failure
16-
export OVERALL_RESULT # Overall result of the test run. 0 = success, 1 = failure
13+
export STATUS_DEPLOYMENT_NAMESPACE # Array that holds the namespaces of deployments.
14+
export STATUS_FAILED_TO_DEPLOY # Array that indicates if deployment failed. false = success, true = failure
15+
export STATUS_TEST_FAILED # Array that indicates if test run failed. false = success, true = failure
16+
export STATUS_NUMBER_OF_TEST_FAILED # Array that holds the number of test failures per deployment.
17+
export OVERALL_RESULT # Overall result of the test run. 0 = success, 1 = failure
1718

1819
mkdir -p "$ARTIFACT_DIR/reporting"
1920

@@ -22,35 +23,47 @@ save_status_deployment_namespace() {
2223
local current_namespace=$2
2324
log::debug "Saving STATUS_DEPLOYMENT_NAMESPACE[\"${current_deployment}\"]=${current_namespace}"
2425
STATUS_DEPLOYMENT_NAMESPACE["${current_deployment}"]="${current_namespace}"
25-
printf "%s\n" "${STATUS_DEPLOYMENT_NAMESPACE["${current_deployment}"]}" >> "$SHARED_DIR/STATUS_DEPLOYMENT_NAMESPACE.txt"
26-
cp "$SHARED_DIR/STATUS_DEPLOYMENT_NAMESPACE.txt" "$ARTIFACT_DIR/reporting/STATUS_DEPLOYMENT_NAMESPACE.txt"
26+
_regenerate_status_file "STATUS_DEPLOYMENT_NAMESPACE"
2727
}
2828

2929
save_status_failed_to_deploy() {
3030
local current_deployment=$1
3131
local status=$2
3232
log::debug "Saving STATUS_FAILED_TO_DEPLOY[\"${current_deployment}\"]=${status}"
3333
STATUS_FAILED_TO_DEPLOY["${current_deployment}"]="${status}"
34-
printf "%s\n" "${STATUS_FAILED_TO_DEPLOY["${current_deployment}"]}" >> "$SHARED_DIR/STATUS_FAILED_TO_DEPLOY.txt"
35-
cp "$SHARED_DIR/STATUS_FAILED_TO_DEPLOY.txt" "$ARTIFACT_DIR/reporting/STATUS_FAILED_TO_DEPLOY.txt"
34+
_regenerate_status_file "STATUS_FAILED_TO_DEPLOY"
3635
}
3736

3837
save_status_test_failed() {
3938
local current_deployment=$1
4039
local status=$2
4140
log::debug "Saving STATUS_TEST_FAILED[\"${current_deployment}\"]=${status}"
4241
STATUS_TEST_FAILED["${current_deployment}"]="${status}"
43-
printf "%s\n" "${STATUS_TEST_FAILED["${current_deployment}"]}" >> "$SHARED_DIR/STATUS_TEST_FAILED.txt"
44-
cp "$SHARED_DIR/STATUS_TEST_FAILED.txt" "$ARTIFACT_DIR/reporting/STATUS_TEST_FAILED.txt"
42+
_regenerate_status_file "STATUS_TEST_FAILED"
4543
}
4644

4745
save_status_number_of_test_failed() {
4846
local current_deployment=$1
4947
local number=$2
5048
log::debug "Saving STATUS_NUMBER_OF_TEST_FAILED[\"${current_deployment}\"]=${number}"
5149
STATUS_NUMBER_OF_TEST_FAILED["${current_deployment}"]="${number}"
52-
printf "%s\n" "${STATUS_NUMBER_OF_TEST_FAILED["${current_deployment}"]}" >> "$SHARED_DIR/STATUS_NUMBER_OF_TEST_FAILED.txt"
53-
cp "$SHARED_DIR/STATUS_NUMBER_OF_TEST_FAILED.txt" "$ARTIFACT_DIR/reporting/STATUS_NUMBER_OF_TEST_FAILED.txt"
50+
_regenerate_status_file "STATUS_NUMBER_OF_TEST_FAILED"
51+
}
52+
53+
# Regenerate a STATUS file from its in-memory associative array.
54+
# Writes the file from scratch each time so that the same deployment ID
55+
# can be safely updated multiple times (e.g. pessimistic default written
56+
# before Playwright runs, then overwritten with the real result).
57+
_regenerate_status_file() {
58+
local var_name=$1
59+
local -n _arr="${var_name}"
60+
local file="$SHARED_DIR/${var_name}.txt"
61+
: > "$file"
62+
local key
63+
for key in $(printf '%s\n' "${!_arr[@]}" | sort -n); do
64+
printf '%s\n' "${_arr[$key]}" >> "$file"
65+
done
66+
cp "$file" "$ARTIFACT_DIR/reporting/${var_name}.txt"
5467
}
5568

5669
save_overall_result() {

0 commit comments

Comments
 (0)