Skip to content

Commit 62ffc51

Browse files
committed
Quick fix for batch e2e tests
1 parent d0cfed8 commit 62ffc51

File tree

6 files changed

+30
-27
lines changed

6 files changed

+30
-27
lines changed

tests/e2e_batch/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-include .env
2-
31
test:
4-
ENVIRONMENT=$(ENVIRONMENT) poetry run python -m unittest -v -c
2+
poetry run python -m unittest -v -c
3+
4+
.PHONY: test

tests/e2e_batch/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ This test suite provides automated end-to-end (E2E) testing for the Immunisation
88
- Purpose: Simulate real-world batch file submissions, poll for acknowledgements, and validate processing results.
99
- Test Scenarios: Defined in the scenarios module and enabled in setUp().
1010
- Key Features:
11-
- - Uploads test batch files to S3.
12-
- - Waits for and validates ACK (acknowledgement) files.
13-
- - Cleans up SQS queues and test artifacts after each run.
11+
- Uploads test batch files to S3.
12+
- Waits for and validates ACK (acknowledgement) files.
13+
- Cleans up SQS queues and test artifacts after each run.
1414

1515
## Test Flow
1616

@@ -39,7 +39,7 @@ This test suite provides automated end-to-end (E2E) testing for the Immunisation
3939

4040
1. Ensure all dependencies and environment variables are set (see project root README).
4141
2. Update `.env` file with contents indicated in `PR-NNN.env`, modified for PR
42-
3. Update `.env` with referrence to the appropriate AWS config profile `AWS_PROFILE={your-aws-profile}`
42+
3. Update `.env` with reference to the appropriate AWS config profile `AWS_PROFILE={your-aws-profile}`
4343
4. Update the apigee app to match the required PR-NNN
4444
5. Run tests from vscode debugger or from makefile using
4545

tests/e2e_batch/pr-NNN.env

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,2 @@
11
ENVIRONMENT=pr-NNN
2-
REGION=eu-west-2
3-
PROXY_NAME=immunisation-fhir-api-pr-NNN
4-
APIGEE_ENVIRONMENT=internal-dev
5-
SERVICE_BASE_PATH=immunisation-fhir-api-pr-NNN
6-
AUDIT_TABLE_NAME=immunisation-batch-pr-NNN-audit-table
7-
PR_NUMBER=NNN
8-
9-
AWS_PROFILE={your-aws-profile}
2+
AWS_PROFILE={your-aws-profile}

tests/e2e_batch/scenarios.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class TestCase:
4242
def __init__(self, scenario: dict):
4343
self.name: str = scenario.get("name", "Unnamed Test Case")
4444
self.description: str = scenario.get("description", "")
45+
self.is_failure_scenario = scenario.get("is_failure_scenario", False)
4546
self.ods_vax: OdsVax = scenario.get("ods_vax")
4647
self.actions: list[TestAction] = scenario.get("actions", [])
4748
self.ods = self.ods_vax.ods_code
@@ -207,6 +208,7 @@ def generate_csv_files(test_cases: list[TestCase]) -> list[TestCase]:
207208
expected_operation_outcome=OperationOutcome.IMMS_NOT_FOUND,
208209
)
209210
],
211+
"is_failure_scenario": True,
210212
"operation_outcome": ActionFlag.NONE,
211213
},
212214
{
@@ -220,6 +222,7 @@ def generate_csv_files(test_cases: list[TestCase]) -> list[TestCase]:
220222
expected_operation_outcome=OperationOutcome.IMMS_NOT_FOUND,
221223
)
222224
],
225+
"is_failure_scenario": True,
223226
"operation_outcome": ActionFlag.NONE,
224227
},
225228
{

tests/e2e_batch/test_e2e_batch.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
)
2929

3030

31+
# For consideration - these tests are suboptimal and difficult to read and extend. Consider integrating the automation
32+
# test repo into this one in future (it currently lives elsewhere but uses a nice readable framework to drive the tests)
3133
class TestE2EBatch(unittest.TestCase):
3234
def setUp(self):
3335
self.tests: list[TestCase] = create_test_cases(scenarios["dev"])
@@ -97,27 +99,28 @@ def poll_for_responses(tests: list[TestCase], max_timeout=1200) -> bool:
9799

98100
def validate_responses(tests: list[TestCase]):
99101
start_time = time.time()
100-
count = 0
101-
expected_count = len(tests) * 2
102+
current_ack_file_count = 0
103+
104+
# We expect an INF Ack (high-level i.e. file accepted or not) and a BUS Ack (containing all failure rows) for each
105+
# batch file
106+
expected_ack_file_count = len(tests) * 2
102107
errors = False
103108
try:
104109
for test in tests:
105110
logger.info(f"Validation for Test: {test.name} ")
106111
# Validate the ACK file
107112
if test.ack_keys[DestinationType.INF]:
108-
count += 1
113+
current_ack_file_count += 1
109114
inf_ack_content = get_file_content_from_s3(ACK_BUCKET, test.ack_keys[DestinationType.INF])
110115
check_ack_file_content(test.name, inf_ack_content, "Success", None, test.operation_outcome)
111116
else:
112117
logger.error(f"INF ACK file not found for test: {test.name}")
113118
errors = True
114119

115120
if test.ack_keys[DestinationType.BUS]:
116-
count += 1
121+
current_ack_file_count += 1
117122
validate_row_count(
118-
f"{test.name} - bus",
119-
test.file_name,
120-
test.ack_keys[DestinationType.BUS],
123+
f"{test.name} - bus", test.file_name, test.ack_keys[DestinationType.BUS], test.is_failure_scenario
121124
)
122125

123126
test.check_bus_file_content()
@@ -131,10 +134,12 @@ def validate_responses(tests: list[TestCase]):
131134
logger.error(f"Error during validation: {e}")
132135
errors = True
133136
finally:
134-
if count == expected_count:
137+
if current_ack_file_count == expected_ack_file_count:
135138
logger.info("All responses subject to validation.")
136139
else:
137-
logger.error(f"{count} of {expected_count} responses subject to validation.")
140+
logger.error(f"{current_ack_file_count} of {expected_ack_file_count} responses subject to validation.")
138141
logger.info(f"Time: {time.time() - start_time:.1f} seconds")
139-
assert count == expected_count, f"Only {count} of {expected_count} responses subject to validation."
142+
assert current_ack_file_count == expected_ack_file_count, (
143+
f"Only {current_ack_file_count} of {expected_ack_file_count} responses subject to validation."
144+
)
140145
assert not errors, "Errors found during validation."

tests/e2e_batch/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,14 +307,16 @@ def fetch_pk_and_operation_from_dynamodb(identifier_pk):
307307
return "ERROR"
308308

309309

310-
def validate_row_count(desc, source_file_name, ack_file_name):
310+
def validate_row_count(desc: str, source_file_name: str, ack_file_name: str, is_failure_scenario: bool) -> None:
311311
"""
312312
Compare the row count of a file in one S3 bucket with a file in another S3 bucket.
313313
Raises:
314314
AssertionError: If the row counts do not match.
315315
"""
316-
source_file_row_count = fetch_row_count(SOURCE_BUCKET, f"archive/{source_file_name}")
316+
# The BUS Ack will only add failed rows to the final file.
317+
source_file_row_count = fetch_row_count(SOURCE_BUCKET, f"archive/{source_file_name}") if is_failure_scenario else 1
317318
ack_file_row_count = fetch_row_count(ACK_BUCKET, ack_file_name)
319+
318320
assert source_file_row_count == ack_file_row_count, (
319321
f"{desc}. Row count mismatch: Input ({source_file_row_count}) vs Ack ({ack_file_row_count})"
320322
)

0 commit comments

Comments
 (0)