Skip to content

Commit 8a665b3

Browse files
authored
run integration tests for CDK (#31)
* run integration tests for CDK * add deps * set env vars * add sender email * fix state machine issue * apply the hack * try fixing again * retry * remove parts * try to get tests passing
1 parent 0cdcd05 commit 8a665b3

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

.github/workflows/cdk.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,19 @@ jobs:
6868
awslocal dynamodb list-tables
6969
awslocal s3 ls
7070
71+
- name: Set up test dependencies
72+
run: |
73+
pip install requests boto3 pytest localstack-sdk-python
74+
75+
- name: Run Integration Tests
76+
env:
77+
AWS_DEFAULT_REGION: us-east-1
78+
AWS_REGION: us-east-1
79+
AWS_ACCESS_KEY_ID: test
80+
AWS_SECRET_ACCESS_KEY: test
81+
run: |
82+
pytest tests/test_infra.py
83+
7184
- name: Send a Slack notification
7285
if: failure() || github.event_name != 'pull_request'
7386
uses: ravsamhq/notify-slack-action@v2

cdk/quiz_app/quiz_app_stack.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
158158
self.backend_api_url = rest_api.url
159159

160160
# verify email identity for SES
161-
161+
162162
sanitised_email = email.replace(".", "-").replace("@", "-")
163163
cr.AwsCustomResource(
164164
self,
@@ -262,6 +262,7 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
262262
"../configurations/statemachine.json"
263263
),
264264
role=state_machine_role,
265+
state_machine_name="SendEmailStateMachine"
265266
)
266267

267268
# set up lambda permissions

tests/test_infra.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,26 @@ def test_quiz_workflow(api_endpoint):
156156

157157
time.sleep(5)
158158

159-
response = requests.get(f"{api_endpoint}/getleaderboard?quiz_id={quiz_id}&top=3")
160-
assert response.status_code == 200
161-
leaderboard = response.json()
162-
assert len(leaderboard) == 3
159+
leaderboard_url = f"{api_endpoint}/getleaderboard?quiz_id={quiz_id}&top=3"
160+
response = requests.get(leaderboard_url)
161+
leaderboard = None
163162

163+
if response.json():
164+
assert response.status_code == 200
165+
leaderboard = response.json()
166+
else:
167+
# If the response is empty, retry it for 5 times with a 2 second delay.
168+
# TODO: This is a hack to get around the fact that the leaderboard is not available immediately.
169+
for _ in range(5):
170+
time.sleep(2)
171+
response = requests.get(leaderboard_url)
172+
if response.json():
173+
assert response.status_code == 200
174+
leaderboard = response.json()
175+
break
176+
177+
assert leaderboard is not None, "Failed to retrieve leaderboard data after retries"
178+
assert len(leaderboard) == 3
164179
expected_scores = {
165180
"user1": None,
166181
"user2": None,

0 commit comments

Comments
 (0)