From 60d05eafd432289f57a1084136fd97894412c8f0 Mon Sep 17 00:00:00 2001 From: Jithin Emmanuel Date: Thu, 21 May 2020 15:38:26 -0700 Subject: [PATCH] fix: fix for broken stop builds (#26) * fix: fix for broken stop builds * fix: typo --- index.js | 13 +++++++++---- package.json | 3 ++- test/index.test.js | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 62527ff..51e2178 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ const ANNOTATION_EXECUTOR_TYPE = 'executor'; // Key in annotations object that maps to an executor NPM module const Executor = require('screwdriver-executor-base'); +const logger = require('screwdriver-logger'); class ExecutorRouter extends Executor { /** @@ -33,7 +34,7 @@ class ExecutorRouter extends Executor { ExecutorPlugin = require(`screwdriver-executor-${plugin.name}`); this._executors.push(plugin); } catch (err) { - console.error(err.message); + logger.error(err.message); return; } @@ -133,9 +134,13 @@ class ExecutorRouter extends Executor { let executorName; for (const rule of this._executorRules) { - executorName = rule.check(config); - if (executorName && this[executorName]) { - break; + try { + executorName = rule.check(config); + if (executorName && this[executorName]) { + break; + } + } catch (err) { + logger.error(`Failed to validate executor rule ${rule.name}`, err); } } diff --git a/package.json b/package.json index d248e0c..33562c5 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,8 @@ "sinon": "^4.5.0" }, "dependencies": { - "screwdriver-executor-base": "^7.0.0" + "screwdriver-executor-base": "^7.0.0", + "screwdriver-logger": "^1.0.0" }, "release": { "debug": false, diff --git a/test/index.test.js b/test/index.test.js index 3046d9c..f325558 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -549,6 +549,41 @@ describe('index test', () => { }); }); + it('calls _stop with default executor on executor selection errors', () => { + executor = new Executor({ + ecosystem, + defaultPlugin: 'example', + executor: [ + { + name: 'k8s', + weightage: 20, + options: k8sPluginOptions, + exclusions: ['rhel6'] + }, + { + name: 'example', + weightage: 0, + options: examplePluginOptions + }, + { + name: 'k8s-vm', + weightage: 10, + options: k8sVmPluginOptions + } + ] + }); + + return executor + .stop({ + buildId: 920 + }) + .then(() => { + assert.called(exampleExecutorMock._stop); + assert.notCalled(k8sVmExecutorMock._stop); + assert.notCalled(k8sExecutorMock._stop); + }); + }); + it('calls _start with executor from annotation', () => { k8sVmExecutorMock._start.resolves('k8sVmExecutorResult');