Skip to content
This repository was archived by the owner on Jan 5, 2019. It is now read-only.

Commit a9c790b

Browse files
authored
Merge pull request #90 from djmitche/catch-oneshot-bug
Fail when oneShot doesn't get the right arguments
2 parents 279036e + 4e9e4bc commit a9c790b

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

src/base.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const _ = require('lodash');
2+
const assert = require('assert');
23
const debug = require('debug')('taskcluster-lib-monitor');
34

45
/**
@@ -169,6 +170,9 @@ class BaseMonitor {
169170

170171
try {
171172
try {
173+
assert.equal(typeof name, 'string');
174+
assert.equal(typeof fn, 'function');
175+
172176
await this.timer(`${name}.duration`, fn);
173177
this.count(`${name}.done`);
174178
} catch (err) {

src/mockmonitor.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class MockMonitor extends BaseMonitor {
6464
* Override oneShot to helpfully not call process.exit
6565
*/
6666
async oneShot(name, fn) {
67+
assert.equal(typeof name, 'string');
68+
assert.equal(typeof fn, 'function');
69+
6770
await fn();
6871
}
6972
}

test/base_test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,11 @@ suite('BaseMonitor', function() {
117117
assert.equal(monitor.counts.length, 0);
118118
assert(monitor.errors[0].toString().match(/uhoh/), monitor.errors[0]);
119119
});
120+
121+
test('missing name', async function() {
122+
await monitor.oneShot(async () => { throw new Error('uhoh'); });
123+
assert.equal(exitStatus, 1);
124+
assert(monitor.errors[0].toString().match(/Assertion/), monitor.errors[0]);
125+
});
120126
});
121127
});

test/mockmonitor_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ suite('MockMonitor', () => {
155155
});
156156

157157
test('monitor.oneShot', async () => {
158-
monitor.oneShot(() => {});
158+
await monitor.oneShot('test', () => {});
159159
// just expect this not to call process.exit!
160160
});
161161
});

0 commit comments

Comments
 (0)