@@ -5,6 +5,7 @@ const { connect } = require('../../../src/cmap/connect');
55const { Connection } = require ( '../../../src/cmap/connection' ) ;
66const { expect } = require ( 'chai' ) ;
77const { ns } = require ( '../../../src/utils' ) ;
8+ const { getSymbolFrom } = require ( '../../tools/utils' ) ;
89
910describe ( 'Connection - unit/cmap' , function ( ) {
1011 let server ;
@@ -58,4 +59,51 @@ describe('Connection - unit/cmap', function () {
5859 } ) ;
5960 } ) ;
6061 } ) ;
62+
63+ it ( 'should throw a network error with kBeforeHandshake set to false on timeout after hand shake' , function ( done ) {
64+ server . setMessageHandler ( request => {
65+ const doc = request . document ;
66+ if ( doc . ismaster || doc . hello ) {
67+ request . reply ( mock . DEFAULT_ISMASTER_36 ) ;
68+ }
69+ // respond to no other requests to trigger timeout event
70+ } ) ;
71+
72+ const options = {
73+ hostAddress : server . hostAddress ( )
74+ } ;
75+
76+ connect ( options , ( err , conn ) => {
77+ expect ( err ) . to . be . a ( 'undefined' ) ;
78+ expect ( conn ) . to . be . instanceOf ( Connection ) ;
79+ expect ( conn ) . to . have . property ( 'ismaster' ) . that . is . a ( 'object' ) ;
80+
81+ conn . command ( ns ( '$admin.cmd' ) , { ping : 1 } , { socketTimeoutMS : 50 } , err => {
82+ const beforeHandshakeSymbol = getSymbolFrom ( err , 'beforeHandshake' , false ) ;
83+ expect ( beforeHandshakeSymbol ) . to . be . a ( 'symbol' ) ;
84+ expect ( err ) . to . have . property ( beforeHandshakeSymbol , false ) ;
85+
86+ done ( ) ;
87+ } ) ;
88+ } ) ;
89+ } ) ;
90+
91+ it ( 'should throw a network error with kBeforeHandshake set to true on timeout before hand shake' , function ( done ) {
92+ // respond to no requests to trigger timeout event
93+ server . setMessageHandler ( ( ) => { } ) ;
94+
95+ const options = {
96+ hostAddress : server . hostAddress ( ) ,
97+ socketTimeoutMS : 50
98+ } ;
99+
100+ connect ( options , ( err , conn ) => {
101+ expect ( conn ) . to . be . a ( 'undefined' ) ;
102+
103+ const beforeHandshakeSymbol = getSymbolFrom ( err , 'beforeHandshake' ) ;
104+ expect ( err ) . to . have . property ( beforeHandshakeSymbol , true ) ;
105+
106+ done ( ) ;
107+ } ) ;
108+ } ) ;
61109} ) ;
0 commit comments