Skip to content

Commit 465f7ec

Browse files
authored
test: flakiness testing workflow (#128)
Signed-off-by: Nicklas Lundin <[email protected]>
1 parent 06b6f6b commit 465f7ec

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Run Tests Manually
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
branch:
7+
description: 'Branch to run the tests on'
8+
required: true
9+
default: 'main'
10+
number_of_runs:
11+
description: 'Number of runs for the script'
12+
required: true
13+
default: '10'
14+
gradle_task:
15+
description: 'Gradle task to execute'
16+
required: false
17+
default: 'testDebugUnitTest'
18+
19+
jobs:
20+
run-tests:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v4
25+
with:
26+
ref: ${{ github.event.inputs.branch }}
27+
28+
- name: Run the tests script
29+
run: |
30+
chmod +x ./run-tests.sh
31+
./run-tests.sh ${{ github.event.inputs.number_of_runs }} ${{ github.event.inputs.gradle_task }}

run-tests.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
3+
# Colors for output
4+
GREEN='\033[0;32m'
5+
RED='\033[0;31m'
6+
NC='\033[0m' # No Color
7+
8+
# Create output directory for reports
9+
OUTPUT_DIR="test-reports"
10+
rm -rf "$OUTPUT_DIR"
11+
mkdir -p "$OUTPUT_DIR"
12+
13+
# First arg is total runs
14+
if [ "$1" != "" ]; then
15+
total_runs=$1
16+
else
17+
total_runs=10
18+
fi
19+
20+
# Second arg is the gradle task to run
21+
if [ "$2" != "" ]; then
22+
gradle_task=$2
23+
else
24+
gradle_task="testDebugUnitTest"
25+
fi
26+
27+
success_count=0
28+
failure_count=0
29+
30+
echo "Running test $total_runs times with gradle task $gradle_task..."
31+
echo "------------------------"
32+
start_time=$(date +%s)
33+
34+
for ((i=1; i<=total_runs; i++)); do
35+
echo -n "Run #$i: "
36+
37+
# Run the specific test with correct flags
38+
touch "$OUTPUT_DIR/test-run-$i.txt"
39+
./gradlew $gradle_task --rerun-tasks --daemon > "$OUTPUT_DIR/test-run-$i.txt" 2>&1
40+
41+
if [ $? -eq 0 ]; then
42+
((success_count++))
43+
echo -e "${GREEN}PASSED${NC}"
44+
else
45+
((failure_count++))
46+
echo -e "${RED}FAILED${NC}"
47+
# Print the output of the test run
48+
echo "Output of test run $i:"
49+
cat "$OUTPUT_DIR/test-run-$i.txt"
50+
# Copy the HTML report with run number
51+
cp -R "./android/build/reports/tests/" "$OUTPUT_DIR/failure-run-$i/"
52+
fi
53+
done
54+
55+
echo "------------------------"
56+
echo "Execution time: $(($(date +%s) - start_time)) seconds"
57+
echo "Results:"
58+
echo "Total runs: $total_runs"
59+
echo -e "Successes: ${GREEN}$success_count${NC}"
60+
echo -e "Failures: ${RED}$failure_count${NC}"
61+
echo "Failure rate: $(( (failure_count * 100) / total_runs ))%"
62+
63+
if [ $failure_count -gt 0 ]; then
64+
echo "Failure reports saved in $OUTPUT_DIR/"
65+
fi

0 commit comments

Comments
 (0)