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

Commit

Permalink
Merge pull request #90 from djmitche/catch-oneshot-bug
Browse files Browse the repository at this point in the history
Fail when oneShot doesn't get the right arguments
  • Loading branch information
djmitche committed Nov 20, 2018
2 parents 279036e + 4e9e4bc commit a9c790b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/base.js
@@ -1,4 +1,5 @@
const _ = require('lodash');
const assert = require('assert');
const debug = require('debug')('taskcluster-lib-monitor');

/**
Expand Down Expand Up @@ -169,6 +170,9 @@ class BaseMonitor {

try {
try {
assert.equal(typeof name, 'string');
assert.equal(typeof fn, 'function');

await this.timer(`${name}.duration`, fn);
this.count(`${name}.done`);
} catch (err) {
Expand Down
3 changes: 3 additions & 0 deletions src/mockmonitor.js
Expand Up @@ -64,6 +64,9 @@ class MockMonitor extends BaseMonitor {
* Override oneShot to helpfully not call process.exit
*/
async oneShot(name, fn) {
assert.equal(typeof name, 'string');
assert.equal(typeof fn, 'function');

await fn();
}
}
Expand Down
6 changes: 6 additions & 0 deletions test/base_test.js
Expand Up @@ -117,5 +117,11 @@ suite('BaseMonitor', function() {
assert.equal(monitor.counts.length, 0);
assert(monitor.errors[0].toString().match(/uhoh/), monitor.errors[0]);
});

test('missing name', async function() {
await monitor.oneShot(async () => { throw new Error('uhoh'); });
assert.equal(exitStatus, 1);
assert(monitor.errors[0].toString().match(/Assertion/), monitor.errors[0]);
});
});
});
2 changes: 1 addition & 1 deletion test/mockmonitor_test.js
Expand Up @@ -155,7 +155,7 @@ suite('MockMonitor', () => {
});

test('monitor.oneShot', async () => {
monitor.oneShot(() => {});
await monitor.oneShot('test', () => {});
// just expect this not to call process.exit!
});
});

0 comments on commit a9c790b

Please sign in to comment.