From ac1c6e9779ff4c7f1c1fa9fbe89218a03bef62e3 Mon Sep 17 00:00:00 2001 From: rackhd Date: Wed, 8 Nov 2017 01:45:42 -0800 Subject: [PATCH] RAC-5743: unit test doesn't exit after upgrading mocha to 4.0.1 --- lib/common/connection.js | 2 +- lib/services/statsd.js | 1 + package.json | 2 +- spec/lib/common/connection-spec.js | 3 ++- spec/lib/protocol/dhcp-spec.js | 7 +++---- spec/lib/protocol/scheduler-spec.js | 5 ++++- spec/lib/protocol/task-graph-runner-spec.js | 8 +++++++- spec/lib/protocol/task-spec.js | 5 ++++- spec/lib/protocol/waterline-spec.js | 5 ----- 9 files changed, 23 insertions(+), 15 deletions(-) diff --git a/lib/common/connection.js b/lib/common/connection.js index 94719306..6259b020 100644 --- a/lib/common/connection.js +++ b/lib/common/connection.js @@ -102,7 +102,7 @@ function connectionFactory (assert, amqp, Promise, util, _) { delete self.connection; resolve(); }); - + self.connection.setImplOptions({reconnect: false}); self.connection.disconnect(); } else { reject(new Error('Connection Not Started.')); diff --git a/lib/services/statsd.js b/lib/services/statsd.js index 43f5f318..754384c6 100644 --- a/lib/services/statsd.js +++ b/lib/services/statsd.js @@ -51,6 +51,7 @@ function statsdServiceFactory( if(this.started) { this.increment('process.stopped'); this.started = false; + this.close(); } return Promise.resolve(); }; diff --git a/package.json b/package.json index a87dabbc..f1e4476f 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "istanbul": "^0.3.5", "jsdoc": "^3.3.0-alpha13", "jshint": "^2.5.11", - "mocha": "^2.1.0", + "mocha": "^4.0.1", "nock": "~9.0.22", "sinon": "1.16.1", "sinon-as-promised": "^2.0.3", diff --git a/spec/lib/common/connection-spec.js b/spec/lib/common/connection-spec.js index e49a2a7e..18400eb3 100755 --- a/spec/lib/common/connection-spec.js +++ b/spec/lib/common/connection-spec.js @@ -290,7 +290,8 @@ describe('Connection', function () { }); this.subject.start().then(function () { return expect(self.subject.stop()).to.be.fulfilled; - }); + }) + .then(done()); }); it('should reject if not connected', function () { diff --git a/spec/lib/protocol/dhcp-spec.js b/spec/lib/protocol/dhcp-spec.js index 3adc7c00..d911f655 100755 --- a/spec/lib/protocol/dhcp-spec.js +++ b/spec/lib/protocol/dhcp-spec.js @@ -22,12 +22,10 @@ describe("DHCP protocol functions", function () { testSubscription = new Subscription({},{}); testMessage = new Message({},{},{}); sinon.stub(testMessage); - sinon.stub(messenger); }); beforeEach(function() { - messenger.subscribe.reset(); - messenger.request.reset(); + this.sandbox.stub(messenger, 'request'); }); helper.after(); @@ -291,4 +289,5 @@ describe("DHCP protocol functions", function () { }).should.be.rejectedWith(sampleError); }); }); -}); \ No newline at end of file +}); + diff --git a/spec/lib/protocol/scheduler-spec.js b/spec/lib/protocol/scheduler-spec.js index 129c7c89..1b1f60e7 100644 --- a/spec/lib/protocol/scheduler-spec.js +++ b/spec/lib/protocol/scheduler-spec.js @@ -20,7 +20,10 @@ describe("Schedular protocol functions", function () { testSubscription = new Subscription({},{}); testMessage = new Message({},{},{}); sinon.stub(testMessage); - sinon.stub(messenger); + }); + + beforeEach(function() { + this.sandbox.stub(messenger, 'request'); }); helper.after(); diff --git a/spec/lib/protocol/task-graph-runner-spec.js b/spec/lib/protocol/task-graph-runner-spec.js index af59e186..ed8d921c 100644 --- a/spec/lib/protocol/task-graph-runner-spec.js +++ b/spec/lib/protocol/task-graph-runner-spec.js @@ -25,7 +25,12 @@ describe("TaskGraph Runner protocol functions", function () { testSubscription = new Subscription({},{}); testMessage = new Message({},{},{}); sinon.stub(testMessage); - sinon.stub(messenger); + }); + + beforeEach(function() { + this.sandbox.stub(messenger, 'request'); + this.sandbox.stub(messenger, 'publish'); + this.sandbox.stub(messenger, 'subscribe'); }); helper.after(); @@ -88,6 +93,7 @@ describe("TaskGraph Runner protocol functions", function () { it("should subscribe and receive cancelTaskGraph failures", function() { var graphId = uuid.v4(); + messenger.subscribe.restore(); messenger.request.rejects(sampleError); return taskgraphrunner.subscribeCancelTaskGraph(function(_graphId) { expect(_graphId).to.deep.equal(graphId); diff --git a/spec/lib/protocol/task-spec.js b/spec/lib/protocol/task-spec.js index 252e99e8..7a8e4ab0 100755 --- a/spec/lib/protocol/task-spec.js +++ b/spec/lib/protocol/task-spec.js @@ -22,11 +22,14 @@ describe("Task protocol functions", function() { testSubscription = new Subscription({},{}); testMessage = new Message({},{},{}); sinon.stub(testMessage); - sinon.stub(messenger); sinon.stub(testSubscription); sinon.stub(events); }); + beforeEach(function() { + this.sandbox.stub(messenger, 'request'); + this.sandbox.stub(messenger, 'publish'); + }); helper.after(); describe("Run", function() { diff --git a/spec/lib/protocol/waterline-spec.js b/spec/lib/protocol/waterline-spec.js index 7c7cceeb..d0f9859f 100755 --- a/spec/lib/protocol/waterline-spec.js +++ b/spec/lib/protocol/waterline-spec.js @@ -17,23 +17,18 @@ describe('Protocol.Waterline', function() { var Subscription = helper.injector.get('Subscription'); testSubscription = new Subscription({},{}); sinon.stub(testSubscription); - sinon.stub(messenger); }); helper.after(); it('should publish a created event', function() { - messenger.publish.resolves(); return waterlineProtocol.publishRecord(collection, 'created', { id: 1 }); }); - it('should publish an updated event', function() { - messenger.publish.resolves(); return waterlineProtocol.publishRecord(collection, 'updated', { id: 1 }); }); it('should publish a destroyed event', function() { - messenger.publish.resolves(); return waterlineProtocol.publishRecord(collection, 'destroyed', { id: 1 }); }); });