Skip to content

Commit 6c96c6d

Browse files
committed
VED-812: Wait for API to be available before running tests.
1 parent 443aaf9 commit 6c96c6d

File tree

1 file changed

+49
-11
lines changed

1 file changed

+49
-11
lines changed

.github/workflows/run-e2e-tests.yml

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,59 @@ env:
3737
APIGEE_ENVIRONMENT: ${{ inputs.apigee_environment }}
3838
ENVIRONMENT: ${{ inputs.environment }}
3939
SUB_ENVIRONMENT: ${{ inputs.sub_environment }}
40+
# TODO - handle PR deployments
41+
SERVICE_BASE_PATH: "immunisation-fhir-api/FHIR/R4"
42+
STATUS_API_KEY: ${{ secrets.STATUS_API_KEY }}
4043

4144
permissions:
4245
id-token: write
4346
contents: read
4447

4548
jobs:
49+
wait-for-deployment:
50+
runs-on: ubuntu-latest
51+
environment: ${{ inputs.environment }}
52+
steps:
53+
- name: Wait for API to be available
54+
run: |
55+
set -ex
56+
57+
endpoint=""
58+
if [[ $APIGEE_ENVIRONMENT =~ "prod" ]]; then
59+
endpoint="https://api.service.nhs.uk/${SERVICE_BASE_PATH}/_status"
60+
else
61+
endpoint="https://${APIGEE_ENVIRONMENT}.api.service.nhs.uk/${SERVICE_BASE_PATH}/_status"
62+
fi
63+
64+
counter=0
65+
while [[ $counter -lt 31 ]]; do
66+
response=$(curl -H "apikey: ${STATUS_API_KEY}" -s "$endpoint")
67+
response_code=$(jq -r '.checks.healthcheck.responseCode' <<< "$response")
68+
response_body=$(jq -r '.checks.healthcheck.outcome' <<< "$response")
69+
status=$(jq -r '.status' <<< "$response")
70+
if [ "$response_code" -eq 200 ] && [ "$response_body" == "OK" ] && [ "$status" == "pass" ]; then
71+
echo "Status test successful"
72+
break
73+
else
74+
echo "Waiting for $endpoint to return a 200 response with 'OK' body..."
75+
((counter=counter+1)) # Increment counter by 1
76+
echo "Attempt $counter"
77+
sleep 30
78+
fi
79+
done
80+
81+
if [ $counter -eq 31 ]; then
82+
echo "Status test failed: Maximum number of attempts reached"
83+
echo "Last response received:"
84+
echo "$response"
85+
exit 1
86+
fi
87+
4688
e2e-tests:
4789
runs-on: ubuntu-latest
48-
environment:
49-
name: ${{ inputs.environment }}
50-
env: # Sonarcloud - do not allow direct usage of untrusted data
90+
needs: [wait-for-deployment]
91+
environment: ${{ inputs.environment }}
92+
env:
5193
APIGEE_USERNAME: ${{ vars.APIGEE_USERNAME }}
5294
steps:
5395
- name: Connect to AWS
@@ -118,20 +160,16 @@ jobs:
118160
working-directory: e2e
119161
env:
120162
SOURCE_COMMIT_ID: ${{ github.sha }}
121-
# STATUS_API_KEY: ${{ secrets.STATUS_API_KEY }}
122-
run: |
123163
# TODO - handle PR deployments
124-
export SERVICE_BASE_PATH=immunisation-fhir-api/FHIR/R4
125-
export PROXY_NAME=immunisation-fhir-api-internal-dev
126-
164+
PROXY_NAME: "immunisation-fhir-api-internal-dev"
165+
run: |
127166
poetry run python -m unittest -c -v
128167
129168
batch-e2e-tests:
130169
needs: [e2e-tests]
131-
if: ${{ always() }}
170+
if: ${{ !cancelled() and jobs.wait-for-deployment.result == 'success' }}
132171
runs-on: ubuntu-latest
133-
environment:
134-
name: ${{ inputs.environment }}
172+
environment: ${{ inputs.environment }}
135173
steps:
136174
- name: Connect to AWS
137175
uses: aws-actions/configure-aws-credentials@a03048d87541d1d9fcf2ecf528a4a65ba9bd7838

0 commit comments

Comments
 (0)