From 02281281a80f42b9aa3fa498114ff0d35cb81379 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Tue, 17 Mar 2020 11:31:00 -0500 Subject: [PATCH] build: watch for sauce service failures when waiting for it to start (#36109) Also add two targets to make it more convienent to tail & dump the sauce service logs: //tools/saucelabs:sauce_service_tail & //tools/saucelabs:sauce_service_log PR Close #36109 --- tools/saucelabs/BUILD.bazel | 14 ++++++++++++ tools/saucelabs/README.md | 10 ++++++++- tools/saucelabs/sauce-service.sh | 38 ++++++++++++++++++++++++++++---- 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/tools/saucelabs/BUILD.bazel b/tools/saucelabs/BUILD.bazel index 5cfca5be42..da7dd957b5 100644 --- a/tools/saucelabs/BUILD.bazel +++ b/tools/saucelabs/BUILD.bazel @@ -37,6 +37,20 @@ sh_binary( data = ["@npm//sauce-connect"], ) +sh_binary( + name = "sauce_service_tail", + srcs = ["sauce-service.sh"], + args = ["tail"], + data = ["@npm//sauce-connect"], +) + +sh_binary( + name = "sauce_service_log", + srcs = ["sauce-service.sh"], + args = ["log"], + data = ["@npm//sauce-connect"], +) + nodejs_binary( name = "karma-saucelabs", data = [ diff --git a/tools/saucelabs/README.md b/tools/saucelabs/README.md index f3ec9cf586..25fdda31c6 100644 --- a/tools/saucelabs/README.md +++ b/tools/saucelabs/README.md @@ -27,11 +27,19 @@ yarn bazel run //tools/saucelabs:sauce_service_setup For example, `packages/core/test:test_web` becomes `packages/core/test:saucelabs_test_web`. ``` -yarn bazel test //path/to/target:saucelabs_target1 --config=saucelabs --config=ivy +yarn bazel test //packages/core/test:saucelabs_test_web --config=saucelabs --config=ivy ``` Remove the `--config=ivy` if you want to run through View Engine instead. +5. Sauce service log may be tailed or dumped with the following targets: + +``` bash +yarn bazel run //tools/saucelabs:sauce_service_tail +yarn bazel run //tools/saucelabs:sauce_service_log +``` + + ## Additional test features To see the test output while the tests are running (as these are long tests), add the `--test_output=streamed` option. diff --git a/tools/saucelabs/sauce-service.sh b/tools/saucelabs/sauce-service.sh index 9f70183be7..3bb2058ba5 100755 --- a/tools/saucelabs/sauce-service.sh +++ b/tools/saucelabs/sauce-service.sh @@ -191,16 +191,32 @@ service-pre-start() { # Called after service is started service-post-start() { - @wait_for "Waiting for Sauce Connect Proxy process" "${SAUCE_PID_FILE}" + if [[ ! -f "${SAUCE_PID_FILE}" ]]; then + printf "# Waiting for Sauce Connect Proxy process (${SAUCE_PID_FILE})" + while [[ ! -f "${SAUCE_PID_FILE}" ]]; do + if ! @serviceStatus >/dev/null 2>&1; then + printf "\n" + @serviceStop + @echo "Service failed to start!" + service-failed-setup + exit 1 + fi + printf "." + sleep 0.5 + done + printf "\n" + fi @echo "Sauce Connect Proxy started (pid $(cat "${SAUCE_PID_FILE}"))" } # Called if service fails to start service-failed-setup() { if [[ -f "${SERVICE_LOG_FILE}" ]]; then - echo "================================================================================" - echo "${SERVICE_LOG_FILE}:" - echo $(cat "${SERVICE_LOG_FILE}") + @echo "tail ${SERVICE_LOG_FILE}:" + echo "--------------------------------------------------------------------------------" + tail "${SERVICE_LOG_FILE}" + echo "--------------------------------------------------------------------------------" + echo "^^^^^ ${SERVICE_LOG_FILE} ^^^^^" fi } @@ -359,6 +375,8 @@ service-post-stop() { return 0 else @warn "Service is not running" + @remove "${SERVICE_PID_FILE}" + @remove "${SERVICE_START_FILE}" service-post-stop fi } @@ -378,9 +396,18 @@ service-post-stop() { } @serviceTail() { + @echo "tail ${SERVICE_LOG_FILE}:" tail -f "${SERVICE_LOG_FILE}" } +@serviceLog() { + @echo "cat ${SERVICE_LOG_FILE}:" + echo "--------------------------------------------------------------------------------" + cat "${SERVICE_LOG_FILE}" + echo "--------------------------------------------------------------------------------" + echo "^^^^^ ${SERVICE_LOG_FILE} ^^^^^" +} + case "${1:-}" in setup) @serviceLock @@ -419,6 +446,9 @@ case "${1:-}" in ${SERVICE_COMMAND} ) ;; + log) + @serviceLog + ;; tail) @serviceTail ;;