@@ -1865,20 +1865,6 @@ describe('Change Streams', function () {
18651865 collection = client . db ( dbName ) . collection ( collectionName ) ;
18661866
18671867 changeStream = collection . watch ( [ ] ) ;
1868-
1869- // Configure a fail point with skip: 1 to simulate a server failure on the second `getMore`,
1870- // triggering the resume process.
1871- await client . db ( 'admin' ) . command ( {
1872- configureFailPoint : is4_2Server ( this . configuration . version )
1873- ? 'failCommand'
1874- : 'failGetMoreAfterCursorCheckout' ,
1875- mode : { skip : 1 } ,
1876- data : {
1877- failCommands : [ 'getMore' ] ,
1878- errorCode : resumableError . code ,
1879- errmsg : resumableError . message
1880- }
1881- } as FailCommandFailPoint ) ;
18821868 } ) ;
18831869
18841870 afterEach ( async function ( ) {
@@ -1905,6 +1891,18 @@ describe('Change Streams', function () {
19051891 fullDocument : { a : 1 }
19061892 } ) ;
19071893
1894+ await client . db ( 'admin' ) . command ( {
1895+ configureFailPoint : is4_2Server ( this . configuration . version )
1896+ ? 'failCommand'
1897+ : 'failGetMoreAfterCursorCheckout' ,
1898+ mode : { times : 1 } ,
1899+ data : {
1900+ failCommands : [ 'getMore' ] ,
1901+ errorCode : resumableError . code ,
1902+ errmsg : resumableError . message
1903+ }
1904+ } as FailCommandFailPoint ) ;
1905+
19081906 await collection . insertOne ( { a : 2 } ) ;
19091907 const change2 = await changeStream . next ( ) ;
19101908 expect ( change2 ) . to . containSubset ( {
@@ -1925,6 +1923,18 @@ describe('Change Streams', function () {
19251923 fullDocument : { a : 1 }
19261924 } ) ;
19271925
1926+ await client . db ( 'admin' ) . command ( {
1927+ configureFailPoint : is4_2Server ( this . configuration . version )
1928+ ? 'failCommand'
1929+ : 'failGetMoreAfterCursorCheckout' ,
1930+ mode : { times : 1 } ,
1931+ data : {
1932+ failCommands : [ 'getMore' ] ,
1933+ errorCode : resumableError . code ,
1934+ errmsg : resumableError . message
1935+ }
1936+ } as FailCommandFailPoint ) ;
1937+
19281938 await collection . insertOne ( { a : 2 } ) ;
19291939 const change2 = await changeStream . tryNext ( ) ;
19301940 expect ( change2 ) . to . containSubset ( {
@@ -1947,7 +1957,26 @@ describe('Change Streams', function () {
19471957 fullDocument : { a : 1 }
19481958 } ) ;
19491959
1960+ await client . db ( 'admin' ) . command ( {
1961+ configureFailPoint : is4_2Server ( this . configuration . version )
1962+ ? 'failCommand'
1963+ : 'failGetMoreAfterCursorCheckout' ,
1964+ mode : { times : 1 } ,
1965+ data : {
1966+ failCommands : [ 'getMore' ] ,
1967+ errorCode : resumableError . code ,
1968+ errmsg : resumableError . message
1969+ }
1970+ } as FailCommandFailPoint ) ;
1971+
1972+ // There's an inherent race condition here because we need to make sure that the `aggregates` that succeed when
1973+ // resuming a change stream don't return the change event.
1974+ // So we defer the insert until a period of time after the change stream has received the first change.
1975+ // 2000ms is long enough for the change stream to attempt to resume and fail once before exhausting the failpoint
1976+ // and succeeding.
1977+ await sleep ( 2000 ) ;
19501978 await collection . insertOne ( { a : 2 } ) ;
1979+
19511980 const change2 = await willBeChange . next ( ) ;
19521981 expect ( change2 . value [ 0 ] ) . to . containSubset ( {
19531982 operationType : 'insert' ,
0 commit comments