lethal
v0.1.0
Published
Controlled process-termination and chaos-testing utilities for Node.js services
Readme
lethal
Controlled process-termination and chaos-testing utilities for Node.js services
Features
- Spawn and manage child processes for shutdown testing and fault injection.
- Send signals, staged termination sequences, and timed kills to verify graceful shutdown.
- Verify cleanup hooks, open-handle detection, and exit codes with simple assertions.
- CLI and programmatic APIs for integrating termination scenarios into CI and chaos tests.
Install
npm install lethal
Quick Start
const lethal = require('lethal');
(async () => {
// Spawn a child process (e.g., a local server) to test graceful shutdown
const ctl = lethal.spawn('node', ['server.js'], { cwd: __dirname });
// Optionally wait for a startup message or timeout
await ctl.waitForOutput(/listening on/i, { timeout: 5000 });
// Send a SIGTERM after a short delay and verify shutdown
await ctl.kill({ signal: 'SIGTERM', delay: 200 });
const result = await ctl.waitForExit(5000);
if (result.graceful) {
console.log('Process shut down gracefully');
} else {
console.error('Process did not shut down cleanly', result);
process.exitCode = 1;
}
})();License
MIT
