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

Commit 6ece07b

Browse files
committed
fix(tests): Explicitly close driver connections ✅
1 parent aa24177 commit 6ece07b

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

test/connect.test.js

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,35 @@ describe('connection model connector', () => {
1515
this.slow(2000);
1616
this.timeout(10000);
1717

18-
before(require('mongodb-runner/mocha/before')({ port: 27018, version: '4.0.0' }));
18+
before(
19+
require('mongodb-runner/mocha/before')({ port: 27018, version: '4.0.0' })
20+
);
1921

20-
after(require('mongodb-runner/mocha/after')({ port: 27018, version: '4.0.0' }));
22+
after(
23+
require('mongodb-runner/mocha/after')({ port: 27018, version: '4.0.0' })
24+
);
2125

22-
it('should connect to `localhost:27018 with model`', (done) => {
26+
it('should connect to `localhost:27018 with model`', done => {
2327
Connection.from('mongodb://localhost:27018', (parseErr, model) => {
2428
assert.equal(parseErr, null);
25-
connect(model, setupListeners, (connectErr) => {
29+
connect(model, setupListeners, (connectErr, client) => {
2630
assert.equal(connectErr, null);
31+
client.close(true);
2732
done();
2833
});
2934
});
3035
});
3136

32-
it('should connect to `localhost:27018 with object`', (done) => {
33-
connect({port: 27018, host: 'localhost'}, setupListeners, (err) => {
34-
assert.equal(err, null);
35-
done();
36-
});
37+
it('should connect to `localhost:27018 with object`', done => {
38+
connect(
39+
{ port: 27018, host: 'localhost' },
40+
setupListeners,
41+
(err, client) => {
42+
assert.equal(err, null);
43+
client.close(true);
44+
done();
45+
}
46+
);
3747
});
3848

3949
describe('ssh tunnel failures', () => {
@@ -43,13 +53,13 @@ describe('connection model connector', () => {
4353
// simulate successful tunnel creation
4454
cb();
4555
// then return a mocked tunnel object with a spy close() function
46-
return {close: spy};
56+
return { close: spy };
4757
});
4858

4959
const MockConnection = mock.reRequire('../lib/extended-model');
5060
const mockConnect = mock.reRequire('../lib/connect');
5161

52-
it('should close ssh tunnel if the connection fails', (done) => {
62+
it('should close ssh tunnel if the connection fails', done => {
5363
const model = new MockConnection({
5464
hostname: 'localhost',
5565
port: '27017',
@@ -61,7 +71,7 @@ describe('connection model connector', () => {
6171
});
6272

6373
assert(model.isValid());
64-
mockConnect(model, setupListeners, (err) => {
74+
mockConnect(model, setupListeners, err => {
6575
// must throw error here, because the connection details are invalid
6676
assert.ok(err);
6777
assert.ok(/ECONNREFUSED/.test(err.reason));
@@ -77,27 +87,27 @@ describe('connection model connector', () => {
7787
this.slow(5000);
7888
this.timeout(10000);
7989

80-
data.MATRIX.map((d) => {
81-
it.skip('should connect to ' + d.name, (done) => {
82-
connect(d, setupListeners, (err, _db) => {
90+
data.MATRIX.map(d => {
91+
it.skip('should connect to ' + d.name, done => {
92+
connect(d, setupListeners, (err, client) => {
8393
if (err) {
8494
return done(err);
8595
}
8696

87-
_db.close();
97+
client.close(true);
8898
done();
8999
});
90100
});
91101
});
92102

93-
data.SSH_TUNNEL_MATRIX.map((d) => {
94-
it.skip(`connects via the sshTunnel to ${d.sshTunnelHostname}`, (done) => {
95-
connect(d, setupListeners, (err, _db) => {
103+
data.SSH_TUNNEL_MATRIX.map(d => {
104+
it.skip(`connects via the sshTunnel to ${d.sshTunnelHostname}`, done => {
105+
connect(d, setupListeners, (err, client) => {
96106
if (err) {
97107
return done(err);
98108
}
99109

100-
_db.close();
110+
client.close(true);
101111
done();
102112
});
103113
});

0 commit comments

Comments
 (0)