@@ -152,6 +152,21 @@ describe('Connect Tests', function () {
152
152
it ( 'connection instance has property socketTimeoutMS equal to the value passed in the connectOptions' , async ( ) => {
153
153
expect ( connection ) . to . have . property ( 'socketTimeoutMS' , 15000 ) ;
154
154
} ) ;
155
+
156
+ it ( 'cancels connecting if provided cancellationToken emits cancel' , async ( ) => {
157
+ // set no response handler for mock server, effectively black hole requests
158
+ server . setMessageHandler ( ( ) => null ) ;
159
+
160
+ const cancellationToken = new CancellationToken ( ) ;
161
+ setTimeout ( ( ) => cancellationToken . emit ( 'cancel' ) , 5 ) ;
162
+
163
+ const error = await promisify < Connection > ( callback =>
164
+ //@ts -expect-error: Callbacks do not have mutual exclusion for error/result existence
165
+ connect ( { ...connectOptions , cancellationToken } , callback )
166
+ ) ( ) . catch ( error => error ) ;
167
+
168
+ expect ( error ) . to . match ( / c o n n e c t i o n e s t a b l i s h m e n t w a s c a n c e l l e d / ) ;
169
+ } ) ;
155
170
} ) ;
156
171
157
172
it ( 'should emit `MongoNetworkError` for network errors' , function ( done ) {
@@ -161,19 +176,6 @@ describe('Connect Tests', function () {
161
176
} ) ;
162
177
} ) ;
163
178
164
- it . skip ( 'should allow a cancellaton token' , function ( done ) {
165
- const cancellationToken = new CancellationToken ( ) ;
166
- setTimeout ( ( ) => cancellationToken . emit ( 'cancel' ) , 500 ) ;
167
- // set no response handler for mock server, effectively black hole requests
168
-
169
- connect ( { hostAddress : new HostAddress ( '240.0.0.1' ) , cancellationToken } , ( err , conn ) => {
170
- expect ( err ) . to . exist ;
171
- expect ( err ) . to . match ( / c o n n e c t i o n e s t a b l i s h m e n t w a s c a n c e l l e d / ) ;
172
- expect ( conn ) . to . not . exist ;
173
- done ( ) ;
174
- } ) ;
175
- } ) . skipReason = 'TODO(NODE-2941): stop using 240.0.0.1 in tests' ;
176
-
177
179
context ( 'prepareHandshakeDocument' , ( ) => {
178
180
const prepareHandshakeDocument = promisify ( prepareHandshakeDocumentCb ) ;
179
181
0 commit comments