Testing Guide
This guide provides comprehensive testing scenarios for the microservices coordination patterns demonstrated in Chapter 3.
🚀 Quick Start Testing
# One-command setup with all services
curl -fsSL https://raw.githubusercontent.com/your-repo/chapter-3/setup.sh | bash
cd microservices-demo
docker-compose up -d
# Run quick test
./bin/test-registration🧪 Test Scenarios
1. Happy Path - Full Registration Success
Test: All services respond successfully
# Create a new user registration
curl -X POST http://localhost:3000/api/register \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"name": "Sarah Chen",
"plan": "pro",
"phone": "+1-555-0123"
}'
# Expected: Task completes with all steps successful
# Response includes task_id for monitoringWhat to verify:
User created in UserService (port 3001)
Billing profile created in BillingService (port 3002)
Preferences initialized in PreferencesService (port 3003)
Welcome email queued in NotificationService (port 3004)
All steps show "complete" status
2. Service Timeout - Billing Service Slow
Test: Billing service responds slowly, triggering timeout
What to verify:
Initial billing step times out after 30 seconds
Step enters retry with exponential backoff
Other parallel steps (preferences) complete normally
Eventually succeeds after billing service recovers
3. Circuit Breaker - Service Completely Down
Test: User service fails repeatedly, opening circuit breaker
What to verify:
First 5 attempts fail with connection errors
6th attempt fails immediately with "Circuit breaker OPEN"
No additional calls made to user service
Circuit breaker reopens after 60 seconds
4. Idempotency - Duplicate Registration
Test: Same user registered twice
What to verify:
Second registration completes successfully
User creation step shows "already_exists" status
No duplicate billing profiles created
Both tasks complete without errors
5. Partial Failure Recovery - Preferences Service Error
Test: Preferences service returns 500 error intermittently
What to verify:
Preferences step fails initially
Automatic retry with backoff
Other steps continue independently
Eventually succeeds within retry limit
6. Rate Limiting - Notification Service
Test: Notification service enforces rate limits
What to verify:
First few notification steps succeed
Later ones get 429 Rate Limited response
Steps respect Retry-After header
Backoff prevents thundering herd
7. Service Degradation - Free Plan Resilience
Test: Billing service down but free users continue
What to verify:
Free user registration completes with degraded billing
Paid user registration retries and eventually fails
Graceful degradation for non-critical services
8. Correlation Tracking - Distributed Debugging
Test: Track request across all services
What to verify:
Correlation ID appears in all service logs
Can trace entire request flow
Service timings are recorded
Easy to identify failure points
9. Parallel Execution - Performance Testing
Test: Verify parallel steps execute simultaneously
What to verify:
Total time ~5-6 seconds (not 10+)
Billing and preferences run in parallel
Step timings show overlap
Parallel savings recorded in annotations
10. Peak Hours Simulation - Adaptive Timeouts
Test: System adapts during high load
What to verify:
Timeouts increase during peak hours
Backoff periods extended
System remains stable under load
Gradual recovery after peak
🔍 Monitoring and Debugging
Check Service Health
View Distributed Traces
Database Inspection
🐛 Common Issues and Solutions
"Circuit breaker is OPEN"
Problem: Service has failed too many times Solution:
Wait for recovery timeout (60 seconds)
Check service health:
docker-compose psReset circuit breaker:
curl -X POST http://localhost:3000/api/circuit-breakers/reset
"Task stuck in pending"
Problem: No workers processing tasks Solution:
Check Sidekiq:
docker-compose logs sidekiqEnsure Redis is running:
docker-compose ps redisRestart workers:
docker-compose restart sidekiq
"All services timeout"
Problem: Network issues or resource constraints Solution:
Check Docker resources:
docker statsIncrease Docker memory allocation
Check for port conflicts:
lsof -i :3001-3004
"Correlation ID not propagating"
Problem: Services not forwarding headers Solution:
Check service logs for X-Correlation-ID header
Verify middleware is installed in each service
Update service configuration
🎯 Performance Benchmarks
Expected performance under normal conditions:
Full Registration
250ms
800ms
2s
User Creation
50ms
150ms
300ms
Billing Setup
100ms
300ms
500ms
Preferences Init
30ms
100ms
200ms
Email Send
200ms
500ms
1s
🔧 Advanced Testing
Chaos Engineering
Load Testing
Remember: The goal is to understand how Tasker handles the complexity of coordinating multiple services, not to test the services themselves. Focus on workflow resilience, retry strategies, and visibility into distributed operations.
Last updated