2024-12-13 20:45:41 +01:00
|
|
|
#!/bin/bash
|
2025-01-15 12:09:59 +01:00
|
|
|
export DESKTOP_FORCE_MOBILE="Y"
|
2024-12-13 20:45:41 +01:00
|
|
|
|
|
|
|
declare -a targets
|
|
|
|
declare -a passed_tests
|
|
|
|
declare -a failed_tests
|
|
|
|
|
2025-01-17 14:19:04 +01:00
|
|
|
# Max inactivity duration in seconds before marking the test as failed
|
|
|
|
MAX_INACTIVITY=180 # Adjust as needed (e.g., 300 seconds = 5 minutes)
|
|
|
|
|
|
|
|
# Function to monitor test output and kill the process if inactive
|
|
|
|
monitor_test() {
|
|
|
|
local test_pid=$1
|
|
|
|
local log_file=$2
|
|
|
|
local start_time=$(date +%s)
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
sleep 10
|
|
|
|
|
|
|
|
# Check if the process is still running
|
|
|
|
if ! kill -0 $test_pid 2>/dev/null; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
2025-04-09 20:02:57 +01:00
|
|
|
# Check for log activity: use OS-specific flag for stat command
|
|
|
|
if [[ "$(uname)" == "Darwin" ]]; then
|
|
|
|
last_modified=$(stat -f %m "$log_file")
|
|
|
|
else
|
|
|
|
last_modified=$(stat -c %Y "$log_file")
|
|
|
|
fi
|
|
|
|
|
2025-01-17 14:19:04 +01:00
|
|
|
local current_time=$(date +%s)
|
|
|
|
if (( current_time - last_modified > MAX_INACTIVITY )); then
|
|
|
|
echo "❌ Test hung due to inactivity, terminating..."
|
|
|
|
kill -9 $test_pid
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2025-04-09 20:02:57 +01:00
|
|
|
|
2024-12-13 20:45:41 +01:00
|
|
|
# Collect all Dart test files in the integration_test directory
|
|
|
|
while IFS= read -r -d $'\0' file; do
|
|
|
|
targets+=("$file")
|
|
|
|
done < <(find integration_test/test_suites -name "*.dart" -type f -print0)
|
|
|
|
|
|
|
|
# Run each test and collect results
|
|
|
|
for target in "${targets[@]}"
|
|
|
|
do
|
2025-01-17 14:19:04 +01:00
|
|
|
if [[ "x$REMOVE_DATA_DIRECTORY" == "xY" ]]; then
|
2025-01-15 12:09:59 +01:00
|
|
|
rm -rf ~/.local/share/com.example.cake_wallet ~/Documents/cake_wallet
|
|
|
|
fi
|
2024-12-13 20:45:41 +01:00
|
|
|
echo "Running test: $target"
|
2025-01-17 14:19:04 +01:00
|
|
|
|
|
|
|
# Temporary log file to track activity
|
|
|
|
log_file=$(mktemp)
|
|
|
|
|
|
|
|
# Run the test in the background and log output
|
|
|
|
flutter drive \
|
|
|
|
--driver=test_driver/integration_test.dart \
|
2025-02-11 20:37:15 +01:00
|
|
|
--target="$target" \
|
|
|
|
--dart-define=CI_BUILD=true \
|
|
|
|
>"$log_file" 2>&1 &
|
2025-01-17 14:19:04 +01:00
|
|
|
test_pid=$!
|
|
|
|
|
|
|
|
# Monitor the test for inactivity
|
|
|
|
if monitor_test $test_pid "$log_file"; then
|
2024-12-13 20:45:41 +01:00
|
|
|
echo "✅ Test passed: $target"
|
|
|
|
passed_tests+=("$target")
|
|
|
|
else
|
2025-01-17 14:19:04 +01:00
|
|
|
echo "❌ Test failed or hung: $target"
|
2024-12-13 20:45:41 +01:00
|
|
|
failed_tests+=("$target")
|
|
|
|
fi
|
2025-01-17 14:19:04 +01:00
|
|
|
|
|
|
|
# Clean up log file
|
|
|
|
rm -f "$log_file"
|
2024-12-13 20:45:41 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
# Provide a summary of test results
|
|
|
|
echo -e "\n===== Test Summary ====="
|
|
|
|
if [ ${#passed_tests[@]} -gt 0 ]; then
|
|
|
|
echo "✅ Passed Tests:"
|
|
|
|
for test in "${passed_tests[@]}"; do
|
|
|
|
echo " - $test"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ${#failed_tests[@]} -gt 0 ]; then
|
|
|
|
echo -e "\n❌ Failed Tests:"
|
|
|
|
for test in "${failed_tests[@]}"; do
|
|
|
|
echo " - $test"
|
|
|
|
done
|
|
|
|
# Exit with a non-zero status to indicate failure
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo -e "\n🎉 All tests passed successfully!"
|
|
|
|
fi
|