diff --git a/.github/actions/incremental-build/reactor_timing.sh b/.github/actions/incremental-build/reactor_timing.sh index 291132cdb2c0f..8d60ae9a1e26a 100644 --- a/.github/actions/incremental-build/reactor_timing.sh +++ b/.github/actions/incremental-build/reactor_timing.sh @@ -133,10 +133,13 @@ sum_elapsed_seconds_from_tsv() { render_top_slowest_modules() { local tsv="$1" local limit="${2:-${TOP_SLOWEST_LIMIT}}" + # Limit with awk, which reads all its input, not head: incremental-build.sh + # ignores SIGPIPE, so sort fails with a write error once head stops reading, + # and pipefail turns that into a failed build (CAMEL-24777). echo "$tsv" | awk -F '\t' ' $2 != "" && $2 ~ /^[0-9]+(\.[0-9]+)?$/ { printf "%s\t%s\n", $2, $1 - }' | sort -t $'\t' -k1,1nr | head -n "$limit" | while IFS=$'\t' read -r seconds module; do + }' | sort -t $'\t' -k1,1nr | awk -v n="$limit" 'NR <= n' | while IFS=$'\t' read -r seconds module; do local formatted formatted=$(format_elapsed_seconds "$seconds") echo "- \`${module}\` (${formatted})" diff --git a/.github/actions/incremental-build/reactor_timing_test.sh b/.github/actions/incremental-build/reactor_timing_test.sh index c1e39b5c5c80e..a878f996562bb 100755 --- a/.github/actions/incremental-build/reactor_timing_test.sh +++ b/.github/actions/incremental-build/reactor_timing_test.sh @@ -115,6 +115,18 @@ append_reactor_timing_report "$empty_fixture" "$empty_report" "All tested module assert_eq "" "$(cat "$empty_report")" "empty log yields empty report" rm -f "$empty_fixture" "$empty_report" +# A large reactor with SIGPIPE ignored, as incremental-build.sh runs it: limiting +# the slowest modules must not fail the pipeline (CAMEL-24777) +large_tsv="$(seq 1 50000 | awk '{ printf "module-%d\t%d\tSUCCESS\n", $1, $1 }')" +if large_slowest="$(trap '' PIPE; render_top_slowest_modules "$large_tsv" 3 2>&1)"; then + pass=$((pass + 1)) +else + echo "FAIL: render_top_slowest_modules fails on a large reactor with SIGPIPE ignored" + fail=$((fail + 1)) +fi +assert_eq "3" "$(echo "$large_slowest" | grep -c .)" "large reactor lists only the limit" +assert_contains "$large_slowest" "\`module-50000\`" "large reactor lists the slowest module first" + echo "" echo "reactor_timing_test.sh: ${pass} passed, ${fail} failed" if [[ "$fail" -ne 0 ]]; then