@@ -185,7 +185,7 @@ describeSpec('Limits:', [], () => {
185
185
} ) ;
186
186
187
187
specTest (
188
- 'Initial snapshots for limit queries are re-filled from cache' ,
188
+ 'Initial snapshots for limit queries are re-filled from cache (with removal) ' ,
189
189
[ ] ,
190
190
( ) => {
191
191
// Verify that views for limit queries are re-filled even if the initial
@@ -205,8 +205,84 @@ describeSpec('Limits:', [], () => {
205
205
. watchAcksFull ( fullQuery , 1003 , doc1 , doc2 , doc3 )
206
206
. expectEvents ( fullQuery , { added : [ doc1 , doc2 , doc3 ] } )
207
207
. userUnlistens ( fullQuery )
208
+ . userListens ( limitQuery )
209
+ . expectEvents ( limitQuery , { added : [ doc1 , doc2 ] , fromCache : true } )
210
+ . watchAcksFull ( limitQuery , 1004 , doc1 , doc2 )
211
+ . expectEvents ( limitQuery , { } )
212
+ . userUnlistens ( limitQuery )
213
+ . watchRemoves ( limitQuery )
208
214
. userSets ( 'collection/a' , { matches : false } )
215
+ . userListens ( limitQuery , 'resume-token-1004' )
216
+ . expectEvents ( limitQuery , { added : [ doc2 , doc3 ] , fromCache : true } ) ;
217
+ }
218
+ ) ;
219
+
220
+ specTest (
221
+ 'Initial snapshots for limit queries are re-filled from cache (with latency-compensated edit)' ,
222
+ [ ] ,
223
+ ( ) => {
224
+ // Verify that views for limit queries contain the correct set of documents
225
+ // even if a previously matching document receives a latency-compensate update
226
+ // that makes it sort below an older document.
227
+ const fullQuery = Query . atPath ( path ( 'collection' ) ) ;
228
+ const limitQuery = Query . atPath ( path ( 'collection' ) )
229
+ . addOrderBy ( orderBy ( 'pos' ) )
230
+ . withLimit ( 2 ) ;
231
+ const doc1 = doc ( 'collection/a' , 1001 , { pos : 1 } ) ;
232
+ const doc2 = doc ( 'collection/b' , 1002 , { pos : 2 } ) ;
233
+ const doc3 = doc ( 'collection/c' , 1003 , { pos : 3 } ) ;
234
+ return spec ( )
235
+ . withGCEnabled ( false )
236
+ . userListens ( fullQuery )
237
+ . watchAcksFull ( fullQuery , 1003 , doc1 , doc2 , doc3 )
238
+ . expectEvents ( fullQuery , { added : [ doc1 , doc2 , doc3 ] } )
239
+ . userUnlistens ( fullQuery )
240
+ . watchRemoves ( fullQuery )
241
+ . userListens ( limitQuery )
242
+ . expectEvents ( limitQuery , { added : [ doc1 , doc2 ] , fromCache : true } )
243
+ . watchAcksFull ( limitQuery , 1004 , doc1 , doc2 )
244
+ . expectEvents ( limitQuery , { } )
245
+ . userUnlistens ( limitQuery )
246
+ . watchRemoves ( limitQuery )
247
+ . userSets ( 'collection/a' , { pos : 4 } )
248
+ . userListens ( limitQuery , 'resume-token-1004' )
249
+ . expectEvents ( limitQuery , { added : [ doc2 , doc3 ] , fromCache : true } ) ;
250
+ }
251
+ ) ;
252
+
253
+ specTest (
254
+ 'Initial snapshots for limit queries are re-filled from cache (with update from backend)' ,
255
+ [ ] ,
256
+ ( ) => {
257
+ // Verify that views for limit queries contain the correct set of documents
258
+ // even if a previously matching document receives an update from the backend
259
+ // that makes it sort below an older document.
260
+ const fullQuery = Query . atPath ( path ( 'collection' ) ) ;
261
+ const limitQuery = Query . atPath ( path ( 'collection' ) )
262
+ . addOrderBy ( orderBy ( 'pos' ) )
263
+ . withLimit ( 2 ) ;
264
+ const doc1 = doc ( 'collection/a' , 1001 , { pos : 1 } ) ;
265
+ const doc1Edited = doc ( 'collection/a' , 1005 , { pos : 4 } ) ;
266
+ const doc2 = doc ( 'collection/b' , 1002 , { pos : 2 } ) ;
267
+ const doc3 = doc ( 'collection/c' , 1003 , { pos : 3 } ) ;
268
+ return spec ( )
269
+ . withGCEnabled ( false )
270
+ . userListens ( fullQuery )
271
+ . watchAcksFull ( fullQuery , 1003 , doc1 , doc2 , doc3 )
272
+ . expectEvents ( fullQuery , { added : [ doc1 , doc2 , doc3 ] } )
273
+ . userUnlistens ( fullQuery )
274
+ . watchRemoves ( fullQuery )
209
275
. userListens ( limitQuery )
276
+ . expectEvents ( limitQuery , { added : [ doc1 , doc2 ] , fromCache : true } )
277
+ . watchAcksFull ( limitQuery , 1004 , doc1 , doc2 )
278
+ . expectEvents ( limitQuery , { } )
279
+ . userUnlistens ( limitQuery )
280
+ . watchRemoves ( limitQuery )
281
+ . userListens ( fullQuery , 'resume-token-1003' )
282
+ . expectEvents ( fullQuery , { added : [ doc1 , doc2 , doc3 ] , fromCache : true } )
283
+ . watchAcksFull ( fullQuery , 1005 , doc1Edited )
284
+ . expectEvents ( fullQuery , { modified : [ doc1Edited ] } )
285
+ . userListens ( limitQuery , 'resume-token-1004' )
210
286
. expectEvents ( limitQuery , { added : [ doc2 , doc3 ] , fromCache : true } ) ;
211
287
}
212
288
) ;
0 commit comments