@@ -4796,6 +4796,10 @@ describe("index", () => {
47964796 } ) ;
47974797
47984798 it ( "outOfOrder mode=drop can collect dropped items" , async function ( ) {
4799+ // Under full CI load, push iterators can briefly yield empty batches. Drain the
4800+ // in-order items first so the iterator frontier is established before inserting
4801+ // the late item, and bound the wait on the callback so the suite cannot hang.
4802+ this . timeout ( 80_000 ) ;
47994803 session = await TestSession . disconnected ( 3 ) ;
48004804 await session . connect ( [
48014805 [ session . peers [ 0 ] , session . peers [ 1 ] ] ,
@@ -4851,11 +4855,38 @@ describe("index", () => {
48514855 try {
48524856 await writer . docs . put ( new Document ( { id : "2" } ) ) ;
48534857 await writer . docs . put ( new Document ( { id : "3" } ) ) ;
4854- await iterator . next ( 10 ) ;
4858+ const seen = new Set < string > ( ) ;
4859+ const start = Date . now ( ) ;
4860+ while (
4861+ Date . now ( ) - start < 10_000 &&
4862+ ( ! seen . has ( "2" ) || ! seen . has ( "3" ) )
4863+ ) {
4864+ const batch = await iterator . next ( 10 ) ;
4865+ for ( const doc of batch ) {
4866+ seen . add ( doc . id ) ;
4867+ }
4868+ if ( ! seen . has ( "2" ) || ! seen . has ( "3" ) ) {
4869+ await delay ( 50 ) ;
4870+ }
4871+ }
4872+ expect ( [ ...seen ] ) . to . include ( "2" ) ;
4873+ expect ( [ ...seen ] ) . to . include ( "3" ) ;
4874+
4875+ await waitForResolved (
4876+ async ( ) => expect ( await iterator . pending ( ) ) . to . equal ( 0 ) ,
4877+ { timeout : 10_000 , delayInterval : 50 } ,
4878+ ) ;
48554879
48564880 await writer . docs . put ( new Document ( { id : "1" } ) ) ;
48574881
4858- await latePromise . promise ;
4882+ await Promise . race ( [
4883+ latePromise . promise ,
4884+ delay ( 20_000 ) . then ( ( ) => {
4885+ throw new Error (
4886+ "Timed out waiting for outOfOrder(drop) handler" ,
4887+ ) ;
4888+ } ) ,
4889+ ] ) ;
48594890 expect ( collected ?. length ) . to . equal ( 1 ) ;
48604891 expect (
48614892 collected ?. [ 0 ] ?. value ?. id || collected ?. [ 0 ] ?. indexed ?. id ,
0 commit comments