Skip to content

Make initial view test actually use index-free queries #2051

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 5 commits into from
Aug 9, 2019
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
78 changes: 77 additions & 1 deletion packages/firestore/test/unit/specs/limit_spec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ describeSpec('Limits:', [], () => {
});

specTest(
'Initial snapshots for limit queries are re-filled from cache',
'Initial snapshots for limit queries are re-filled from cache (with removal)',
[],
() => {
// Verify that views for limit queries are re-filled even if the initial
Expand All @@ -205,8 +205,84 @@ describeSpec('Limits:', [], () => {
.watchAcksFull(fullQuery, 1003, doc1, doc2, doc3)
.expectEvents(fullQuery, { added: [doc1, doc2, doc3] })
.userUnlistens(fullQuery)
.userListens(limitQuery)
.expectEvents(limitQuery, { added: [doc1, doc2], fromCache: true })
.watchAcksFull(limitQuery, 1004, doc1, doc2)
.expectEvents(limitQuery, {})
.userUnlistens(limitQuery)
.watchRemoves(limitQuery)
.userSets('collection/a', { matches: false })
.userListens(limitQuery, 'resume-token-1004')
.expectEvents(limitQuery, { added: [doc2, doc3], fromCache: true });
}
);

specTest(
'Initial snapshots for limit queries are re-filled from cache (with latency-compensated edit)',
[],
() => {
// Verify that views for limit queries contain the correct set of documents
// even if a previously matching document receives a latency-compensate update
// that makes it sort below an older document.
const fullQuery = Query.atPath(path('collection'));
const limitQuery = Query.atPath(path('collection'))
.addOrderBy(orderBy('pos'))
.withLimit(2);
const doc1 = doc('collection/a', 1001, { pos: 1 });
const doc2 = doc('collection/b', 1002, { pos: 2 });
const doc3 = doc('collection/c', 1003, { pos: 3 });
return spec()
.withGCEnabled(false)
.userListens(fullQuery)
.watchAcksFull(fullQuery, 1003, doc1, doc2, doc3)
.expectEvents(fullQuery, { added: [doc1, doc2, doc3] })
.userUnlistens(fullQuery)
.watchRemoves(fullQuery)
.userListens(limitQuery)
.expectEvents(limitQuery, { added: [doc1, doc2], fromCache: true })
.watchAcksFull(limitQuery, 1004, doc1, doc2)
.expectEvents(limitQuery, {})
.userUnlistens(limitQuery)
.watchRemoves(limitQuery)
.userSets('collection/a', { pos: 4 })
.userListens(limitQuery, 'resume-token-1004')
.expectEvents(limitQuery, { added: [doc2, doc3], fromCache: true });
}
);

specTest(
'Initial snapshots for limit queries are re-filled from cache (with update from backend)',
[],
() => {
// Verify that views for limit queries contain the correct set of documents
// even if a previously matching document receives an update from the backend
// that makes it sort below an older document.
const fullQuery = Query.atPath(path('collection'));
const limitQuery = Query.atPath(path('collection'))
.addOrderBy(orderBy('pos'))
.withLimit(2);
const doc1 = doc('collection/a', 1001, { pos: 1 });
const doc1Edited = doc('collection/a', 1005, { pos: 4 });
const doc2 = doc('collection/b', 1002, { pos: 2 });
const doc3 = doc('collection/c', 1003, { pos: 3 });
return spec()
.withGCEnabled(false)
.userListens(fullQuery)
.watchAcksFull(fullQuery, 1003, doc1, doc2, doc3)
.expectEvents(fullQuery, { added: [doc1, doc2, doc3] })
.userUnlistens(fullQuery)
.watchRemoves(fullQuery)
.userListens(limitQuery)
.expectEvents(limitQuery, { added: [doc1, doc2], fromCache: true })
.watchAcksFull(limitQuery, 1004, doc1, doc2)
.expectEvents(limitQuery, {})
.userUnlistens(limitQuery)
.watchRemoves(limitQuery)
.userListens(fullQuery, 'resume-token-1003')
.expectEvents(fullQuery, { added: [doc1, doc2, doc3], fromCache: true })
.watchAcksFull(fullQuery, 1005, doc1Edited)
.expectEvents(fullQuery, { modified: [doc1Edited] })
.userListens(limitQuery, 'resume-token-1004')
.expectEvents(limitQuery, { added: [doc2, doc3], fromCache: true });
}
);
Expand Down