Contributor Focus: [Resilience Testing] Validate how the backend behaves under realistic failure conditions
ETA: 2 days
Status: COMPLETED ✅
- Extends the existing mock RPC server with fault injection capabilities
- Supports multiple fault types:
- Latency injection: Add delays to RPC responses
- Failure injection: Return error responses
- Partial failures: Some methods fail while others work
- Rate limiting: Enforce request limits
- Flaky behavior: Periodic availability
- Gradual degradation: Increasing failure probability over time
- Dynamic configuration updates
- Comprehensive logging
- Orchestrates chaos scenarios and collects observations
- Predefined realistic failure scenarios:
- Latency Spikes
- Partial RPC Failure
- Rate Limiting
- Flaky Network
- Gradual Degradation
- Complete Outage
- Automated evaluation against expected behaviors
- Metrics collection and reporting
- Recommendation generation based on test results
- Integrated with existing Jest test framework
- 7 comprehensive test cases:
- RPC latency spike handling
- Partial RPC failure handling
- Rate limiting and backoff behavior
- Circuit breaker tripping during outages
- Retry logic with error classification
- End-to-end chaos scenario suite
- Health reporting during chaos
- Can be run standalone or as part of test suite
- User-friendly interface for running chaos tests
- Multiple output formats (console, JSON, markdown)
- Scenario selection and filtering
- Report generation and file export
- Integration with npm scripts
- Comprehensive guide to chaos testing
- Scenario descriptions and expected behaviors
- Usage examples and best practices
- Troubleshooting guide
- Integration instructions
- Interactive demonstration of chaos testing
- Example scenarios and configurations
- Programmatic usage patterns
- Added npm scripts to
package.json:npm run chaos-test- Run all chaos scenariosnpm run chaos-test:list- List available scenariosnpm run chaos-test:single- Run single scenarionpm run test:chaos- Run chaos tests via Jest
- Updated README with chaos testing section
- Implemented: 6 realistic fault scenarios covering common production issues
- Verified: Each scenario injects specific, measurable faults
- Testable: Scenarios can be run individually or as a suite
- Implemented: Comprehensive metrics collection (requests, failures, latency, circuit state)
- Observable: Real-time logging and health reporting
- Repeatable: Deterministic fault injection with configurable probabilities
- Implemented: Detailed documentation with expected behaviors
- Educational: Each scenario documents what should happen
- Actionable: Recommendations generated from test results
- Implemented: Automated recommendation generation
- Prioritized: Recommendations categorized by severity (CRITICAL, HIGH, MEDIUM)
- Actionable: Specific actions suggested for each finding
- Not just binary success/failure - includes partial failures, degradation, flakiness
- Configurable probabilities and intensities
- Time-based behaviors (gradual degradation, periodic flakiness)
- Metrics collection at multiple levels (RPC, circuit breaker, retry logic)
- Health state tracking during chaos
- Detailed logs for debugging
- Works with existing Jest test framework
- Compatible with current RPC wrapper and circuit breaker
- Minimal dependencies on existing code
- Configurable scenario durations (short for CI, longer for manual testing)
- Easy to add new fault types or scenarios
- Clear separation between test infrastructure and application code
# Run all chaos scenarios
npm run chaos-test
# Run specific scenarios
npm run chaos-test -- --scenario=latency,ratelimit
# Run via Jest
npm test -- chaos.test.js
# Generate JSON report
npm run chaos-test -- --output=json --file=report.jsonconst { ChaosTestHarness } = require('./src/chaosTestHarness');
async function testResilience() {
const harness = new ChaosTestHarness();
const results = await harness.runAllScenarios();
console.log(`Passed ${results.summary.passedScenarios}/${results.summary.totalScenarios}`);
if (results.summary.failedScenarios > 0) {
const report = harness.generateReport(results);
console.log('Recommendations:', report.recommendations);
}
}src/chaosRpcServer.js- Fault-injecting RPC serversrc/chaosTestHarness.js- Chaos test orchestration__tests__/chaos.test.js- Chaos test suitescripts/chaos-test.js- Command-line tooldocs/CHAOS_TESTING.md- Comprehensive documentationexamples/chaos-demo.js- Interactive demoIMPLEMENTATION_SUMMARY_CHAOS_TESTING.md- This summary
package.json- Added chaos testing scriptsREADME.md- Added chaos testing section to table of contents and documentation
The implementation provides:
- Unit tests: Individual component testing
- Integration tests: Component interaction testing
- Scenario tests: Realistic failure pattern testing
- End-to-end tests: Full system behavior under chaos
- Run the chaos tests to establish baseline resilience
- Review recommendations from test reports
- Add new scenarios for specific failure modes encountered in production
- Integrate into CI/CD to catch resilience regressions
- Extend fault injection to cover new dependency types (resolvers, databases, etc.)
The chaos testing framework successfully addresses Issue #244 by providing a comprehensive, practical, and maintainable way to test keeper resilience under realistic failure conditions. The implementation meets all acceptance criteria and provides a solid foundation for ongoing resilience testing and improvement.