@@ -37,6 +37,55 @@ exports['Should correctly connect pool to single server'] = {
37
37
}
38
38
}
39
39
40
+ exports [ 'Should only listen on connect once' ] = {
41
+ metadata : { requires : { topology : "single" } } ,
42
+
43
+ test : function ( configuration , test ) {
44
+ var Pool = require ( '../../../lib/connection/pool' )
45
+ , Connection = require ( '../../../lib/connection/connection' )
46
+ , bson = require ( 'bson' ) ;
47
+
48
+ // Enable connections accounting
49
+ Connection . enableConnectionAccounting ( ) ;
50
+
51
+ // Attempt to connect
52
+ var pool = new Pool ( {
53
+ host : configuration . host
54
+ , port : configuration . port
55
+ , bson : new bson ( )
56
+ , messageHandler : function ( ) { }
57
+ } ) ;
58
+
59
+ var connection ;
60
+
61
+ // Add event listeners
62
+ pool . on ( 'connect' , function ( _pool ) {
63
+ process . nextTick ( ( ) => {
64
+ // Now that we are in next tick, connection should still exist, but there
65
+ // should be no connect listeners
66
+ test . equal ( 0 , connection . connection . listenerCount ( 'connect' ) ) ;
67
+ test . equal ( 1 , pool . allConnections ( ) . length ) ;
68
+
69
+ _pool . destroy ( ) ;
70
+
71
+ // Connection should be gone after destroy
72
+ test . equal ( 0 , pool . allConnections ( ) . length ) ;
73
+ Connection . disableConnectionAccounting ( ) ;
74
+ test . done ( ) ;
75
+ } ) ;
76
+ } ) ;
77
+
78
+ test . equal ( 0 , pool . allConnections ( ) . length ) ;
79
+
80
+ // Start connection
81
+ pool . connect ( ) ;
82
+
83
+ test . equal ( 1 , pool . allConnections ( ) . length ) ;
84
+ connection = pool . allConnections ( ) [ 0 ] ;
85
+ test . equal ( 1 , connection . connection . listenerCount ( 'connect' ) ) ;
86
+ }
87
+ }
88
+
40
89
exports [ 'Should properly emit errors on forced destroy' ] = {
41
90
metadata : { requires : { topology : "single" } } ,
42
91
0 commit comments