From a6a59211b3d15acf025657875008197fea6d9f0f Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Tue, 30 Oct 2018 20:35:37 +0000 Subject: [PATCH 1/2] Bug 1456909 - make oneShot a no-op in mock situations --- src/base.js | 1 + src/mockmonitor.js | 6 ++++++ test/mockmonitor_test.js | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/src/base.js b/src/base.js index c9f30f2..ee9376a 100644 --- a/src/base.js +++ b/src/base.js @@ -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; diff --git a/src/mockmonitor.js b/src/mockmonitor.js index d3d47d2..4de2c88 100644 --- a/src/mockmonitor.js +++ b/src/mockmonitor.js @@ -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; diff --git a/test/mockmonitor_test.js b/test/mockmonitor_test.js index 6a5a544..fef4742 100644 --- a/test/mockmonitor_test.js +++ b/test/mockmonitor_test.js @@ -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! + }); }); From 328392d535d3496f2d370999f84a47811d38ac19 Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Tue, 30 Oct 2018 20:56:47 +0000 Subject: [PATCH 2/2] Bug 1456909 - fix README to return promise --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6909197..360bbdd 100644 --- a/README.md +++ b/README.md @@ -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 }); },