Testing and integration - kristianrpo/mom-grpc-microservices GitHub Wiki
1. Testing Scope
- Integration Testing:
- API Gateway β Microservices communication
- API Gateway β MOM (Redis) interaction
- Client β MOM β Microservices
- Functional Testing:
- Request processing workflows
- Failover mechanisms
- Task management operations
- Inmediate response
- Resilience Test:
- Handle timeout when service is unavailable
2. Prerequisites
- Python 3.8+
- Pytest 8.3.5
- Redis server running locally (port 6379)
- MOM server running locally (port 50051)
- API gateway running
2.1. Microservices Requirements
-
For API Gateway tests (
test_api_gateway.py
):
All microservices must be running or mocked externally. -
For Client tests (
test_multiplication.py
,test_sum.py
,test_subtraction.py
):
Microservices are launched and stopped automatically inside the tests.
3. Tests execution
From project root (mom-grpc-microservices/
):
3.1. Install dependencies
cd api_gateway
pip install -r requirements.txt
3.2. Run API Gateway tests
python -m pytest tests/test_api_gateway.py -v
3.3. Run Client β Microservices tests
3.3.1. Multiplication service tests
python -m pytest tests/test_multiplication.py -s
3.3.2. Sum service tests
python -m pytest tests/test_sum.py -s
3.3.3. Subtraction service tests
python -m pytest tests/test_subtraction.py -s
4. Implemented Tests
test_request_processing
)
4.1. Test: Request Processing (- Purpose: Verifies correct routing to microservices
- Success Criteria:
- HTTP status code 200
processed_immediately
= True- Response contains correct sum (15.0)
- Execution:
pytest tests/test_api_gateway.py::test_request_processing -v
test_failover_to_mom
)
4.2. Test: MOM Failover (- Purpose: Validates queueing mechanism when microservice fails
- Success Criteria:
- HTTP status code 200
- "queued" status in response
- Presence of task_id
- Execution:
pytest tests/test_api_gateway.py::test_failover_to_mom -v
test_task_retrieval
)
4.3. Test: Task Retrieval (- Purpose: Verifies task status query functionality
- Success Criteria:
- HTTP status code 200
- Response contains valid status
- Execution:
pytest tests/test_api_gateway.py::test_task_retrieval -v
test_inmediate_response
)
4.4. Test: Immediate Response Test (- Purpose: Verifies that the microservice returns an immediate response when already running.
- Scenario:
- The microservice is started manually by the test.
- A client request is submitted.
- The service responds instantly with a result.
- Success Criteria:
- Status:
COMPLETED
- Result: expected value (
product
,total
, ordifference
)
- Status:
- Used in:
test_multiplication.py
,test_sum.py
,test_subtraction.py
test_delayed_response_from_queue
)
4.5. Delayed Queue Response Test (- Purpose: Tests the system behavior when the microservice is initially down.
- Scenario:
- A request is submitted before the service is running.
- The request is enqueued via MOM.
- The microservice is started after a delay.
- The client receives the result after re-polling.
- Success Criteria:
- Status:
COMPLETED
- Correct result delivered after delay
- Status:
- Used in:
test_multiplication.py
,test_sum.py
,test_subtraction.py
test_timeout_when_service_never_starts
)
4.6. Timeout Handling Test (- Purpose: Ensures the client times out gracefully when no microservice ever responds.
- Scenario:
- A request is submitted.
- The microservice is never started.
- The client times out after a fixed duration.
- The test captures and inspects the clientβs output.
- Success Criteria:
- Output contains
"timeout reached"
- Output contains
- Used in:
test_multiplication.py
,test_sum.py
,test_subtraction.py
π Note: Tests from 4 to 6 automatically launch the actual microservice processes during execution and clean them up afterward.
You do not need to start any microservice manually for these tests.
5. Test Cases Results
5.1. API Gateway Tests
Test Case | Status | Description |
---|---|---|
test_request_processing |
β PASSED | Validates successful request processing |
test_failover_to_mom |
β PASSED | Verifies MOM failover mechanism |
test_task_retrieval |
β PASSED | Tests task status retrieval functionality |
Total Execution Time (API Gateway): 5.51 seconds
5.2. Sum Service Tests
Test Case | Status | Description |
---|---|---|
test_inmediate_response |
β PASSED | Returns result immediately if service is running |
test_delayed_response_from_queue |
β PASSED | Enqueues task, returns result after service starts |
test_timeout_when_service_never_starts |
β PASSED | Handles timeout when service never responds |
Total Execution Time (Sum): 51.51 seconds
5.3. Subtraction Service Tests
Test Case | Status | Description |
---|---|---|
test_inmediate_response |
β PASSED | Returns result immediately if service is running |
test_delayed_response_from_queue |
β PASSED | Enqueues task, returns result after service starts |
test_timeout_when_service_never_starts |
β PASSED | Handles timeout when service never responds |
Total Execution Time (Subtraction): 53.56 seconds
5.4. Multiplication Service Tests
Test Case | Status | Description |
---|---|---|
test_inmediate_response |
β PASSED | Returns result immediately if service is running |
test_delayed_response_from_queue |
β PASSED | Enqueues task, returns result after service starts |
test_timeout_when_service_never_starts |
β PASSED | Handles timeout when service never responds |
Total Execution Time (Multiplication): 51.47 seconds
5.5. Grand Total
Overall Execution Time (All Tests): 162.05 seconds