Skip to content

Adding Limit/Limbo spec tests for go/index-free #1960

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 2 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
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
55 changes: 55 additions & 0 deletions packages/firestore/test/unit/specs/limbo_spec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,4 +434,59 @@ describeSpec('Limbo Documents:', [], () => {
.expectEvents(query, { removed: [docC] });
}
);

specTest('Limbo documents stay consistent between views', [], () => {
// This tests verifies that a document is consistent between views, even
// if the document is only in Limbo in one of them.
const originalQuery = Query.atPath(path('collection'));
const filteredQuery = Query.atPath(path('collection'))
.addFilter(filter('matches', '==', true));

const docA = doc('collection/a', 1000, { matches: true });
const docADirty = doc(
'collection/a',
1000,
{ matches: true },
{ hasCommittedMutations: true }
);
const docBDirty = doc(
'collection/b',
1001,
{ matches: true },
{ hasCommittedMutations: true }
);

return (
client(0)
.userSets('collection/a', { matches: true })
.userSets('collection/b', { matches: true })
.writeAcks('collection/a', 1000)
.writeAcks('collection/b', 1001)
.userListens(originalQuery)
.expectEvents(originalQuery, {
added: [docADirty, docBDirty],
fromCache: true
})
// Watch only includes docA in the result set, indicating that docB was
// modified out-of-band.
.watchAcksFull(originalQuery, 2000, docA)
.expectLimboDocs(docBDirty.key)
.userListens(filteredQuery)
.expectEvents(filteredQuery, {
added: [docA, docBDirty],
fromCache: true
})
.userUnlistens(originalQuery)
.expectLimboDocs()
// Re-run the query. Note that we still return the unresolved limbo
// document `docBCommitted`, since we haven't received the resolved
// document from Watch. Until we do, we return the version from cache
// even though the backend told it does not match.
.userListens(originalQuery, 'resume-token-2000')
.expectEvents(originalQuery, {
added: [docA, docBDirty],
fromCache: true
})
);
});
});
31 changes: 30 additions & 1 deletion packages/firestore/test/unit/specs/limit_spec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { Query } from '../../../src/core/query';
import { deletedDoc, doc, path } from '../../util/helpers';
import { deletedDoc, doc, filter, path } from '../../util/helpers';

import { describeSpec, specTest } from './describe_spec';
import { client, spec } from './spec_builder';
Expand Down Expand Up @@ -155,6 +155,35 @@ describeSpec('Limits:', [], () => {
}
);

specTest('Limits are re-filled from cache', [], () => {
// This test verifies that our Query handling backfills a limit query from
// cache even if the backend has not told us that an existing
// RemoteDocument is within the limit.
const fullQuery = Query.atPath(path('collection')).addFilter(
filter('matches', '==', true)
);
const limitQuery = Query.atPath(path('collection'))
.addFilter(filter('matches', '==', true))
.withLimit(2);
const doc1 = doc('collection/a', 1001, { matches: true });
const doc2 = doc('collection/b', 1002, { matches: true });
const doc3 = doc('collection/c', 1000, { matches: true });
return spec()
.withGCEnabled(false)
.userListens(fullQuery)
.watchAcksFull(fullQuery, 1002, doc1, doc2, doc3)
.expectEvents(fullQuery, { added: [doc1, doc2, doc3] })
.userUnlistens(fullQuery)
.userListens(limitQuery)
.expectEvents(limitQuery, { added: [doc1, doc2], fromCache: true })
.userSets('collection/a', { matches: false })
.expectEvents(limitQuery, {
added: [doc3],
removed: [doc1],
fromCache: true
});
});

specTest('Multiple docs in limbo in full limit query', [], () => {
const query1 = Query.atPath(path('collection')).withLimit(2);
const query2 = Query.atPath(path('collection'));
Expand Down
6 changes: 3 additions & 3 deletions packages/firestore/test/unit/specs/spec_test_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1021,11 +1021,11 @@ abstract class TestRunner {
);
});
for (const expectedLimboDoc of this.expectedLimboDocs) {
expect(
actualLimboDocs.get(expectedLimboDoc),
expect(actualLimboDocs.get(expectedLimboDoc)).to.not.equal(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI: Using equal makes the custom error message show up.

null,
'Expected doc to be in limbo, but was not: ' +
expectedLimboDoc.toString()
).to.be.ok;
);
actualLimboDocs = actualLimboDocs.remove(expectedLimboDoc);
}
expect(actualLimboDocs.size).to.equal(
Expand Down