@@ -5,6 +5,7 @@ const { connect } = require('../../../src/cmap/connect');
5
5
const { Connection } = require ( '../../../src/cmap/connection' ) ;
6
6
const { expect } = require ( 'chai' ) ;
7
7
const { ns } = require ( '../../../src/utils' ) ;
8
+ const { getSymbolFrom } = require ( '../../tools/utils' ) ;
8
9
9
10
describe ( 'Connection - unit/cmap' , function ( ) {
10
11
let server ;
@@ -58,4 +59,51 @@ describe('Connection - unit/cmap', function () {
58
59
} ) ;
59
60
} ) ;
60
61
} ) ;
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
+ } ) ;
61
109
} ) ;
0 commit comments