1
1
'use strict' ;
2
2
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' ) ;
5
8
9
+ const test = { } ;
6
10
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
+
7
23
it ( 'should correctly connect using server object' , {
8
24
metadata : {
9
25
requires : { topology : [ 'single' , 'replicaset' , 'sharded' ] }
@@ -547,8 +563,6 @@ describe('Operation tests', function() {
547
563
548
564
test : function ( done ) {
549
565
var self = this ;
550
- var Connection = require ( '../../../lib/connection/connection' ) ;
551
-
552
566
self . configuration . newTopology ( function ( err , server ) {
553
567
// console.log('================ -- 1')
554
568
// Add event listeners
@@ -563,9 +577,6 @@ describe('Operation tests', function() {
563
577
// Number of operations left
564
578
if ( left === 0 ) {
565
579
self . configuration . newTopology ( function ( topologyErr , innerServer ) {
566
- // Enable connections accounting
567
- Connection . enableConnectionAccounting ( ) ;
568
-
569
580
// Add event listeners
570
581
innerServer . on ( 'connect' , function ( _innerServer ) {
571
582
_innerServer . command (
@@ -576,12 +587,7 @@ describe('Operation tests', function() {
576
587
expect ( result . result . n ) . to . equal ( 100 ) ;
577
588
578
589
_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 ( ) ;
585
591
}
586
592
) ;
587
593
} ) ;
0 commit comments