diff --git a/src/base.js b/src/base.js index ee9376a..5bfe09c 100644 --- a/src/base.js +++ b/src/base.js @@ -1,4 +1,5 @@ const _ = require('lodash'); +const assert = require('assert'); const debug = require('debug')('taskcluster-lib-monitor'); /** @@ -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) { diff --git a/src/mockmonitor.js b/src/mockmonitor.js index 4de2c88..ff1aa7a 100644 --- a/src/mockmonitor.js +++ b/src/mockmonitor.js @@ -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(); } } diff --git a/test/base_test.js b/test/base_test.js index 9a7391d..ed2867e 100644 --- a/test/base_test.js +++ b/test/base_test.js @@ -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]); + }); }); }); diff --git a/test/mockmonitor_test.js b/test/mockmonitor_test.js index fef4742..5bd7938 100644 --- a/test/mockmonitor_test.js +++ b/test/mockmonitor_test.js @@ -155,7 +155,7 @@ suite('MockMonitor', () => { }); test('monitor.oneShot', async () => { - monitor.oneShot(() => {}); + await monitor.oneShot('test', () => {}); // just expect this not to call process.exit! }); });