add cluster testing

deepsource-autofix-76c6eb20
Dan Gowans 2023-02-24 10:00:00 -05:00
parent 16097862fc
commit 8dbaf9534a
4 changed files with 42 additions and 4 deletions

View File

@ -32,6 +32,9 @@ jobs:
- name: Copy Test Config
run: cp ./data/config.testing.js ./data/config.js
- name: Test Application Startup
run: npm run test:startup
- name: Code Climate (Before)
if: ${{ github.event_name != 'pull_request' && env.CC_TEST_REPORTER_ID != '' && matrix.node == 16 }}
run: |

View File

@ -11,9 +11,15 @@ const directoryName = dirname(fileURLToPath(import.meta.url));
const processCount = Math.min(configFunctions.getProperty('application.maximumProcesses'), os.cpus().length);
debug(`Primary pid: ${process.pid}`);
debug(`Launching ${processCount} processes`);
cluster.setupPrimary({
const clusterSettings = {
exec: directoryName + '/wwwProcess.js'
});
};
if (cluster.setupPrimary) {
cluster.setupPrimary(clusterSettings);
}
else {
cluster.setupMaster(clusterSettings);
}
for (let index = 0; index < processCount; index += 1) {
cluster.fork();
}
@ -48,3 +54,11 @@ if (ntfyStartupConfig) {
void ntfyPublish(ntfyShutdownMessage);
});
}
if (process.env.STARTUP_TEST === 'true') {
const killSeconds = 10;
debug(`Killing processes in ${killSeconds} seconds...`);
setTimeout(() => {
debug('Killing processes');
process.exit(0);
}, 10000);
}

View File

@ -23,9 +23,15 @@ const processCount = Math.min(
debug(`Primary pid: ${process.pid}`)
debug(`Launching ${processCount} processes`)
cluster.setupPrimary({
const clusterSettings = {
exec: directoryName + '/wwwProcess.js'
})
}
if (cluster.setupPrimary) {
cluster.setupPrimary(clusterSettings)
} else {
cluster.setupMaster(clusterSettings)
}
for (let index = 0; index < processCount; index += 1) {
cluster.fork()
@ -69,3 +75,16 @@ if (ntfyStartupConfig) {
void ntfyPublish(ntfyShutdownMessage)
})
}
if (process.env.STARTUP_TEST === 'true') {
const killSeconds = 10
debug(`Killing processes in ${killSeconds} seconds...`)
setTimeout(() => {
debug('Killing processes')
// eslint-disable-next-line no-process-exit, unicorn/no-process-exit
process.exit(0)
}, 10_000)
}

View File

@ -11,11 +11,13 @@
"build:version": "npx genversion --es6 --semi version.js",
"start": "cross-env NODE_ENV=production node ./bin/www",
"dev:test": "cross-env NODE_ENV=dev DEBUG=lot-occupancy-system:* TEST_DATABASES=true nodemon ./bin/www.js",
"dev:test:process": "cross-env NODE_ENV=dev DEBUG=lot-occupancy-system:* TEST_DATABASES=true nodemon ./bin/wwwProcess.js",
"dev:live": "cross-env NODE_ENV=dev DEBUG=lot-occupancy-system:* nodemon ./bin/www.js",
"cy:open": "cypress open --config-file cypress.config.js",
"cy:run": "cypress run --config-file cypress.config.js",
"cy:run:firefox": "cypress run --config-file cypress.config.js --browser firefox",
"test": "cross-env NODE_ENV=dev DEBUG=lot-occupancy-system:* TEST_DATABASES=true mocha --timeout 30000 --exit",
"test:startup": "cross-env NODE_ENV=dev DEBUG=lot-occupancy-system:* TEST_DATABASES=true STARTUP_TEST=true node ./bin/www.js",
"coverage": "cross-env NODE_ENV=dev DEBUG=lot-occupancy-system:* TEST_DATABASES=true c8 --reporter=lcov --reporter=text --reporter=text-summary mocha --timeout 30000 --exit",
"temp:legacy:importFromCsv": "cross-env NODE_ENV=dev DEBUG=lot-occupancy-system:* TEST_DATABASES=true node ./temp/legacy.importFromCsv.js",
"temp:so:exportMaps": "node ./temp/so.exportMaps.js"