Skip to content

Commit

Permalink
fix: fix for broken stop builds (#26)
Browse files Browse the repository at this point in the history
* fix: fix for broken stop builds

* fix: typo
  • Loading branch information
jithine authored May 21, 2020
1 parent a4154ea commit 60d05ea
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
13 changes: 9 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
}

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
35 changes: 35 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down

0 comments on commit 60d05ea

Please sign in to comment.