Performance Testing ​
Performance testing in gRPC Testify focuses on validating response times and handling timeouts for individual tests.
What's Supported ​
gRPC Testify supports these performance testing features:
- âś… Timeout Configuration - Set maximum time for individual tests
- âś… Retry Mechanism - Configure retries for failed network calls
- âś… Response Time Validation - Basic timeout enforcement
Timeout Testing ​
Setting Test Timeout ​
Configure timeout for individual tests:
php
--- ENDPOINT ---
service.ServiceName/MethodName
--- REQUEST ---
{ "data": "test" }
--- RESPONSE ---
{
"result": "success"
}
--- OPTIONS ---
timeout: 5Testing Slow Responses ​
Test that slow responses are properly handled:
php
--- ENDPOINT ---
service.ServiceName/SlowMethod
--- REQUEST ---
{ "delay": 3000 }
--- ERROR ---
{
"code": 4,
"message": "Deadline exceeded",
"details": "Request timed out"
}
--- OPTIONS ---
timeout: 2Retry Configuration ​
Basic Retry Setup ​
Configure retry attempts for network failures:
php
--- ENDPOINT ---
service.ServiceName/MethodName
--- REQUEST ---
{ "data": "test" }
--- RESPONSE ---
{
"result": "success"
}
--- OPTIONS ---
timeout: 10
retry: 3
retry_delay: 1Disabling Retries ​
For tests that should fail immediately:
php
--- ENDPOINT ---
service.ServiceName/MethodName
--- REQUEST ---
{ "data": "test" }
--- RESPONSE ---
{
"result": "success"
}
--- OPTIONS ---
timeout: 5
retry: 0CLI Performance Options ​
Global Timeout ​
Set timeout for all tests via command line:
bash
# Set 30 second timeout for all tests
grpctestify.sh tests/ --timeout 30
# Set 60 second timeout for specific test
grpctestify.sh test.gctf --timeout 60Global Retry Configuration ​
Configure retry behavior globally:
bash
# Set 5 retries with 2 second delay
grpctestify.sh tests/ --retry 5 --retry-delay 2
# Disable retries completely
grpctestify.sh tests/ --no-retryParallel Execution ​
Run multiple test files in parallel:
bash
# Auto-detect optimal parallel jobs
grpctestify.sh tests/ --parallel auto
# Use 4 parallel workers
grpctestify.sh tests/ --parallel 4Real Examples ​
Timeout Test ​
php
--- ADDRESS ---
localhost:4770
--- ENDPOINT ---
shopflow.ShopFlowService/HealthCheck
--- REQUEST ---
{
"service": "shopflow-ecommerce"
}
--- ASSERTS ---
.status == "healthy"
.message | test("ShopFlow")
--- OPTIONS ---
timeout: 2Retry Test ​
php
--- ADDRESS ---
localhost:4770
--- ENDPOINT ---
shopflow.ShopFlowService/GetProduct
--- REQUEST ---
{
"product_id": "prod_001"
}
--- ASSERTS ---
.found == true
.product.id == "prod_001"
.product.name == "Wireless Bluetooth Headphones"
--- OPTIONS ---
timeout: 10
retry: 3
retry_delay: 1Best Practices ​
✅ Do This: ​
Set Reasonable Timeouts
php--- OPTIONS --- timeout: 30 # 30 seconds for normal operationsConfigure Retries for Network Tests
php--- OPTIONS --- timeout: 10 retry: 3 retry_delay: 1Use Global Options for Consistency
bashgrpctestify.sh tests/ --timeout 30 --retry 3
❌ Avoid This: ​
Setting Unrealistic Timeouts
php# Bad - too short timeout: 1 # Bad - too long timeout: 3600Excessive Retries
php# Bad - too many retries retry: 100 # Good - reasonable retries retry: 3
Limitations ​
What's NOT Supported ​
- ❌ Response Time Assertions - Cannot validate specific response times
- ❌ Load Testing - No built-in load testing capabilities
- ❌ Performance Metrics - No detailed performance reporting
- ❌ Concurrent Test Execution - Tests run sequentially within files
Workarounds ​
For advanced performance testing:
Use External Tools
bash# Use Apache Bench or similar for load testing ab -n 1000 -c 10 http://localhost:8080/Custom Performance Scripts
bash# Create custom performance test scripts for i in {1..100}; do grpctestify.sh test.gctf done
Next Steps ​
- Data Validation - Learn basic testing patterns
- Error Testing - Test error conditions
- Real Examples - See performance testing in action