diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index dbf758c7..974da63e 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -31,6 +31,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 }} diff --git a/bin/www.js b/bin/www.js index 43039d86..027a970e 100644 --- a/bin/www.js +++ b/bin/www.js @@ -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); +} diff --git a/bin/www.ts b/bin/www.ts index 0d2f9f31..e12169d8 100644 --- a/bin/www.ts +++ b/bin/www.ts @@ -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) +} diff --git a/package.json b/package.json index e38f1b41..36dab48e 100644 --- a/package.json +++ b/package.json @@ -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"