@@ -6,7 +6,9 @@ var expect = require('chai').expect,
66 Pool = require ( '../../../lib/connection/pool' ) ,
77 Connection = require ( '../../../lib/connection/connection' ) ,
88 Query = require ( '../../../lib/connection/commands' ) . Query ,
9- Bson = require ( 'bson' ) ;
9+ Bson = require ( 'bson' ) ,
10+ co = require ( 'co' ) ,
11+ mock = require ( '../../mock' ) ;
1012
1113describe ( 'Pool tests' , function ( ) {
1214 it . skip ( 'should correctly connect pool to single server' , {
@@ -1183,4 +1185,64 @@ describe('Pool tests', function() {
11831185 pool . connect ( ) ;
11841186 }
11851187 } ) ;
1188+
1189+ it ( 'should remove all connections from further use during reauthentication of a pool' , {
1190+ metadata : { requires : { topology : 'single' } } ,
1191+
1192+ test : function ( done ) {
1193+ co ( function * ( ) {
1194+ const server = yield mock . createServer ( 37017 , 'localhost' ) ;
1195+ server . setMessageHandler ( request => {
1196+ var doc = request . document ;
1197+ if ( doc . getnonce ) {
1198+ request . reply ( { ok : 1 , result : { nonce : 'testing' } } ) ;
1199+ } else if ( doc . authenticate ) {
1200+ request . reply ( { ok : 1 } ) ;
1201+ } else if ( doc . ismaster ) {
1202+ setTimeout ( ( ) => request . reply ( { ok : 1 } ) , 10000 ) ;
1203+ }
1204+ } ) ;
1205+
1206+ var pool = new Pool ( null , {
1207+ host : 'localhost' ,
1208+ port : 37017 ,
1209+ bson : new Bson ( ) ,
1210+ size : 10
1211+ } ) ;
1212+
1213+ var query = new Query (
1214+ new Bson ( ) ,
1215+ 'system.$cmd' ,
1216+ { ismaster : true } ,
1217+ { numberToSkip : 0 , numberToReturn : 1 }
1218+ ) ;
1219+
1220+ pool . on ( 'connect' , function ( ) {
1221+ pool . write ( query , { monitoring : true } , function ( ) { } ) ;
1222+
1223+ setTimeout ( function ( ) {
1224+ pool . auth ( 'mongocr' , 'test' , 'admin' , 'admin' , function ( err ) {
1225+ expect ( err ) . to . not . exist ;
1226+
1227+ // ensure that there are no duplicates in the available connection queue
1228+ var availableIds = pool . availableConnections . map ( conn => conn . id ) ;
1229+ availableIds . forEach ( function ( id , pos , arr ) {
1230+ expect ( arr . indexOf ( id ) ) . to . equal ( pos ) ;
1231+ } ) ;
1232+
1233+ expect ( pool . availableConnections ) . to . have . length ( 1 ) ;
1234+ expect ( pool . inUseConnections ) . to . have . length ( 0 ) ;
1235+
1236+ pool . destroy ( true ) ;
1237+ expect ( Object . keys ( Connection . connections ( ) ) ) . to . have . length ( 0 ) ;
1238+ Connection . disableConnectionAccounting ( ) ;
1239+ done ( ) ;
1240+ } ) ;
1241+ } , 500 ) ;
1242+ } ) ;
1243+
1244+ pool . connect ( ) ;
1245+ } ) ;
1246+ }
1247+ } ) ;
11861248} ) ;
0 commit comments