mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
GitHub Actions: Re-run only failed tests; warn about slow tests
This commit is contained in:
5
.github/workflows/main.yml
vendored
5
.github/workflows/main.yml
vendored
@@ -51,10 +51,13 @@ jobs:
|
|||||||
name: uhabits-android
|
name: uhabits-android
|
||||||
path: uhabits-android/build/outputs/
|
path: uhabits-android/build/outputs/
|
||||||
|
|
||||||
- name: Install flock
|
- name: Install Linux utils
|
||||||
run: |
|
run: |
|
||||||
brew install util-linux
|
brew install util-linux
|
||||||
|
brew unlink parallel
|
||||||
|
brew install moreutils
|
||||||
echo "/usr/local/opt/util-linux/bin" >> $GITHUB_PATH
|
echo "/usr/local/opt/util-linux/bin" >> $GITHUB_PATH
|
||||||
|
echo "/usr/local/opt/moreutils/bin" >> $GITHUB_PATH
|
||||||
|
|
||||||
- name: Run Android Tests
|
- name: Run Android Tests
|
||||||
run: ./build.sh android-tests ${{ matrix.api }}
|
run: ./build.sh android-tests ${{ matrix.api }}
|
||||||
|
|||||||
31
build.sh
31
build.sh
@@ -122,14 +122,25 @@ android_test() {
|
|||||||
$ADB install -r ${ANDROID_OUTPUTS_DIR}/apk/androidTest/debug/uhabits-android-debug-androidTest.apk || return 1
|
$ADB install -r ${ANDROID_OUTPUTS_DIR}/apk/androidTest/debug/uhabits-android-debug-androidTest.apk || return 1
|
||||||
|
|
||||||
for size in medium large; do
|
for size in medium large; do
|
||||||
log_info "Running $size instrumented tests..."
|
|
||||||
OUT_INSTRUMENT=${ANDROID_OUTPUTS_DIR}/instrument-${API}.txt
|
OUT_INSTRUMENT=${ANDROID_OUTPUTS_DIR}/instrument-${API}.txt
|
||||||
OUT_LOGCAT=${ANDROID_OUTPUTS_DIR}/logcat-${API}.txt
|
OUT_LOGCAT=${ANDROID_OUTPUTS_DIR}/logcat-${API}.txt
|
||||||
$ADB shell am instrument \
|
FAILED_TESTS=""
|
||||||
-r -e coverage true -e size $size \
|
for i in {1..5}; do
|
||||||
-w ${PACKAGE_NAME}.test/androidx.test.runner.AndroidJUnitRunner \
|
log_info "Running $size instrumented tests (attempt $i)..."
|
||||||
| tee $OUT_INSTRUMENT
|
$ADB shell am instrument \
|
||||||
if grep "\(INSTRUMENTATION_STATUS_CODE.*-1\|FAILURES\|ABORTED\|onError\|Error type\|crashed\)" $OUT_INSTRUMENT; then
|
-r -e coverage true -e size "$size" $FAILED_TESTS \
|
||||||
|
-w ${PACKAGE_NAME}.test/androidx.test.runner.AndroidJUnitRunner \
|
||||||
|
| ts "%.s" | tee "$OUT_INSTRUMENT"
|
||||||
|
|
||||||
|
FAILED_TESTS=$(tools/parseInstrument.py "$OUT_INSTRUMENT")
|
||||||
|
SUCCESS=$?
|
||||||
|
if [ $SUCCESS -eq 0 ]; then
|
||||||
|
log_info "$size tests passed."
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $SUCCESS -ne 0 ]; then
|
||||||
log_error "Some $size instrumented tests failed."
|
log_error "Some $size instrumented tests failed."
|
||||||
log_error "Saving logcat: $OUT_LOGCAT..."
|
log_error "Saving logcat: $OUT_LOGCAT..."
|
||||||
$ADB logcat -d > $OUT_LOGCAT
|
$ADB logcat -d > $OUT_LOGCAT
|
||||||
@@ -138,7 +149,6 @@ android_test() {
|
|||||||
$ADB shell rm -r /sdcard/Android/data/${PACKAGE_NAME}/files/test-screenshots/
|
$ADB shell rm -r /sdcard/Android/data/${PACKAGE_NAME}/files/test-screenshots/
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
log_info "$size tests passed."
|
|
||||||
done
|
done
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@@ -276,12 +286,7 @@ main() {
|
|||||||
_print_usage
|
_print_usage
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
for attempt in {1..5}; do
|
android_test $1
|
||||||
log_info "Running Android tests (attempt $attempt)..."
|
|
||||||
android_test $1 && return 0
|
|
||||||
done
|
|
||||||
log_error "Maximum number of attempts reached. Failing."
|
|
||||||
return 1
|
|
||||||
;;
|
;;
|
||||||
android-tests-parallel)
|
android-tests-parallel)
|
||||||
shift; _parse_opts "$@"
|
shift; _parse_opts "$@"
|
||||||
|
|||||||
58
tools/parseInstrument.py
Executable file
58
tools/parseInstrument.py
Executable file
@@ -0,0 +1,58 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Android Instrumentation Test Parser
|
||||||
|
|
||||||
|
Given a raw Android Instrumentation log (produced by "adb shell am instrument -r ...") this script
|
||||||
|
return zero if all tests pass and non-zero if some tests fail. In case of failure, this script
|
||||||
|
also prints arguments that, if passed to "am instrument", will cause it to re-run just the tests
|
||||||
|
that failed. This script additionally prints warning about the tests on the STDERR; e.g. slow tests.
|
||||||
|
"""
|
||||||
|
import sys
|
||||||
|
import re
|
||||||
|
|
||||||
|
STATUS_START = 1
|
||||||
|
STATUS_DISABLED = -3
|
||||||
|
SLOW_TEST_THRESHOLD = 5.0
|
||||||
|
|
||||||
|
COLOR_YELLOW = '\033[93m'
|
||||||
|
COLOR_END = '\033[0m'
|
||||||
|
|
||||||
|
def warn(msg):
|
||||||
|
sys.stderr.write("%s%s%s\n" % (COLOR_YELLOW, msg, COLOR_END))
|
||||||
|
|
||||||
|
log_filename = sys.argv[1]
|
||||||
|
current_class, current_method = None, None
|
||||||
|
failed_tests = ""
|
||||||
|
exit_code = 1
|
||||||
|
|
||||||
|
for line in open(log_filename).readlines():
|
||||||
|
matches = re.findall('^([0-9.]*)', line)
|
||||||
|
current_time = float(matches[0])
|
||||||
|
|
||||||
|
matches = re.findall('INSTRUMENTATION_STATUS: class=(.*)', line)
|
||||||
|
if len(matches) > 0:
|
||||||
|
current_class = matches[0]
|
||||||
|
|
||||||
|
matches = re.findall('INSTRUMENTATION_STATUS: test=(.*)', line)
|
||||||
|
if len(matches) > 0:
|
||||||
|
current_method = matches[0]
|
||||||
|
|
||||||
|
matches = re.findall('OK \([0-9]* tests\)', line)
|
||||||
|
if len(matches) > 0:
|
||||||
|
exit_code = 0
|
||||||
|
|
||||||
|
matches = re.findall('INSTRUMENTATION_STATUS_CODE: ([-0-9]*)', line)
|
||||||
|
if len(matches) > 0:
|
||||||
|
status_code = int(matches[0])
|
||||||
|
if (status_code < 0) and (status_code != STATUS_DISABLED):
|
||||||
|
failed_tests += f"-e class {current_class}#{current_method} "
|
||||||
|
if status_code == STATUS_START:
|
||||||
|
initial_time = current_time
|
||||||
|
else:
|
||||||
|
elapsed_time = current_time - initial_time
|
||||||
|
if(elapsed_time > SLOW_TEST_THRESHOLD):
|
||||||
|
warn("SLOW_TEST %s#%s (%.2f seconds)" % (current_class, current_method, elapsed_time))
|
||||||
|
|
||||||
|
if len(failed_tests) > 0:
|
||||||
|
print(failed_tests)
|
||||||
|
sys.exit(exit_code)
|
||||||
Reference in New Issue
Block a user