Check whether the infra dependencies are ready before E2E test (#870)

Fixes #848
This commit is contained in:
WangXiang 2021-06-03 07:56:44 +08:00 committed by GitHub
parent 567950d5f0
commit 06b2e564e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 0 deletions

58
.github/scripts/check-infra-dependencies.sh vendored Executable file
View File

@ -0,0 +1,58 @@
#!/usr/bin/env bash
set -eou pipefail
usage() {
echo "${0} <INFRA_NAME> 'CHECK WHETHER THE SPECIFIED INFRA DEPENDENCE IS READY"
}
if [ "$#" -ne 1 ] || [ -z "$1" ]; then
echo "Error: Missing the infra name which needs to check"
usage
exit 1
fi
# infra is one of 'mysql', 'redis', 'mailhog', 'saml_idp'.
# use 'all' to check all these infras.
INFRA_NAME=${1}
INFRAS=()
RETRYNUM=10
if [ "$INFRA_NAME" == "all" ]; then
INFRAS=("mysql" "redis" "mailhog" "saml_idp")
else
INFRAS=("$INFRA_NAME")
fi
checkInfraFun() {
INFRA=$1
echo "check whether the $INFRA is ready"
if [ "$INFRA" == "mysql" ]; then
! docker-compose exec -T mysql_test bash -c 'echo "SHOW DATABASES;" | mysql -uroot -ptoor' && return 1
echo "mysql is ready!"
elif [ "$INFRA" == "redis" ]; then
! docker-compose exec -T redis bash -c "redis-cli ping" && return 1
echo "redis is ready!"
elif [ "$INFRA" == "mailhog" ]; then
echo "TODO"
echo "mailhog is ready!"
elif [ "$INFRA" == "saml_idp" ]; then
echo "TODO"
echo "saml_idp is ready!"
fi
}
for INFRA in ${INFRAS[@]}; do
n=0
success=false
until [ "$n" -ge $RETRYNUM ]; do
checkInfraFun $INFRA && success=true && break
n=$((n+1))
sleep 1
done
if [ ! $success ]; then
exit 1
fi
done

View File

@ -66,6 +66,7 @@ jobs:
- name: Run E2E Tests - name: Run E2E Tests
run: | run: |
.github/scripts/check-infra-dependencies.sh all
make e2e-reset-db make e2e-reset-db
make e2e-serve & make e2e-serve &
sleep 3 sleep 3