@@ -14,6 +14,7 @@ import {
1414 type CommandStartedEvent ,
1515 type Db ,
1616 isHello ,
17+ LEGACY_HELLO_COMMAND ,
1718 Long ,
1819 MongoAPIError ,
1920 MongoChangeStreamError ,
@@ -1818,7 +1819,7 @@ describe('Change Streams', function () {
18181819 } ) ;
18191820} ) ;
18201821
1821- describe ( 'ChangeStream resumability' , function ( ) {
1822+ describe . only ( 'ChangeStream resumability' , function ( ) {
18221823 let client : MongoClient ;
18231824 let collection : Collection ;
18241825 let changeStream : ChangeStream ;
@@ -2045,6 +2046,65 @@ describe('ChangeStream resumability', function () {
20452046 expect ( changeStream . closed ) . to . be . true ;
20462047 } ) ;
20472048 } ) ;
2049+
2050+ context . only ( 'when the error is not a server error' , function ( ) {
2051+ let client1 : MongoClient ;
2052+ let client2 : MongoClient ;
2053+
2054+ beforeEach ( async function ( ) {
2055+ client1 = this . configuration . newClient (
2056+ { } ,
2057+ { serverSelectionTimeoutMS : 1000 , appName : 'client-errors' }
2058+ ) ;
2059+ client2 = this . configuration . newClient ( ) ;
2060+
2061+ collection = client1 . db ( 'client-errors' ) . collection ( 'test' ) ;
2062+ } ) ;
2063+
2064+ afterEach ( async function ( ) {
2065+ await client2 . db ( 'admin' ) . command ( {
2066+ configureFailPoint : 'failCommand' ,
2067+ mode : 'off' ,
2068+ data : { appName : 'client-errors' }
2069+ } as FailCommandFailPoint ) ;
2070+
2071+ await client1 ?. close ( ) ;
2072+ await client2 ?. close ( ) ;
2073+ } ) ;
2074+
2075+ it (
2076+ 'should resume on ServerSelectionError' ,
2077+ { requires : { topology : '!single' } } ,
2078+ async function ( ) {
2079+ changeStream = collection . watch ( [ ] ) ;
2080+ await initIteratorMode ( changeStream ) ;
2081+
2082+ await collection . insertOne ( { a : 1 } ) ;
2083+
2084+ await client2 . db ( 'admin' ) . command ( {
2085+ configureFailPoint : 'failCommand' ,
2086+ mode : 'alwaysOn' ,
2087+ data : {
2088+ failCommands : [ 'ping' , 'hello' , LEGACY_HELLO_COMMAND ] ,
2089+ closeConnection : true ,
2090+ handshakeCommands : true ,
2091+ failInternalCommands : true ,
2092+ appName : 'client-errors'
2093+ }
2094+ } as FailCommandFailPoint ) ;
2095+ await client2
2096+ . db ( 'admin' )
2097+ . command ( { replSetFreeze : 0 } , { readPreference : ReadPreference . secondary } ) ;
2098+ await client2
2099+ . db ( 'admin' )
2100+ . command ( { replSetStepDown : 15 , secondaryCatchUpPeriodSecs : 10 , force : true } ) ;
2101+ // await sleep(15_000);
2102+
2103+ const change = await changeStream . next ( ) ;
2104+ expect ( change ) . to . containSubset ( { operationType : 'insert' , fullDocument : { a : 1 } } ) ;
2105+ }
2106+ ) ;
2107+ } ) ;
20482108 } ) ;
20492109
20502110 context ( '#hasNext' , function ( ) {
0 commit comments