ServerMonitor / dev /tests /web /t_flood.js
mchuca's picture
Server Monitor: six editions (C++/Qt, Python, web for Linux and Windows), requirements and developer kit
bad179a
Raw History Blame Contribute Delete
888 Bytes
// a console command with endless output must not take the monitor down. node t_flood.js <port>
const { sleep, client, check, done } = require('./lib'), { req, post } = client(process.argv[2]);
(async () => {
const t = Date.now();
const r = await req('POST', '/api/exec', { id: 'local1', cmd: 'yes 0123456789012345678901234567890123456789' }).catch(e => ({ status: 0, text: String(e) }));
check('endless output: the command is stopped and reported', r.status === 200 && r.json.code === -1 && r.json.out.length < 6e6, `status ${r.status} after ${Date.now() - t} ms, ${r.json ? r.json.out.length + ' chars, …' + JSON.stringify(r.json.out.slice(-40)) : r.text}`);
await sleep(1500);
const s = await req('GET', '/api/state').catch(e => ({ status: 0, text: String(e) }));
check('the monitor is still running', s.status === 200, s.status || s.text);
done();
})();