@@ -66,4 +66,62 @@ describe('Connection', function() {
66
66
}
67
67
) ;
68
68
} ) ;
69
+
70
+ it ( 'should throw a network error with kBeforeHandshake set to false on timeout after hand shake' , function ( done ) {
71
+ server . setMessageHandler ( request => {
72
+ const doc = request . document ;
73
+ if ( doc . ismaster ) {
74
+ request . reply ( mock . DEFAULT_ISMASTER_36 ) ;
75
+ }
76
+ // respond to no other requests to trigger timeout event
77
+ } ) ;
78
+
79
+ const address = server . address ( ) ;
80
+ const options = {
81
+ bson : new BSON ( ) ,
82
+ connectionType : Connection ,
83
+ host : address . host ,
84
+ port : address . port
85
+ } ;
86
+
87
+ connect ( options , ( err , conn ) => {
88
+ expect ( err ) . to . be . a ( 'undefined' ) ;
89
+ expect ( conn ) . to . be . instanceOf ( Connection ) ;
90
+ expect ( conn )
91
+ . to . have . property ( 'ismaster' )
92
+ . that . is . a ( 'object' ) ;
93
+
94
+ conn . command ( '$admin.cmd' , { ping : 1 } , { socketTimeout : 50 } , err => {
95
+ const beforeHandshakeSymbol = Object . getOwnPropertySymbols ( err ) [ 0 ] ;
96
+ expect ( beforeHandshakeSymbol ) . to . be . a ( 'symbol' ) ;
97
+ expect ( err ) . to . have . property ( beforeHandshakeSymbol , false ) ;
98
+
99
+ done ( ) ;
100
+ } ) ;
101
+ } ) ;
102
+ } ) ;
103
+
104
+ it ( 'should throw a network error with kBeforeHandshake set to true on timeout before hand shake' , function ( done ) {
105
+ // respond to no requests to trigger timeout event
106
+ server . setMessageHandler ( ( ) => { } ) ;
107
+
108
+ const address = server . address ( ) ;
109
+ const options = {
110
+ bson : new BSON ( ) ,
111
+ connectionType : Connection ,
112
+ host : address . host ,
113
+ port : address . port ,
114
+ socketTimeout : 50
115
+ } ;
116
+
117
+ connect ( options , ( err , conn ) => {
118
+ expect ( conn ) . to . be . a ( 'undefined' ) ;
119
+
120
+ const beforeHandshakeSymbol = Object . getOwnPropertySymbols ( err ) [ 0 ] ;
121
+ expect ( beforeHandshakeSymbol ) . to . be . a ( 'symbol' ) ;
122
+ expect ( err ) . to . have . property ( beforeHandshakeSymbol , true ) ;
123
+
124
+ done ( ) ;
125
+ } ) ;
126
+ } ) ;
69
127
} ) ;
0 commit comments