@@ -6,6 +6,7 @@ const ConnectionPool = require('../../../lib/cmap/connection_pool').ConnectionPo
6
6
const EventEmitter = require ( 'events' ) . EventEmitter ;
7
7
const mock = require ( 'mongodb-mock-server' ) ;
8
8
const BSON = require ( 'bson' ) ;
9
+ const cmapEvents = require ( '../../../lib/cmap/events' ) ;
9
10
10
11
const chai = require ( 'chai' ) ;
11
12
chai . use ( require ( '../../functional/spec-runner/matcher' ) . default ) ;
@@ -115,6 +116,35 @@ describe('Connection Pool', function() {
115
116
cb ( new Error ( 'my great error' ) ) ;
116
117
} , callback ) ;
117
118
} ) ;
119
+
120
+ it ( 'should still manage a connection if no callback is provided' , function ( done ) {
121
+ server . setMessageHandler ( request => {
122
+ const doc = request . document ;
123
+ if ( doc . ismaster ) {
124
+ request . reply ( mock . DEFAULT_ISMASTER_36 ) ;
125
+ }
126
+ } ) ;
127
+
128
+ const pool = new ConnectionPool (
129
+ Object . assign ( { bson : new BSON ( ) , maxPoolSize : 1 } , server . address ( ) )
130
+ ) ;
131
+
132
+ const events = [ ] ;
133
+ pool . on ( 'connectionCheckedOut' , event => events . push ( event ) ) ;
134
+ pool . on ( 'connectionCheckedIn' , event => {
135
+ events . push ( event ) ;
136
+
137
+ expect ( events ) . to . have . length ( 2 ) ;
138
+ expect ( events [ 0 ] ) . to . be . instanceOf ( cmapEvents . ConnectionCheckedOutEvent ) ;
139
+ expect ( events [ 1 ] ) . to . be . instanceOf ( cmapEvents . ConnectionCheckedInEvent ) ;
140
+ pool . close ( done ) ;
141
+ } ) ;
142
+
143
+ pool . withConnection ( ( err , conn , cb ) => {
144
+ expect ( err ) . to . not . exist ;
145
+ cb ( ) ;
146
+ } ) ;
147
+ } ) ;
118
148
} ) ;
119
149
120
150
describe ( 'spec tests' , function ( ) {
0 commit comments