Skip to content

Commit 16a8775

Browse files
devversionandrewseguin
authored andcommitted
build: properly wait for external browser tunnels to terminate
We currently wait for browser tunnels of Saucelabs and Browserstack to terminate by repeatedly checking with `ps -p`. This is not reliable and can break if the host system is not removing forcibly killed child processes from the process table. This is valid since the tunnels are launched as child processes and we ideally wait for those to terminate using the `wait` command.
1 parent 05aead6 commit 16a8775

File tree

6 files changed

+19
-16
lines changed

6 files changed

+19
-16
lines changed

scripts/browserstack/start-tunnel.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,7 @@ browserstack-tunnel/BrowserStackLocal -k ${BROWSER_STACK_ACCESS_KEY} ${ARGS} 2>&
6868

6969
# Wait for the tunnel to be ready and create the readyfile with the Browserstack PID
7070
create_ready_file ${!} &
71+
72+
# Wait for all sub processes to finish. This ensures that no zombie
73+
# processes are left over.
74+
wait

scripts/browserstack/stop-tunnel.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,5 @@ tunnelProcessId=$(cat ${tunnelReadyFile})
1919
# we cannot use killall because CircleCI base container images don't have it installed.
2020
kill ${tunnelProcessId}
2121

22-
while (ps -p ${tunnelProcessId} &> /dev/null); do
23-
printf "."
24-
sleep .5
25-
done
26-
2722
echo ""
28-
echo "Browserstack tunnel has been shut down"
23+
echo "Browserstack tunnel interrupt signal has been sent."

scripts/circleci/run-browserstack-tests.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
# proper exit code.
55
set -e
66

7+
# Path to the project directory.
8+
projectDir="$(dirname ${0})/../.."
9+
710
# Go to project directory.
8-
cd $(dirname ${0})/../..
11+
cd ${projectDir}
912

1013
# Decode access token and make it accessible for child processes.
1114
export BROWSER_STACK_ACCESS_KEY=`echo ${BROWSER_STACK_ACCESS_KEY} | rev`
1215

1316
# Start tunnel and wait for it being ready.
14-
./scripts/browserstack/start-tunnel.sh
17+
./scripts/browserstack/start-tunnel.sh &
1518
./scripts/browserstack/wait-tunnel.sh
1619

1720
# Setup the test platform environment variable that will be read
@@ -24,3 +27,6 @@ yarn gulp ci:test
2427
# Kill the Browserstack tunnel. This is necessary in order to avoid rate-limit
2528
# errors that cause the unit tests to be flaky.
2629
./scripts/browserstack/stop-tunnel.sh
30+
31+
# Wait for all sub processes to terminate properly.
32+
wait

scripts/circleci/run-saucelabs-tests.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ cd $(dirname ${0})/../..
1111
export SAUCE_ACCESS_KEY=`echo ${SAUCE_ACCESS_KEY} | rev`
1212

1313
# Start tunnel and wait for it being ready.
14-
./scripts/saucelabs/start-tunnel.sh
14+
./scripts/saucelabs/start-tunnel.sh &
1515
./scripts/saucelabs/wait-tunnel.sh
1616

1717
# Setup the test platform environment variable that will be read
@@ -24,3 +24,6 @@ yarn gulp ci:test
2424
# Kill the Saucelabs tunnel. This is necessary in order to avoid rate-limit
2525
# errors that cause the unit tests to be flaky.
2626
./scripts/saucelabs/stop-tunnel.sh
27+
28+
# Wait for all sub processes to terminate properly.
29+
wait

scripts/saucelabs/start-tunnel.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ fi
3535

3636
echo "Starting Sauce Connect in the background. Passed arguments: ${sauceArgs}"
3737

38-
sauce-connect/bin/sc -u ${SAUCE_USERNAME} -k ${SAUCE_ACCESS_KEY} ${sauceArgs} &
38+
sauce-connect/bin/sc -u ${SAUCE_USERNAME} -k ${SAUCE_ACCESS_KEY} ${sauceArgs}

scripts/saucelabs/stop-tunnel.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,5 @@ tunnelProcessId=$(cat ${tunnelPidFile})
1919
# we cannot use killall because CircleCI base container images don't have it installed.
2020
kill ${tunnelProcessId}
2121

22-
while (ps -p ${tunnelProcessId} &> /dev/null); do
23-
printf "."
24-
sleep .5
25-
done
26-
2722
echo ""
28-
echo "Sauce Connect tunnel has been shut down"
23+
echo "Sauce Connect tunnel interrupt signal has been sent."

0 commit comments

Comments
 (0)