From 8d7439435788318515b56eabb3c35e93ab0c812a Mon Sep 17 00:00:00 2001 From: daxpedda Date: Tue, 10 Dec 2024 21:50:38 +0100 Subject: [PATCH] Re-try to start WebDriver on failure --- .github/workflows/test.yaml | 51 +++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 03cb46f..47bbf6b 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -133,8 +133,55 @@ jobs: - name: Start and set WebDriver if: matrix.driver.browser == true run: | - ${{ matrix.driver.binary }} --port=9000 & - echo "${{ matrix.driver.env }}_REMOTE=http://127.0.0.1:9000" >> $GITHUB_ENV + iteration=5 + + while true; do + if (( iteration == 0 )); then + echo "CI: Failed to start driver." + exit 1 + fi + + (( iteration-- )) + + ${{ matrix.driver.binary }} --port=0 1>stdout 2>stderr & + process_pid=$! + + start_time=$(date +%s) + + while [[ $((( $(date +%s) - start_time ))) -lt 5 ]]; do + cat stdout + cat stderr + + if [[ $(wc -l < stderr) -gt 0 ]]; then + echo "CI: WebDriver failed" + kill -SIGKILL $process_pid || true + echo + + echo "CI: stdout:" + sed 's/^/CI: /' stdout + echo + echo "CI: stderr:" + sed 's/^/CI: /' stderr + echo + + echo "CI: Re-trying to start the WebDriver." + + break + fi + + if [[ $(wc -l < stdout) -gt 0 ]]; then + tail -f stdout >&1 & + tail -f stderr >&2 & + + port=$(lsof -p $process_pid -a -i4| tail -n +2 | awk '{print $9}' | cut -d: -f2) + echo "${{ matrix.driver.env }}_REMOTE=http://127.0.0.1:$port" >> $GITHUB_ENV + + break 2 + fi + + sleep 1 + done + done - name: Set environment if: matrix.environment.name != '' run: echo "${{ matrix.environment.name }}=1" >> $GITHUB_ENV