chaos-injector
Version:
Chaos engineering middleware for testing API resilience
17 lines (14 loc) • 432 B
JavaScript
// ChaosInjector/middlewares/timeout.js
function timeout(options = {}) {
const { failureRate = 0.1 } = options;
return (req, res, next) => {
if (Math.random() < failureRate) {
// Simulate a timeout by not sending a response
console.log('Simulating timeout...');
return; // The request will hang until the client times out
} else {
next();
}
};
}
module.exports = timeout;