|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 4 | +# contributor license agreements. See the NOTICE file distributed with |
| 5 | +# this work for additional information regarding copyright ownership. |
| 6 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 7 | +# (the "License"); you may not use this file except in compliance with |
| 8 | +# the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | + |
| 18 | +set -euo pipefail |
| 19 | + |
| 20 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 21 | +readonly SCRIPT_DIR |
| 22 | +test_dir="$(mktemp -d)" |
| 23 | +trap 'rm -f "${test_dir}/"*; rmdir "${test_dir}"' EXIT |
| 24 | +export TEST_DIR="${test_dir}" |
| 25 | +export PATH="${test_dir}:${PATH}" |
| 26 | +export CANCEL_SLEEP=0 |
| 27 | + |
| 28 | +cat > "${test_dir}/maven" <<'BASH' |
| 29 | +#!/usr/bin/env bash |
| 30 | +set -euo pipefail |
| 31 | +attempt=$(($(cat "${TEST_DIR}/count") + 1)) |
| 32 | +echo "${attempt}" > "${TEST_DIR}/count" |
| 33 | +printf '%s\0' "$@" > "${TEST_DIR}/arguments" |
| 34 | +if [[ "${attempt}" -gt "${FAILURES}" ]]; then |
| 35 | + echo '[INFO] BUILD SUCCESS' |
| 36 | + exit 0 |
| 37 | +fi |
| 38 | +cat "${TEST_DIR}/failure-${attempt}" |
| 39 | +exit 1 |
| 40 | +BASH |
| 41 | + |
| 42 | +cat > "${test_dir}/sleep" <<'BASH' |
| 43 | +#!/usr/bin/env bash |
| 44 | +echo "$1" >> "${TEST_DIR}/delays" |
| 45 | +if [[ "${CANCEL_SLEEP}" -eq 1 ]]; then |
| 46 | + kill -TERM "${PPID}" |
| 47 | +fi |
| 48 | +BASH |
| 49 | +chmod +x "${test_dir}/maven" "${test_dir}/sleep" |
| 50 | + |
| 51 | +cat > "${test_dir}/reset" <<'LOG' |
| 52 | +[ERROR] Failed to execute goal on project shenyu-examples-eureka: Could not collect dependencies |
| 53 | +[ERROR] Failed to read artifact descriptor for org.glassfish.jersey.core:jersey-client:jar:3.0.5 |
| 54 | +[ERROR] Caused by: Could not transfer artifact org.glassfish.jersey.core:jersey-client:pom:3.0.5 from/to central (https://repo.maven.apache.org/maven2): Connection reset |
| 55 | +[ERROR] -> [Help 1] |
| 56 | +[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException |
| 57 | +LOG |
| 58 | + |
| 59 | +cat > "${test_dir}/parent" <<'LOG' |
| 60 | +[ERROR] The build could not read 1 project -> [Help 1] |
| 61 | +[ERROR] The project org.apache.shenyu:shenyu:2.7.2-SNAPSHOT (/workspace/pom.xml) has 1 error |
| 62 | +[ERROR] Non-resolvable parent POM for org.apache.shenyu:shenyu:2.7.2-SNAPSHOT: Could not transfer artifact org.apache:apache:pom:21 from/to central (https://repo.maven.apache.org/maven2): status code: 429, reason phrase: Too Many Requests (429) -> [Help 2] |
| 63 | +[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException |
| 64 | +[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException |
| 65 | +LOG |
| 66 | + |
| 67 | +cat > "${test_dir}/compile" <<'LOG' |
| 68 | +[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:compile on project shenyu-common: Compilation failure |
| 69 | +[ERROR] -> [Help 1] |
| 70 | +[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException |
| 71 | +LOG |
| 72 | + |
| 73 | +cat > "${test_dir}/wagon-502" <<'LOG' |
| 74 | +[ERROR] Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.12:prepare-agent (default) on project shenyu: Execution default of goal org.jacoco:jacoco-maven-plugin:0.8.12:prepare-agent failed: Plugin org.jacoco:jacoco-maven-plugin:0.8.12 or one of its dependencies could not be resolved: Could not transfer artifact org.apache.maven.shared:file-management:jar:3.1.0 from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/org/apache/maven/shared/file-management/3.1.0/file-management-3.1.0.jar 502 Bad Gateway -> [Help 1] |
| 75 | +[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException |
| 76 | +LOG |
| 77 | + |
| 78 | +cat > "${test_dir}/tests" <<'LOG' |
| 79 | +[ERROR] Tests run: 8, Failures: 1, Errors: 0, Skipped: 0 |
| 80 | +[ERROR] DividePluginTest.testDivide: expected 200 but received 502 Bad Gateway |
| 81 | +[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:test on project shenyu-common: There are test failures. |
| 82 | +[ERROR] -> [Help 1] |
| 83 | +[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException |
| 84 | +LOG |
| 85 | + |
| 86 | +cat > "${test_dir}/missing" <<'LOG' |
| 87 | +[ERROR] Failed to execute goal on project shenyu-spring-boot-starter-client-beat: Could not resolve dependencies |
| 88 | +[ERROR] Could not find artifact org.apache.shenyu:shenyu-register-client-beat:jar:2.7.2-SNAPSHOT in apache.snapshots (https://repository.apache.org/snapshots) |
| 89 | +[ERROR] -> [Help 1] |
| 90 | +[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException |
| 91 | +LOG |
| 92 | + |
| 93 | +run_case() { |
| 94 | + local name="$1" fixture="$2" failures="$3" expected_count="$4" expected_status="$5" |
| 95 | + local status=0 |
| 96 | + local attempt |
| 97 | + echo 0 > "${test_dir}/count" |
| 98 | + : > "${test_dir}/delays" |
| 99 | + for attempt in 1 2 3; do |
| 100 | + cp "${fixture}" "${test_dir}/failure-${attempt}" |
| 101 | + done |
| 102 | + FAILURES="${failures}" bash "${SCRIPT_DIR}/maven-with-retry.sh" "${test_dir}/maven" \ |
| 103 | + '-Dmessage=two words' 'literal $(command); *' > "${test_dir}/output" 2>&1 || status=$? |
| 104 | + if [[ "${status}" -ne "${expected_status}" || "$(cat "${test_dir}/count")" -ne "${expected_count}" ]]; then |
| 105 | + echo "${name}: expected status/count ${expected_status}/${expected_count}, got ${status}/$(cat "${test_dir}/count")" >&2 |
| 106 | + cat "${test_dir}/output" >&2 |
| 107 | + exit 1 |
| 108 | + fi |
| 109 | + echo "Passed: ${name}" |
| 110 | +} |
| 111 | + |
| 112 | +run_case success "${test_dir}/reset" 0 1 0 |
| 113 | +# shellcheck disable=SC2016 # Command substitution must remain a literal argument. |
| 114 | +printf '%s\0' '-Dmessage=two words' 'literal $(command); *' > "${test_dir}/expected-arguments" |
| 115 | +cmp "${test_dir}/expected-arguments" "${test_dir}/arguments" |
| 116 | +[[ ! -s "${test_dir}/delays" ]] |
| 117 | + |
| 118 | +run_case reset "${test_dir}/reset" 1 2 0 |
| 119 | +grep -Fq 'Connection reset' "${test_dir}/output" |
| 120 | +grep -Fq 'BUILD SUCCESS' "${test_dir}/output" |
| 121 | +run_case parent-429 "${test_dir}/parent" 1 2 0 |
| 122 | + |
| 123 | +for reason in 'status code: 502, reason phrase: Bad Gateway (502)' 'status: 502 Bad Gateway' 'Return code is: 502, ReasonPhrase: Bad Gateway'; do |
| 124 | + sed "s/Connection reset/${reason}/" "${test_dir}/reset" > "${test_dir}/http" |
| 125 | + run_case "${reason}" "${test_dir}/http" 1 2 0 |
| 126 | +done |
| 127 | + |
| 128 | +run_case wagon-502 "${test_dir}/wagon-502" 1 2 0 |
| 129 | + |
| 130 | +# mvnd prefixes module output, and Maven can emit ANSI colors and CRLF. |
| 131 | +sed 's/^/[shenyu-examples-eureka] /' "${test_dir}/reset" > "${test_dir}/prefixed" |
| 132 | +while IFS= read -r line; do |
| 133 | + printf '\033[1;31m%s\033[0m\r\n' "${line}" |
| 134 | +done < "${test_dir}/prefixed" > "${test_dir}/colored" |
| 135 | +run_case colored-mvnd "${test_dir}/colored" 1 2 0 |
| 136 | + |
| 137 | +run_case exhausted "${test_dir}/reset" 3 3 1 |
| 138 | +printf '10\n20\n' > "${test_dir}/expected-delays" |
| 139 | +cmp "${test_dir}/expected-delays" "${test_dir}/delays" |
| 140 | + |
| 141 | +for fixture in compile tests missing; do |
| 142 | + run_case "${fixture}" "${test_dir}/${fixture}" 3 1 1 |
| 143 | +done |
| 144 | +sed 's/Connection reset/status code: 404, reason phrase: Not Found (404)/' "${test_dir}/reset" > "${test_dir}/not-found" |
| 145 | +run_case http-404 "${test_dir}/not-found" 3 1 1 |
| 146 | +sed 's/from\/to central (https:\/\/repo.maven.apache.org\/maven2)/from\/to apache.snapshots (https:\/\/repository.apache.org\/snapshots)/' \ |
| 147 | + "${test_dir}/reset" > "${test_dir}/other-repository" |
| 148 | +run_case other-repository "${test_dir}/other-repository" 3 1 1 |
| 149 | + |
| 150 | +# A reset in test output must not make a compiler failure retryable. |
| 151 | +cat "${test_dir}/reset" "${test_dir}/compile" > "${test_dir}/mixed" |
| 152 | +run_case mixed-failures "${test_dir}/mixed" 3 1 1 |
| 153 | +cat "${test_dir}/tests" "${test_dir}/reset" > "${test_dir}/mixed" |
| 154 | +run_case mixed-failures-reversed "${test_dir}/mixed" 3 1 1 |
| 155 | + |
| 156 | +# Multiple missing dependencies can belong to one terminal Maven error. |
| 157 | +sed '/^\[ERROR\] ->/i\[ERROR] Could not find artifact org.apache.shenyu:missing:jar:2.7.2-SNAPSHOT' \ |
| 158 | + "${test_dir}/reset" > "${test_dir}/mixed-dependencies" |
| 159 | +run_case mixed-dependencies "${test_dir}/mixed-dependencies" 3 1 1 |
| 160 | +sed '/^\[ERROR\] ->/i\[ERROR] Could not transfer artifact org.example:other:pom:1 from/to central (https://repo.maven.apache.org/maven2): status code: 404' \ |
| 161 | + "${test_dir}/reset" > "${test_dir}/mixed-transfers" |
| 162 | +run_case mixed-transfers "${test_dir}/mixed-transfers" 3 1 1 |
| 163 | + |
| 164 | +# ProjectBuildingException also covers unrelated POM errors. |
| 165 | +sed 's/has 1 error/has 2 errors/' "${test_dir}/parent" > "${test_dir}/invalid-model" |
| 166 | +echo '[ERROR] Unknown packaging: invalid' >> "${test_dir}/invalid-model" |
| 167 | +run_case invalid-model "${test_dir}/invalid-model" 3 1 1 |
| 168 | + |
| 169 | +# A later attempt must not reuse the preceding attempt's transfer error. |
| 170 | +echo 0 > "${test_dir}/count" |
| 171 | +cp "${test_dir}/reset" "${test_dir}/failure-1" |
| 172 | +cp "${test_dir}/compile" "${test_dir}/failure-2" |
| 173 | +status=0 |
| 174 | +FAILURES=3 bash "${SCRIPT_DIR}/maven-with-retry.sh" "${test_dir}/maven" > "${test_dir}/output" 2>&1 || status=$? |
| 175 | +[[ "${status}" -eq 1 && "$(cat "${test_dir}/count")" -eq 2 ]] |
| 176 | +echo 'Passed: current-attempt-only' |
| 177 | + |
| 178 | +export CANCEL_SLEEP=1 |
| 179 | +run_case cancellation "${test_dir}/reset" 3 1 143 |
| 180 | + |
| 181 | +echo 'Maven transfer retry tests passed' |
0 commit comments