Skip to content

Commit

Permalink
retry per file so we can handle anvil separately
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobar79 committed Dec 21, 2024
1 parent 1815417 commit ccb5b3f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/macstadium-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
89 changes: 55 additions & 34 deletions scripts/run-serial-e2e.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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



0 comments on commit ccb5b3f

Please sign in to comment.