0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-13 22:41:32 -05:00

Added additional test routes (#22000)

no ref

Added a couple new routes for testing purposes. server:testmode config
must be set to true to access.
- {ghostUrl}/ghost/api/block/:seconds will block the node process for
the given duration
- {ghostUrl}/ghost/api/drop will simply hold the connection until client
timeout by doing nothing with it, helpful for saturating connections
This commit is contained in:
Steve Larson 2025-01-13 17:00:13 -06:00 committed by GitHub
parent 40073d916a
commit 978609506a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -91,5 +91,29 @@ module.exports = function testRoutes() {
res.sendStatus(202);
});
function blockForSeconds(seconds) {
const end = Date.now() + seconds * 1000;
while (Date.now() < end) {
// Busy-wait loop to block the event loop
}
}
router.get('/block/:seconds', (req, res) => {
const seconds = parseInt(req.params.seconds, 10);
if (isNaN(seconds) || seconds <= 0) {
return res.status(400).send('Invalid number of seconds');
}
// eslint-disable-next-line no-console
console.log(`Blocking for ${seconds} seconds`);
blockForSeconds(seconds);
res.send(`Blocked for ${seconds} seconds`);
});
router.get('/drop', () => { // do nothing and wait for request to drop
// eslint-disable-next-line no-console
console.log('Request received but not responding');
});
return router;
};