From b1b4a64d386f07771a65dcde5a7d9ff824070394 Mon Sep 17 00:00:00 2001 From: soulgalore Date: Mon, 9 Sep 2024 12:57:26 +0200 Subject: [PATCH 1/4] server configuration fixes --- server/src/testrunners.js | 61 ++++++++---------------- testrunner/src/queue/queuehandler.js | 3 +- testrunner/src/sitespeedio-testrunner.js | 4 +- testrunner/src/validateconfig.js | 1 + 4 files changed, 25 insertions(+), 44 deletions(-) diff --git a/server/src/testrunners.js b/server/src/testrunners.js index a2832c5..676c6e0 100755 --- a/server/src/testrunners.js +++ b/server/src/testrunners.js @@ -1,53 +1,34 @@ -import merge from 'lodash.merge'; +const testRunners = {}; -const testRunners = []; -const testRunnersById = []; - -export function addTestRunner(config) { - const index = testRunners.findIndex( - testRunner => testRunner.name == config.name - ); - testRunnersById.push(config); - if (index === -1) { - testRunners.push(config); +function mergeByHostname(target, source) { + if (target[source.hostname]) { + target[source.hostname].setup = [ + ...target[source.hostname].setup, + ...source.setup + ]; } else { - // Maybe we have multiple testrunners for the same location etc - merge(testRunners[index], config); + target[source.hostname] = { ...source }; } } -export function removeTestRunner(config) { - // Runners need to have uniqie ids. - // First remove the runner - testRunnersById.splice( - testRunnersById.findIndex( - testRunner => testRunner.hostname === config.hostname - ), - 1 - ); +function removeByHostname(target, hostnameToRemove) { + delete target[hostnameToRemove]; +} - // Update the merged version - const index = testRunners.findIndex( - testRunner => testRunner.name == config.name - ); - let updatedSetup = {}; - for (let testRunner of testRunnersById) { - if ((testRunner.name = config.name)) { - merge(updatedSetup, testRunner); - } - } +export function addTestRunner(config) { + mergeByHostname(testRunners, config); +} - if (Object.keys(updatedSetup) > 0) { - testRunners[index] = updatedSetup; - } else { - testRunners.splice(index, 1); - } +export function removeTestRunner(config) { + removeByHostname(testRunners, config.hostname); } + export function getTestRunners() { - return testRunners; + return Object.values(testRunners); } export function getTestRunnersConfiguration(name) { - const index = testRunners.findIndex(testRunner => testRunner.name === name); - return testRunners[index]; + return Object.values(testRunners).find( + testRunner => testRunner.name === name + ); } diff --git a/testrunner/src/queue/queuehandler.js b/testrunner/src/queue/queuehandler.js index 2069b6f..c98d90e 100644 --- a/testrunner/src/queue/queuehandler.js +++ b/testrunner/src/queue/queuehandler.js @@ -13,7 +13,7 @@ class QueueHandler { this.queues = {}; } - async start() { + async start(serverConfig) { const port = nconf.get('redis:port') ?? 6379; const host = nconf.get('redis:host') ?? '127.0.0.1'; const password = nconf.get('redis:password'); @@ -72,7 +72,6 @@ class QueueHandler { }); // Lets tell the world (or the testsrunners queue) that we are live - const serverConfig = nconf.get('location'); const testRunnersQueue = await this.getQueue('testrunners'); testRunnersQueue.add({ type: 'start', serverConfig: serverConfig }); } diff --git a/testrunner/src/sitespeedio-testrunner.js b/testrunner/src/sitespeedio-testrunner.js index 348b4b7..6acd1bf 100644 --- a/testrunner/src/sitespeedio-testrunner.js +++ b/testrunner/src/sitespeedio-testrunner.js @@ -29,7 +29,7 @@ export class SitespeedioTestRunner { // If hostname isn't configured add it const hostname = os.hostname(); - if (nconf.get('hostname') === undefined) { + if (serverConfig.hostname === undefined) { serverConfig.hostname = hostname; logger.info('No hostname found in configuration. Will use %s', hostname); } @@ -69,7 +69,7 @@ export class SitespeedioTestRunner { } } - await queueHandler.start(); + await queueHandler.start(serverConfig); process.on('uncaughtException', error => { // ioredis configuration is tricky to get right diff --git a/testrunner/src/validateconfig.js b/testrunner/src/validateconfig.js index 121af6d..34e9b3e 100644 --- a/testrunner/src/validateconfig.js +++ b/testrunner/src/validateconfig.js @@ -6,6 +6,7 @@ import Joi from 'joi'; const setupSchema = Joi.array().items( Joi.object({ name: Joi.string().required(), + hostname: Joi.string().optional(), type: Joi.string().valid('desktop', 'emulatedMobile', 'android').required(), browsers: Joi.array() .items(Joi.string().valid('chrome', 'firefox', 'edge', 'safari')) From 85c0522874f4e3cf2235a6c778a5655d7e1c51f4 Mon Sep 17 00:00:00 2001 From: soulgalore Date: Mon, 9 Sep 2024 13:21:45 +0200 Subject: [PATCH 2/4] pug fix --- server/views/includes/script.pug | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/server/views/includes/script.pug b/server/views/includes/script.pug index 82cf92e..6744e8c 100644 --- a/server/views/includes/script.pug +++ b/server/views/includes/script.pug @@ -33,8 +33,11 @@ script. document.getElementById('connectivity').add(new Option(connectivity,connectivity), undefined); } - for (let testType of location.setup.testTypes) { - document.getElementById('testType').add(new Option(testType,testType), undefined); + + for (let setup of location.setup) { + if (setup.type) { + document.getElementById('testType').add(new Option(setup.type, setup.type), undefined); + } } for (let setup of location.setup) { From d31c00bd053932b41ecac98bd3561d411eaf08fe Mon Sep 17 00:00:00 2001 From: soulgalore Date: Mon, 9 Sep 2024 14:28:39 +0200 Subject: [PATCH 3/4] fixes --- server/src/testrunners.js | 6 +++--- testrunner/src/sitespeedio-testrunner.js | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/server/src/testrunners.js b/server/src/testrunners.js index 676c6e0..dc982be 100755 --- a/server/src/testrunners.js +++ b/server/src/testrunners.js @@ -11,8 +11,8 @@ function mergeByHostname(target, source) { } } -function removeByHostname(target, hostnameToRemove) { - delete target[hostnameToRemove]; +function removeByHostname(hostnameToRemove) { + delete testRunners[hostnameToRemove]; } export function addTestRunner(config) { @@ -20,7 +20,7 @@ export function addTestRunner(config) { } export function removeTestRunner(config) { - removeByHostname(testRunners, config.hostname); + removeByHostname(config.hostname); } export function getTestRunners() { diff --git a/testrunner/src/sitespeedio-testrunner.js b/testrunner/src/sitespeedio-testrunner.js index 6acd1bf..b97319f 100644 --- a/testrunner/src/sitespeedio-testrunner.js +++ b/testrunner/src/sitespeedio-testrunner.js @@ -82,6 +82,11 @@ export class SitespeedioTestRunner { try { const serverConfig = nconf.get('location'); + const hostname = os.hostname(); + if (serverConfig.hostname === undefined) { + serverConfig.hostname = hostname; + } + const testRunnerQueue = await queueHandler.getQueue('testrunners'); if (testRunnerQueue.client.status === 'ready') { From 80cd3a16f20fd92fbd8cb86f8c0c0d26da68355d Mon Sep 17 00:00:00 2001 From: soulgalore Date: Mon, 9 Sep 2024 14:37:36 +0200 Subject: [PATCH 4/4] lint --- server/views/includes/script.pug | 1 - 1 file changed, 1 deletion(-) diff --git a/server/views/includes/script.pug b/server/views/includes/script.pug index 6744e8c..85103bb 100644 --- a/server/views/includes/script.pug +++ b/server/views/includes/script.pug @@ -33,7 +33,6 @@ script. document.getElementById('connectivity').add(new Option(connectivity,connectivity), undefined); } - for (let setup of location.setup) { if (setup.type) { document.getElementById('testType').add(new Option(setup.type, setup.type), undefined);