feat: start re-working stress testing
This commit is contained in:
parent
7d11bfacb0
commit
6fb2b29bcb
18 changed files with 454 additions and 463 deletions
59
tests/stress/server.js
Normal file
59
tests/stress/server.js
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
const cp = require('node:child_process')
|
||||
const path = require('node:path')
|
||||
|
||||
const { EXIT } = require('./consts')
|
||||
const CLI = require('./cli')
|
||||
|
||||
const help_message = "Start the server configured for stress testing."
|
||||
|
||||
const cli = CLI({
|
||||
grammar: [
|
||||
[["--help"], "Show this help message"],
|
||||
],
|
||||
})
|
||||
|
||||
const help = (exit_code) => {
|
||||
console.log("Usage: lamassu-server-stress-testing server ARGS...")
|
||||
console.log(help_message)
|
||||
cli.help()
|
||||
return exit_code
|
||||
}
|
||||
|
||||
const start_server = (args) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const lamassu_server = path.join(__dirname, "../../bin/lamassu-server")
|
||||
const ls = cp.fork(lamassu_server, args, {
|
||||
cwd: process.cwd(),
|
||||
encoding: 'utf8',
|
||||
env: { LAMASSU_STRESS_TESTING: "YES" },
|
||||
})
|
||||
|
||||
ls.on('error', (error) => {
|
||||
console.log(error)
|
||||
resolve(EXIT.EXCEPTION)
|
||||
})
|
||||
|
||||
ls.on('exit', (code, signal) => {
|
||||
console.error("lamassu-server code:", code)
|
||||
console.error("lamassu-server signal:", signal)
|
||||
resolve(typeof(code) === 'number' ? code : EXIT.EXCEPTION)
|
||||
})
|
||||
})
|
||||
|
||||
const run = async (args) => {
|
||||
const [err, options, positional] = cli.parse(args)
|
||||
if (err) {
|
||||
console.error(err)
|
||||
return help(EXIT.BADARGS)
|
||||
}
|
||||
|
||||
if (options.help)
|
||||
return help(EXIT.OK)
|
||||
|
||||
return await start_server(positional)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
help_message,
|
||||
run,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue