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 #78 from djmitche/bug1456909
Browse files Browse the repository at this point in the history
Bug 1456909 - make oneShot a no-op in mock situations
  • Loading branch information
imbstack authored Oct 30, 2018
2 parents f50c4be + 328392d commit 27b4b73
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ with timing and error handling support.
```javascript
'expire-info': {
requires: ['cfg', 'monitor'],
setup: async ({cfg, monitor}) => {
monitor.oneShot('expire-info', () => {
setup: ({cfg, monitor}) => {
return monitor.oneShot('expire-info', () => {
// do the expiration stuff
});
},
Expand Down
1 change: 1 addition & 0 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class BaseMonitor {

/**
* Monitor a one-shot process. This function's promise never resolves!
* (except in testing, with MockMonitor)
*/
async oneShot(name, fn) {
let exitStatus = 0;
Expand Down
6 changes: 6 additions & 0 deletions src/mockmonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ class MockMonitor extends BaseMonitor {
);
}

/**
* Override oneShot to helpfully not call process.exit
*/
async oneShot(name, fn) {
await fn();
}
}

module.exports = MockMonitor;
5 changes: 5 additions & 0 deletions test/mockmonitor_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,9 @@ suite('MockMonitor', () => {
data = monitor.counts['mm.ec2.us-west-2.describeAvailabilityZones.count'];
assert(data === 1);
});

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

0 comments on commit 27b4b73

Please sign in to comment.