diff --git a/.github/workflows/macstadium-tests.yml b/.github/workflows/macstadium-tests.yml index 43b326c14b1..4748f7b8df8 100644 --- a/.github/workflows/macstadium-tests.yml +++ b/.github/workflows/macstadium-tests.yml @@ -166,7 +166,7 @@ jobs: yarn detox build --configuration ios.sim.release - name: Detox iOS e2e tests serial run: | - ./scripts/run-serial-e2e.sh + ./scripts/run-serial-e2e.sh 3 - name: Detox iOS e2e tests parallel run: | diff --git a/scripts/run-serial-e2e.sh b/scripts/run-serial-e2e.sh index 84bcbd3c85d..922729eaeaf 100755 --- a/scripts/run-serial-e2e.sh +++ b/scripts/run-serial-e2e.sh @@ -1,8 +1,7 @@ #!/bin/bash -set -e +MAX_RETRIES=${1:-3} # number of times that a test should be retried in case of failure. default to 3 if not specified +BUILD_TYPE=${2:-release} # can be "debug" or "release". default to "release" if not specified -# 0) Read build type from first argument; default to "release" if not specified -BUILD_TYPE=${1:-release} # can be "debug" or "release" # 0.1) Decide Detox config based on BUILD_TYPE if [ "$BUILD_TYPE" = "debug" ]; then @@ -11,41 +10,63 @@ else DETOX_CONFIG="ios.sim.release" fi +SUCCESS=false + # Loop through each file in the ./e2e/serial/ directory for test_file in ./e2e/serial/*.ts; do - echo "=====================================" - echo "Running test file: $test_file" - echo "=====================================" - - # 1) Start Anvil in the background (show logs in terminal + save to file) - yarn anvil 2>&1 | grep -v "eth_" | tee anvil.log & - ANVIL_PID=$! - - # 2) Wait for Anvil to initialize - sleep 5 - - # 3) Run Detox for this single file - ./node_modules/.bin/detox test "$test_file" -c "$DETOX_CONFIG" --maxWorkers 1 --R 3 - ret_val=$? - - # 4) Kill the Anvil process - echo "Killing Anvil (PID: $ANVIL_PID)" - kill "$ANVIL_PID" - # kill any other processes using port 8545 - kill $(lsof -t -i:8545) - - # 5) Remove the Anvil log file - rm -rf anvil.log - - # 6) Decide what to do if Detox failed or succeeded - if [ "$ret_val" -ne 0 ]; then - echo "❌ Tests failed for $test_file" - exit 1 # or break, depending on your preference - else - echo "✅ Tests passed for $test_file" - fi + COUNT=0 + until (( $COUNT >= MAX_RETRIES )) + do + echo "=====================================" + echo "Running test file: $test_file (attempt ${COUNT+1}/$MAX_RETRIES)" + echo "=====================================" + + echo "Starting anvil..." + # 1) Start Anvil in the background (show logs in terminal + save to file) + yarn anvil 2>&1 | grep -v "eth_" | tee anvil.log & + ANVIL_PID=$! + echo "Anvil started (PID: $ANVIL_PID)" + + # 2) Wait for Anvil to initialize + sleep 5 + + # 3) Run Detox for this single file with retries + ./node_modules/.bin/detox test "$test_file" -c "$DETOX_CONFIG" --maxWorkers 1 + ret_val=$? + + # 4) Kill the Anvil process + echo "Killing Anvil (PID: $ANVIL_PID)" + kill "$ANVIL_PID" 2>/dev/null || true + # kill any other processes using port 8545 + kill $(lsof -t -i:8545) 2>/dev/null || true + + # 5) Remove the Anvil log file + rm -rf anvil.log + + # 6) Decide what to do if Detox failed or succeeded + if [ $ret_val -eq 0 ]; then + echo "✅ Tests passed for $test_file" + SUCCESS=true + break + fi + ((COUNT++)) + echo "❌ Test failed, attempt $COUNT/$MAX_RETRIES..." + + if(($COUNT >= MAX_RETRIES)) + then + SUCCESS=false + fi + done + + if [ "$SUCCESS" = "false" ]; then + echo "❌ Tests failed after $MAX_RETRIES attempts. Bailing out!" + exit 1 + fi done echo "✅ All tests passed for every file!" exit 0 + + +