Skip to content

Commit aa24db0

Browse files
authored
VED-353: Wait for API to be available before running e2e tests. (#581)
1 parent 4c0d853 commit aa24db0

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

azure/templates/post-deploy.yml

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -80,38 +80,38 @@ steps:
8080
8181
- bash: |
8282
set -ex
83-
if ! [[ $APIGEE_ENVIRONMENT =~ .*-*sandbox ]]; then
84-
counter=0
85-
base_path="$SERVICE_BASE_PATH"
8683
87-
endpoint=""
84+
endpoint=""
85+
if [[ $APIGEE_ENVIRONMENT =~ "prod" ]]; then
86+
endpoint="https://api.service.nhs.uk/${SERVICE_BASE_PATH}/_status"
87+
else
88+
endpoint="https://${APIGEE_ENVIRONMENT}.api.service.nhs.uk/${SERVICE_BASE_PATH}/_status"
89+
fi
8890
89-
if [[ $APIGEE_ENVIRONMENT =~ "prod" ]]; then
90-
endpoint="https://api.service.nhs.uk/${base_path}/_status"
91+
counter=0
92+
while [[ $counter -lt 31 ]]; do
93+
response=$(curl -H "apikey: $(status-endpoint-api-key)" -s "$endpoint")
94+
response_code=$(jq -r '.checks.healthcheck.responseCode' <<< "$response")
95+
response_body=$(jq -r '.checks.healthcheck.outcome' <<< "$response")
96+
status=$(jq -r '.status' <<< "$response")
97+
if [ "$response_code" -eq 200 ] && [ "$response_body" == "OK" ] && [ "$status" == "pass" ]; then
98+
echo "Status test successful"
99+
break
91100
else
92-
endpoint="https://${APIGEE_ENVIRONMENT}.api.service.nhs.uk/${base_path}/_status"
101+
echo "Waiting for $endpoint to return a 200 response with 'OK' body..."
102+
((counter=counter+1)) # Increment counter by 1
103+
echo "Attempt $counter"
104+
sleep 30
93105
fi
106+
done
94107
95-
while [[ $counter -lt 11 ]]; do
96-
response=$(curl -H "apikey: $(status-endpoint-api-key)" -s "$endpoint")
97-
response_code=$(jq -r '.checks.healthcheck.responseCode' <<< "$response")
98-
response_body=$(jq -r '.checks.healthcheck.outcome' <<< "$response")
99-
if [ "$response_code" -eq 200 ] && [ "$response_body" == "OK" ]; then
100-
echo "Status test successful"
101-
break
102-
else
103-
echo "Waiting for $endpoint to return a 200 response with 'OK' body..."
104-
((counter=counter+1)) # Increment counter by 1
105-
echo "Attempt $counter"
106-
sleep 30
107-
fi
108-
done
109-
if [ $counter -eq 11 ]; then
110-
echo "Status test failed: Maximum number of attempts reached"
111-
exit 1
112-
fi
108+
if [ $counter -eq 31 ]; then
109+
echo "Status test failed: Maximum number of attempts reached"
110+
echo "Last response received:"
111+
echo "$response"
112+
exit 1
113113
fi
114-
displayName: Waiting for TF resources to be UP
114+
displayName: Wait for API to be available
115115
workingDirectory: "$(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)"
116116
117117
- bash: |
@@ -164,7 +164,7 @@ steps:
164164
export DEFAULT_CLIENT_SECRET="$(INT_CLIENT_SECRET)"
165165
echo "running: $test_cmd -v -c test_deployment.py test_proxy.py"
166166
$test_cmd -v -c test_deployment.py test_proxy.py
167-
167+
168168
elif [[ $APIGEE_ENVIRONMENT == "prod" ]]; then
169169
echo "Proxy test completed successfully as part of terraform resource up status check"
170170
@@ -175,35 +175,35 @@ steps:
175175
workingDirectory: "$(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)/e2e"
176176
displayName: Run Full Test Suite
177177
178-
178+
179179
180180
- bash: |
181181
set -e
182182
if ! [[ "$APIGEE_ENVIRONMENT" == "prod" || "$APIGEE_ENVIRONMENT" == "int" || "$APIGEE_ENVIRONMENT" == *"sandbox" ]]; then
183183
echo "Running E2E batch folder test cases"
184-
184+
185185
export AWS_PROFILE="apim-dev"
186186
aws_account_no="$(aws sts get-caller-identity --query Account --output text)"
187187
echo "Using AWS Account: $aws_account_no"
188-
188+
189189
service_name="${FULLY_QUALIFIED_SERVICE_NAME}"
190-
190+
191191
pr_no=$(echo "$service_name" | { grep -oE '[0-9]+$' || true; })
192192
if [ -z "$pr_no" ]; then
193193
workspace="$APIGEE_ENVIRONMENT"
194194
else
195195
workspace="pr-$pr_no"
196196
fi
197-
197+
198198
poetry install --no-root # Install dependencies defined in pyproject.toml
199-
199+
200200
ENV="$workspace" poetry run python -m unittest -v -c
201-
201+
202202
echo "E2E batch folder test cases executed successfully"
203203
else
204204
echo "Skipping E2E batch folder test cases as the environment is prod-int-sandbox"
205205
fi
206-
206+
207207
displayName: Run full batch test suite
208208
workingDirectory: "$(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)/e2e_batch"
209209
condition: eq(1, 2) # Disable task but make this step visible in the pipeline
@@ -213,4 +213,4 @@ steps:
213213
condition: always()
214214
inputs:
215215
testResultsFiles: '$(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)/tests/test-report.xml'
216-
failTaskOnFailedTests: true
216+
failTaskOnFailedTests: true

0 commit comments

Comments
 (0)