Skip to content

Commit 448c522

Browse files
committed
Write a spec test for the busted cache
1 parent 6905339 commit 448c522

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

packages/firestore/test/unit/specs/listen_spec.test.ts

+31
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,37 @@ describeSpec('Listens:', [], () => {
283283
);
284284
});
285285

286+
specTest('Deleted documents in cache are fixed', [], () => {
287+
const allQuery = Query.atPath(path('collection'));
288+
const docAv1 = doc('collection/a', 1000, { key: 'a' });
289+
const docDeleted = deletedDoc('collection/a', 2000);
290+
291+
return (
292+
spec()
293+
// Presuppose an initial state where the remote document cache has a
294+
// broken synthesized delete at a timestamp later than the true version
295+
// of the document. This requires both adding and later removing the
296+
// document in order to force the watch change aggregator to propagate
297+
// the deletion.
298+
.withGCEnabled(false)
299+
.userListens(allQuery)
300+
.watchAcksFull(allQuery, 1000, docAv1)
301+
.expectEvents(allQuery, { added: [docAv1], fromCache: false })
302+
.watchSends({ removed: [allQuery] }, docDeleted)
303+
.watchSnapshots(2000, [allQuery], 'resume-token-2000')
304+
.watchSnapshots(2000)
305+
.expectEvents(allQuery, { removed: [docAv1], fromCache: false })
306+
.userUnlistens(allQuery)
307+
.watchRemoves(allQuery)
308+
309+
// Now when the client listens expect the cached NoDocument to be
310+
// discarded because the global snapshot version exceeds what came before.
311+
.userListens(allQuery, 'resume-token-2000')
312+
.watchAcksFull(allQuery, 3000, docAv1)
313+
.expectEvents(allQuery, { added: [docAv1], fromCache: false })
314+
);
315+
});
316+
286317
specTest('Listens are reestablished after network disconnect', [], () => {
287318
const expectRequestCount = requestCounts =>
288319
requestCounts.addTarget + requestCounts.removeTarget;

0 commit comments

Comments
 (0)