This is an automated email from the ASF dual-hosted git repository. dragonyliu pushed a commit to branch branch-2 in repository https://gitbox.apache.org/repos/asf/ratis.git
commit c6892d13ecaa7d3dd9c714f0fd43005cb5cd4d4d Author: Doroszlai, Attila <[email protected]> AuthorDate: Mon Oct 10 20:16:15 2022 +0200 RATIS-1658. Prepare unit check for running some tests repeatedly (#704) (cherry picked from commit 84a2997df4917f127217387fbb81dfa63db1c035) --- dev-support/checks/_mvn_unit_report.sh | 38 ++++++++++++++++++------------- dev-support/checks/unit.sh | 41 ++++++++++++++++++++++++++++------ 2 files changed, 57 insertions(+), 22 deletions(-) diff --git a/dev-support/checks/_mvn_unit_report.sh b/dev-support/checks/_mvn_unit_report.sh index 682de9e9f..f7123775f 100755 --- a/dev-support/checks/_mvn_unit_report.sh +++ b/dev-support/checks/_mvn_unit_report.sh @@ -27,17 +27,18 @@ _realpath() { } ## generate summary txt file -find "." -name 'TEST*.xml' -print0 \ +find "." -not -path '*/iteration*' -name 'TEST*.xml' -print0 \ | xargs -n1 -0 "grep" -l -E "<failure|<error" \ | awk -F/ '{sub("'"TEST-"'",""); sub(".xml",""); print $NF}' \ | tee "$REPORT_DIR/summary.txt" #Copy heap dump and dump leftovers -find "." -name "*.hprof" \ +find "." -not -path '*/iteration*' \ + \( -name "*.hprof" \ -or -name "*.dump" \ -or -name "*.dumpstream" \ - -or -name "hs_err_*.log" \ - -exec cp {} "$REPORT_DIR/" \; + -or -name "hs_err_*.log" \) \ + -exec mv {} "$REPORT_DIR/" \; ## Add the tests where the JVM is crashed grep -A1 'Crashed tests' "${REPORT_DIR}/output.log" \ @@ -46,23 +47,30 @@ grep -A1 'Crashed tests' "${REPORT_DIR}/output.log" \ | sort -u \ | tee -a "${REPORT_DIR}/summary.txt" -# Add tests where "There was a timeout or other error in the fork" -grep -e 'Running org' -e 'Tests run: .* in org' "${REPORT_DIR}/output.log" \ - | sed -e 's/.* \(org[^ ]*\)/\1/' \ - | uniq -c \ - | grep -v ' 2 ' \ - | awk '{ print $2 }' \ - | sort -u \ - | tee -a "${REPORT_DIR}/summary.txt" - +# Check for tests that started but were not finished +if grep -q 'There was a timeout or other error in the fork' "${REPORT_DIR}/output.log"; then + diff -uw \ + <(grep -e 'Running org' "${REPORT_DIR}/output.log" \ + | sed -e 's/.* \(org[^ ]*\)/\1/' \ + | uniq -c \ + | sort -u -k2) \ + <(grep -e 'Tests run: .* in org' "${REPORT_DIR}/output.log" \ + | sed -e 's/.* \(org[^ ]*\)/\1/' \ + | uniq -c \ + | sort -u -k2) \ + | grep '^- ' \ + | awk '{ print $3 }' \ + | tee -a "${REPORT_DIR}/summary.txt" +fi #Collect of all of the report files of FAILED tests for failed_test in $(< ${REPORT_DIR}/summary.txt); do - for file in $(find "." -name "${failed_test}.txt" -or -name "${failed_test}-output.txt" -or -name "TEST-${failed_test}.xml"); do + for file in $(find "." -not -path '*/iteration*' \ + \( -name "${failed_test}.txt" -or -name "${failed_test}-output.txt" -or -name "TEST-${failed_test}.xml" \)); do dir=$(dirname "${file}") dest_dir=$(_realpath --relative-to="${PWD}" "${dir}/../..") || continue mkdir -p "${REPORT_DIR}/${dest_dir}" - cp "${file}" "${REPORT_DIR}/${dest_dir}"/ + mv "${file}" "${REPORT_DIR}/${dest_dir}"/ done done diff --git a/dev-support/checks/unit.sh b/dev-support/checks/unit.sh index 4a57d8205..50a1c712f 100755 --- a/dev-support/checks/unit.sh +++ b/dev-support/checks/unit.sh @@ -19,17 +19,44 @@ set -o pipefail DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" cd "$DIR/../.." || exit 1 +: ${ITERATIONS:="1"} + +declare -i ITERATIONS +if [[ ${ITERATIONS} -le 0 ]]; then + ITERATIONS=1 +fi + REPORT_DIR=${OUTPUT_DIR:-"$DIR/../../target/unit"} mkdir -p "$REPORT_DIR" export MAVEN_OPTS="-Xmx4096m" -mvn -B -fae test "$@" | tee "${REPORT_DIR}/output.log" -rc=$? -# shellcheck source=dev-support/checks/_mvn_unit_report.sh -source "$DIR/_mvn_unit_report.sh" +rc=0 +for i in $(seq 1 ${ITERATIONS}); do + if [[ ${ITERATIONS} -gt 1 ]]; then + original_report_dir="${REPORT_DIR}" + REPORT_DIR="${original_report_dir}/iteration${i}" + mkdir -p "${REPORT_DIR}" + fi + + mvn -B -fae test "$@" \ + | tee "${REPORT_DIR}/output.log" + irc=$? + + # shellcheck source=dev-support/checks/_mvn_unit_report.sh + source "${DIR}/_mvn_unit_report.sh" + if [[ ${irc} == 0 ]] && [[ -s "${REPORT_DIR}/summary.txt" ]]; then + irc=1 + fi + + if [[ ${ITERATIONS} -gt 1 ]]; then + REPORT_DIR="${original_report_dir}" + echo "Iteration ${i} exit code: ${irc}" | tee -a "${REPORT_DIR}/summary.txt" + fi + + if [[ ${rc} == 0 ]]; then + rc=${irc} + fi +done -if [[ -s "$REPORT_DIR/summary.txt" ]] ; then - exit 1 -fi exit ${rc}
