@@ -278,6 +278,52 @@ describe('Initiate Connect Test', function() {
278278 connection . connect ( ) ;
279279 } ) ;
280280
281+ it ( 'should clear timeouts when failing to connect' , function ( done ) {
282+ const connection = new Connection ( {
283+ server : 'something.invalid' ,
284+ options : { connectTimeout : 30000 } ,
285+ } ) ;
286+
287+ connection . on ( 'connect' , ( err ) => {
288+ try {
289+ assert . instanceOf ( err , ConnectionError ) ;
290+ assert . strictEqual ( /** @type {ConnectionError } */ ( err ) . code , 'ESOCKET' ) ;
291+ assert . strictEqual ( connection . connectTimer , undefined ) ;
292+ done ( ) ;
293+ } catch ( e ) {
294+ done ( e ) ;
295+ }
296+ } ) ;
297+
298+ connection . on ( 'error' , done ) ;
299+ connection . connect ( ) ;
300+
301+ assert . isOk ( connection . connectTimer ) ;
302+ } ) ;
303+
304+ it ( 'should clear timeouts when failing to connect to named instance' , function ( done ) {
305+ const connection = new Connection ( {
306+ server : 'something.invalid' ,
307+ options : {
308+ instanceName : 'inst' ,
309+ connectTimeout : 30000 ,
310+ } ,
311+ } ) ;
312+
313+ connection . on ( 'connect' , ( err ) => {
314+ assert . instanceOf ( err , ConnectionError ) ;
315+ assert . strictEqual ( /** @type {ConnectionError } */ ( err ) . code , 'EINSTLOOKUP' ) ;
316+ assert . strictEqual ( connection . connectTimer , undefined ) ;
317+
318+ done ( ) ;
319+ } ) ;
320+
321+ connection . on ( 'error' , done ) ;
322+ connection . connect ( ) ;
323+
324+ assert . isOk ( connection . connectTimer ) ;
325+ } ) ;
326+
281327 it ( 'should fail if no cipher can be negotiated' , function ( done ) {
282328 const config = getConfig ( ) ;
283329 config . options . encrypt = true ;
0 commit comments