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

Commit ccde817

Browse files
committed
test(operations): use connection spy for accounting
1 parent 68a6656 commit ccde817

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

Diff for: test/tests/functional/operations_tests.js

+19-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
'use strict';
22

3-
var expect = require('chai').expect,
4-
f = require('util').format;
3+
const expect = require('chai').expect;
4+
const f = require('util').format;
5+
const mock = require('mongodb-mock-server');
6+
const ConnectionSpy = require('./shared').ConnectionSpy;
7+
const Connection = require('../../../lib/connection/connection');
58

9+
const test = {};
610
describe('Operation tests', function() {
11+
beforeEach(() => {
12+
test.spy = new ConnectionSpy();
13+
Connection.enableConnectionAccounting(test.spy);
14+
});
15+
16+
afterEach(() => {
17+
return mock.cleanup(test.spy).then(() => {
18+
test.spy = undefined;
19+
Connection.disableConnectionAccounting();
20+
});
21+
});
22+
723
it('should correctly connect using server object', {
824
metadata: {
925
requires: { topology: ['single', 'replicaset', 'sharded'] }
@@ -547,8 +563,6 @@ describe('Operation tests', function() {
547563

548564
test: function(done) {
549565
var self = this;
550-
var Connection = require('../../../lib/connection/connection');
551-
552566
self.configuration.newTopology(function(err, server) {
553567
// console.log('================ -- 1')
554568
// Add event listeners
@@ -563,9 +577,6 @@ describe('Operation tests', function() {
563577
// Number of operations left
564578
if (left === 0) {
565579
self.configuration.newTopology(function(topologyErr, innerServer) {
566-
// Enable connections accounting
567-
Connection.enableConnectionAccounting();
568-
569580
// Add event listeners
570581
innerServer.on('connect', function(_innerServer) {
571582
_innerServer.command(
@@ -576,12 +587,7 @@ describe('Operation tests', function() {
576587
expect(result.result.n).to.equal(100);
577588

578589
_innerServer.destroy();
579-
580-
setTimeout(function() {
581-
expect(Object.keys(Connection.connections()).length).to.equal(0);
582-
Connection.disableConnectionAccounting();
583-
done();
584-
}, 1000);
590+
done();
585591
}
586592
);
587593
});

0 commit comments

Comments
 (0)