Skip to content

Modify spec test to demonstrate deletedDoc issue. #1017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions packages/firestore/test/unit/specs/listen_spec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,50 @@ describeSpec('Listens:', [], () => {
);
});

specTest('Individual (deleted) documents cannot revert', [], () => {
const allQuery = Query.atPath(path('collection'));
const visibleQuery = Query.atPath(path('collection')).addFilter(
filter('visible', '==', true)
);
const docAv1 = doc('collection/a', 1000, { visible: true, v: 'v1000' });
const docAv2 = doc('collection/a', 2000, { visible: false, v: 'v2000' });
const docAv3 = deletedDoc('collection/a', 3000);

return (
spec()
// Disable GC so the cache persists across listens.
.withGCEnabled(false)
.userListens(visibleQuery)
.watchAcksFull(visibleQuery, 1000, docAv1)
.expectEvents(visibleQuery, { added: [docAv1] })
.userUnlistens(visibleQuery)
.watchRemoves(visibleQuery)
.userListens(allQuery)
.expectEvents(allQuery, { added: [docAv1], fromCache: true })
.watchAcks(allQuery)
.watchSends( { removed: [allQuery]}, docAv3)
.watchCurrents(allQuery, 'resume-token-3000')
.watchSnapshots(3000)
.expectEvents(allQuery, { removed: [docAv1], fromCache: false })
.userUnlistens(allQuery)
.watchRemoves(allQuery)
// Supposing we sent a resume token for visibleQuery, watch could catch
// us up to docAV2 since that's the last relevant change to the query
// (the document falls out) and send us a snapshot that's ahead of
// docAv3 (which is already in our cache).
.userListens(visibleQuery, 'resume-token-1000')
.watchAcksFull(visibleQuery, 5000, docAv2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think Watch can ever send CURRENT to a query and not also send the last version of a document. We should receive v3 before we get CURRENT - even if the document doesn't match anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the question we need Jonny or somebody from watch to answer. If that's true, it would make life much easier... but 1) I'm not sure how watch can guarantee that if it's using a per-target change log to catch us up, and 2) these spec tests (I just copied the one above) seem to specifically be assuming that watch can send us a CURRENT after only giving us the latest version that affected the query.

.expectEvents(visibleQuery, { fromCache: false })
.userUnlistens(visibleQuery)
.watchRemoves(visibleQuery)
// Listen to allQuery again and make sure we still get no docs.
.userListens(allQuery, 'resume-token-4000')
.expectEvents(allQuery, { fromCache: true })
.watchAcksFull(allQuery, 6000)
.expectEvents(allQuery, { fromCache: false })
);
});

specTest('Deleted documents in cache are fixed', [], () => {
const allQuery = Query.atPath(path('collection'));
const docAv1 = doc('collection/a', 1000, { key: 'a' });
Expand Down