test(integration-tests): add structured test infrastructure #781
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Integration Testing Infrastructure Improvement
Overview
This PR enhances the integration testing infrastructure for
indexer-rs
by introducing structured test contexts, reusable utilities, and improved error handling. The changes make tests more reliable, debuggable, and maintainable while preserving existing functionality.Problem Statement
The current integration testing approach had several limitations:
Solution
Phase 1: Foundation (Implemented)
1. Test Context and Isolation (
test_context.rs
)Created a comprehensive
TestContext
struct that provides:Key features:
Structured error types for better diagnostics:
2. Reusable Test Utilities (
test_utils.rs
)Extracted and enhanced utilities from existing tests:
ReceiptUtils
: V1/V2 receipt creation, sending, and batch operationsEscrowUtils
: Escrow balance checking and validationServiceUtils
: Service health checking and monitoringMetricsUtils
: RAV generation and fee aggregation monitoringTestAssertions
: Enhanced assertions with better error messagesKey improvements:
3. Test Macro for Consistent Structure
Introduced
test_with_context!
macro for consistent test structure:Phase 2: Enhanced Test Coverage (Planned)
1. Allocation Lifecycle Testing
2. Error Scenario Testing
3. V1/V2 Migration Testing
Phase 3: Advanced Observability (Planned)
1. Test Observer Pattern
2. Performance Baseline Testing
What This Enables
Enhanced Testing Capabilities
Precise Error Diagnostics: Instead of generic failures, tests now provide specific error contexts:
Test Isolation: Each test runs in its own isolated context with unique identifiers, preventing interference between tests running in parallel
Automatic Cleanup: Tests automatically clean up resources (allocations, escrow funds) even when they fail
Comprehensive Monitoring: Tests can monitor metrics, service health, and system state in real-time
Batch Operations: Send multiple receipts efficiently with proper error handling and progress tracking
New Testing Workflow
1. Writing Tests with TestContext
2. Developer Workflow
Before (Old Approach):
After (New Approach):
test_with_context!
macro for consistent structureTestContext
for automatic resource management3. Error Handling Workflow
4. CI/CD Integration
Prerequisites:
just setup
)Test Execution:
Debugging Failed Tests:
Benefits
For Developers
For CI/CD
For System Reliability
Implementation Progress
✅ Completed
TestContext
struct with isolation and cleanuptest_utils.rs
with extracted utilitiestest_with_context!
macro for consistent structurecargo run -- test-with-context
command🚧 In Progress
📋 Planned
Breaking Changes
None. The changes are purely additive and maintain backward compatibility with existing tests.
Testing
The new infrastructure has been tested with:
Running the Enhanced Tests
Set up the test environment:
Run the enhanced tests:
cd integration-tests cargo run -- test-with-context
Monitor test execution:
Documentation
Next Steps