feat: wrapper to a single entrypoint to the stress test
This commit is contained in:
parent
7794b91d20
commit
722a3d2853
4 changed files with 34 additions and 10 deletions
|
|
@ -11,17 +11,23 @@ async function createMachines (numberOfMachines) {
|
|||
)
|
||||
}
|
||||
|
||||
function startServer () {
|
||||
const forked = fork('test-server.js')
|
||||
forked.send('start')
|
||||
}
|
||||
|
||||
async function run (args = minimist(process.argv.slice(2))) {
|
||||
const NUMBER_OF_MACHINES = args._[0]
|
||||
const HAS_VARIANCE = args.v || false
|
||||
|
||||
startServer()
|
||||
await createMachines(NUMBER_OF_MACHINES)
|
||||
|
||||
for (let i = 1; i <= NUMBER_OF_MACHINES; i++) {
|
||||
const forked = fork('child.js')
|
||||
forked.send({ machineIndex: i, hasVariance: HAS_VARIANCE })
|
||||
forked.on('message', msg => {
|
||||
console.log(`Message from child ${i}: ${msg}`)
|
||||
console.log(`Machine ${i} || ${msg}`)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,13 +20,14 @@ fi
|
|||
rm -rf ./machines/*
|
||||
|
||||
# Create stress database
|
||||
# sudo -u postgres psql postgres -c "drop database if exists lamassu_stress"
|
||||
# sudo -u postgres psql postgres -c "create database lamassu_stress with template lamassu"
|
||||
sudo -u postgres psql postgres -c "drop database if exists lamassu_stress"
|
||||
sudo -u postgres psql postgres -c "create database lamassu_stress with template lamassu"
|
||||
|
||||
START=1
|
||||
END=$1
|
||||
for (( c=$START; c<=$END; c++ ))
|
||||
do
|
||||
echo "Creating machine $c out of $END..."
|
||||
NUMBER=$c
|
||||
mkdir -p ./machines/$NUMBER/
|
||||
cp "$3"/data/client.sample.pem ./machines/$NUMBER/
|
||||
|
|
@ -44,15 +45,15 @@ EOL
|
|||
DEVICE_ID=`openssl x509 -outform der -in ./machines/$NUMBER/client.pem | sha256sum | cut -d " " -f 1`
|
||||
|
||||
# Update db config
|
||||
sudo -u postgres psql -t -d lamassu -c "select data from user_config where type='config' order by id desc limit 1" > config.json
|
||||
sudo -u postgres psql -t -d lamassu_stress -c "select data from user_config where type='config' order by id desc limit 1" > config.json
|
||||
NEW_CONFIG=$(node ./utils/save-config.js $NUMBER $DEVICE_ID)
|
||||
sudo -u postgres psql "lamassu" << EOF
|
||||
sudo -u postgres psql "lamassu_stress" << EOF
|
||||
insert into user_config(type, data, created, valid)
|
||||
values('config', '$NEW_CONFIG', now(), 't')
|
||||
EOF
|
||||
|
||||
# Add device on db
|
||||
sudo -u postgres psql "lamassu" << EOF
|
||||
sudo -u postgres psql "lamassu_stress" << EOF
|
||||
insert into devices(device_id, cashbox, cassette1, cassette2, paired, display, created, name, last_online, location)
|
||||
values ('$DEVICE_ID', 0, 0, 0, 't', 't', now(), $NUMBER, now(), '{}'::json)
|
||||
EOF
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
const exec = require('child_process')
|
||||
const exec = require('child_process').exec
|
||||
|
||||
/**
|
||||
* Execute simple shell command (async wrapper).
|
||||
|
|
@ -7,15 +7,25 @@ const exec = require('child_process')
|
|||
*/
|
||||
async function execCommand (cmd) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
exec.exec(cmd, (err, stdout, stderr) => {
|
||||
const proc = exec(cmd, (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
console.log(stdout)
|
||||
console.error(stderr)
|
||||
resolve({ stdout, stderr })
|
||||
}
|
||||
})
|
||||
|
||||
proc.stdout.on('data', data => {
|
||||
console.log(data)
|
||||
})
|
||||
|
||||
proc.stderr.on('data', data => {
|
||||
console.log(data)
|
||||
})
|
||||
|
||||
proc.on('exit', code => {
|
||||
console.log('child process exited with code ' + code.toString())
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
7
test/stress/test-server.js
Normal file
7
test/stress/test-server.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
const cmd = require('./scripts')
|
||||
|
||||
process.on('message', async (msg) => {
|
||||
console.log('Message from parent:', msg)
|
||||
|
||||
await cmd.execCommand(`node --prof ../../bin/lamassu-server --mockSms --testDB`)
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue