@@ -1865,20 +1865,6 @@ describe('Change Streams', function () {
1865
1865
collection = client . db ( dbName ) . collection ( collectionName ) ;
1866
1866
1867
1867
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 ) ;
1882
1868
} ) ;
1883
1869
1884
1870
afterEach ( async function ( ) {
@@ -1905,6 +1891,18 @@ describe('Change Streams', function () {
1905
1891
fullDocument : { a : 1 }
1906
1892
} ) ;
1907
1893
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
+
1908
1906
await collection . insertOne ( { a : 2 } ) ;
1909
1907
const change2 = await changeStream . next ( ) ;
1910
1908
expect ( change2 ) . to . containSubset ( {
@@ -1925,6 +1923,18 @@ describe('Change Streams', function () {
1925
1923
fullDocument : { a : 1 }
1926
1924
} ) ;
1927
1925
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
+
1928
1938
await collection . insertOne ( { a : 2 } ) ;
1929
1939
const change2 = await changeStream . tryNext ( ) ;
1930
1940
expect ( change2 ) . to . containSubset ( {
@@ -1947,7 +1957,26 @@ describe('Change Streams', function () {
1947
1957
fullDocument : { a : 1 }
1948
1958
} ) ;
1949
1959
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 ) ;
1950
1978
await collection . insertOne ( { a : 2 } ) ;
1979
+
1951
1980
const change2 = await willBeChange . next ( ) ;
1952
1981
expect ( change2 . value [ 0 ] ) . to . containSubset ( {
1953
1982
operationType : 'insert' ,
0 commit comments