Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

Commit 5dafc86

Browse files
committedSep 16, 2017
fix(mock-tests): ensure all servers are properly cleaned up
NODE-1132
1 parent fc1d35e commit 5dafc86

File tree

4 files changed

+21
-22
lines changed

4 files changed

+21
-22
lines changed
 

‎test/tests/functional/mongos_mocks/multiple_proxies_tests.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ describe('Mongos Multiple Proxies (mocks)', function() {
201201
expect(___err).to.be.null;
202202
expect(___r.connection.port).to.equal(11003);
203203

204-
mock.cleanup([server2, mongos1, mongos2], () => done());
204+
mock.cleanup([server, server2, mongos1, mongos2], () => done());
205205
});
206206
});
207207
});

‎test/tests/functional/mongos_mocks/single_proxy_connection_tests.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe('Mongos Single Proxy Connection (mocks)', function() {
7171
});
7272

7373
// Attempt to connect
74-
var _server = new Mongos([{ host: 'localhost', port: 52017 }], {
74+
var mongos = new Mongos([{ host: 'localhost', port: 52017 }], {
7575
connectionTimeout: 3000,
7676
socketTimeout: 1000,
7777
haInterval: 500,
@@ -82,23 +82,23 @@ describe('Mongos Single Proxy Connection (mocks)', function() {
8282
var finished = false;
8383

8484
// Add event listeners
85-
_server.once('connect', function() {
85+
mongos.once('connect', function() {
8686
// Run an interval
8787
var intervalId = setInterval(function() {
88-
_server.insert('test.test', [{ created: new Date() }], function(err, r) {
88+
mongos.insert('test.test', [{ created: new Date() }], function(err, r) {
8989
if (r && !finished) {
9090
finished = true;
9191
clearInterval(intervalId);
9292
expect(r.connection.port).to.equal(52017);
9393

94-
mock.cleanup([server], () => done());
94+
mock.cleanup([mongos, server], () => done());
9595
}
9696
});
9797
}, 500);
9898
});
9999

100-
_server.on('error', done);
101-
_server.connect();
100+
mongos.on('error', done);
101+
mongos.connect();
102102
}
103103
});
104104

@@ -170,17 +170,17 @@ describe('Mongos Single Proxy Connection (mocks)', function() {
170170
});
171171

172172
// Attempt to connect
173-
var _server = new Mongos([{ host: 'localhost', port: 52018 }], {
173+
var mongos = new Mongos([{ host: 'localhost', port: 52018 }], {
174174
connectionTimeout: 30000,
175175
socketTimeout: 30000,
176176
haInterval: 500,
177177
size: 1
178178
});
179179

180180
// Add event listeners
181-
_server.once('connect', function() {
181+
mongos.once('connect', function() {
182182
// Execute find
183-
var cursor = _server.cursor('test.test', {
183+
var cursor = mongos.cursor('test.test', {
184184
find: 'test',
185185
query: {},
186186
batchSize: 2
@@ -195,14 +195,14 @@ describe('Mongos Single Proxy Connection (mocks)', function() {
195195
expect(_err).to.not.exist;
196196
expect(_d).to.exist;
197197

198-
mock.cleanup([server], () => done());
198+
mock.cleanup([mongos, server], () => done());
199199
});
200200
});
201201
});
202202

203-
_server.on('error', done);
203+
mongos.on('error', done);
204204
setTimeout(function() {
205-
_server.connect();
205+
mongos.connect();
206206
}, 100);
207207
}
208208
});

‎test/tests/functional/rs_mocks/primary_loses_network_tests.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var assign = require('../../../../lib/utils').assign,
66
ConnectionSpy = require('../shared').ConnectionSpy;
77

88
describe('ReplSet Primary Loses Network (mocks)', function() {
9-
it('Recover from Primary loosing network connectivity', {
9+
it('Recover from Primary losing network connectivity', {
1010
metadata: {
1111
requires: {
1212
generators: true,
@@ -150,7 +150,7 @@ describe('ReplSet Primary Loses Network (mocks)', function() {
150150
server.on('joined', function(__type, __server) {
151151
if (__type === 'primary' && __server.name === 'localhost:32002') {
152152
mock.cleanup(
153-
[primaryServer, firstSecondaryServer, secondSecondaryServer, __server],
153+
[server, primaryServer, firstSecondaryServer, secondSecondaryServer],
154154
spy,
155155
() => done()
156156
);

‎test/tests/functional/single_mocks/timeout_tests.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var expect = require('chai').expect,
33
assign = require('../../../../lib/utils').assign,
44
co = require('co'),
5-
mockupdb = require('../../../mock');
5+
mock = require('../../../mock');
66

77
describe('Single Timeout (mocks)', function() {
88
it('Should correctly timeout socket operation and then correctly re-execute', {
@@ -40,7 +40,7 @@ describe('Single Timeout (mocks)', function() {
4040

4141
// Boot the mock
4242
co(function*() {
43-
server = yield mockupdb.createServer(37019, 'localhost');
43+
server = yield mock.createServer(37019, 'localhost');
4444

4545
server.setMessageHandler(request => {
4646
var doc = request.document;
@@ -94,7 +94,7 @@ describe('Single Timeout (mocks)', function() {
9494
finished = true;
9595
expect(_r.connection.port).to.equal('37019');
9696
replset.destroy({ force: true });
97-
done();
97+
mock.cleanup([server], () => done());
9898
} else {
9999
wait();
100100
}
@@ -149,7 +149,7 @@ describe('Single Timeout (mocks)', function() {
149149
// Boot the mock
150150
var __server;
151151
co(function*() {
152-
__server = yield mockupdb.createServer(37017, 'localhost', {
152+
__server = yield mock.createServer(37017, 'localhost', {
153153
onRead: function(_server, connection) {
154154
// Force EPIPE error
155155
if (currentStep === 1) {
@@ -268,8 +268,7 @@ describe('Single Timeout (mocks)', function() {
268268
expect(r).to.exist;
269269
expect(brokenPipe).to.equal(true);
270270
_server.destroy();
271-
__server.destroy();
272-
done();
271+
mock.cleanup([__server, _server], () => done());
273272
});
274273
});
275274

@@ -315,7 +314,7 @@ describe('Single Timeout (mocks)', function() {
315314

316315
// Boot the mock
317316
co(function*() {
318-
server = yield mockupdb.createServer(37019, 'localhost');
317+
server = yield mock.createServer(37019, 'localhost');
319318

320319
server.setMessageHandler(request => {
321320
if (currentStep === 1) {

0 commit comments

Comments
 (0)
This repository has been archived.