attempt to wait for backend and frontend to be up w/ burnettk

This commit is contained in:
jasquat 2022-06-17 10:35:38 -04:00
parent edf6293d33
commit 5d2ffa3111
3 changed files with 44 additions and 3 deletions

View File

@ -51,9 +51,26 @@ jobs:
- name: start_frontend
working-directory: ./spiffworkflow-frontend
run: ./bin/build_and_run_with_docker_compose
# Install NPM dependencies, cache them correctly
# and run all Cypress tests
- name: wait_for_backend
working-directory: ./spiffworkflow-backend
run: ./bin/wait_for_server_to_be_up 5
- name: wait_for_frontend
working-directory: ./spiffworkflow-frontend
run: ./bin/wait_for_frontend_to_be_up 5
- name: Cypress run
uses: cypress-io/github-action@v4
with:
working-directory: ./spiffworkflow-frontend
# https://github.com/cypress-io/github-action#artifacts
- uses: actions/upload-artifact@v2
if: failure()
with:
name: cypress-screenshots
path: ./spiffworkflow-frontend/cypress/screenshots
# Test run video was always captured, so this action uses "always()" condition
- uses: actions/upload-artifact@v2
if: always()
with:
name: cypress-videos
path: ./spiffworkflow-frontend/cypress/videos

24
bin/wait_for_frontend_to_be_up Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env bash
function error_handler() {
>&2 echo "Exited with BAD EXIT CODE '${2}' in ${0} script at line: ${1}."
exit "$2"
}
trap 'error_handler ${LINENO} $?' ERR
set -o errtrace -o errexit -o nounset -o pipefail
max_attempts="${1:-}"
if [[ -z "$max_attempts" ]]; then
max_attempts=100
fi
echo "waiting for backend to come up..."
attempts=0
while [[ "$(curl -s -o /dev/null -w '%{http_code}' http://localhost:7001)" != "200" ]]; do
if [[ "$attempts" -gt "$max_attempts" ]]; then
>&2 echo "ERROR: Server not up after $max_attempts attempts. There is probably a problem"
exit 1
fi
attempts=$(( attempts + 1 ))
sleep 1
done

View File

@ -30,7 +30,7 @@
"scripts": {
"start": "PORT=7001 craco start",
"build": "craco build",
"test": "craco test",
"test": "react-scripts test",
"eject": "craco eject"
},
"eslintConfig": {