Skip to content
This repository was archived by the owner on Jan 5, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/base.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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!
});
});