Skip to content

Commit 0bc236f

Browse files
Adding Limit/Limbo spec tests for go/index-free (#1960)
1 parent 493fe52 commit 0bc236f

File tree

3 files changed

+88
-4
lines changed

3 files changed

+88
-4
lines changed

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,4 +434,59 @@ describeSpec('Limbo Documents:', [], () => {
434434
.expectEvents(query, { removed: [docC] });
435435
}
436436
);
437+
438+
specTest('Limbo documents stay consistent between views', [], () => {
439+
// This tests verifies that a document is consistent between views, even
440+
// if the document is only in Limbo in one of them.
441+
const originalQuery = Query.atPath(path('collection'));
442+
const filteredQuery = Query.atPath(path('collection'))
443+
.addFilter(filter('matches', '==', true));
444+
445+
const docA = doc('collection/a', 1000, { matches: true });
446+
const docADirty = doc(
447+
'collection/a',
448+
1000,
449+
{ matches: true },
450+
{ hasCommittedMutations: true }
451+
);
452+
const docBDirty = doc(
453+
'collection/b',
454+
1001,
455+
{ matches: true },
456+
{ hasCommittedMutations: true }
457+
);
458+
459+
return (
460+
client(0)
461+
.userSets('collection/a', { matches: true })
462+
.userSets('collection/b', { matches: true })
463+
.writeAcks('collection/a', 1000)
464+
.writeAcks('collection/b', 1001)
465+
.userListens(originalQuery)
466+
.expectEvents(originalQuery, {
467+
added: [docADirty, docBDirty],
468+
fromCache: true
469+
})
470+
// Watch only includes docA in the result set, indicating that docB was
471+
// modified out-of-band.
472+
.watchAcksFull(originalQuery, 2000, docA)
473+
.expectLimboDocs(docBDirty.key)
474+
.userListens(filteredQuery)
475+
.expectEvents(filteredQuery, {
476+
added: [docA, docBDirty],
477+
fromCache: true
478+
})
479+
.userUnlistens(originalQuery)
480+
.expectLimboDocs()
481+
// Re-run the query. Note that we still return the unresolved limbo
482+
// document `docBCommitted`, since we haven't received the resolved
483+
// document from Watch. Until we do, we return the version from cache
484+
// even though the backend told it does not match.
485+
.userListens(originalQuery, 'resume-token-2000')
486+
.expectEvents(originalQuery, {
487+
added: [docA, docBDirty],
488+
fromCache: true
489+
})
490+
);
491+
});
437492
});

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import { Query } from '../../../src/core/query';
19-
import { deletedDoc, doc, path } from '../../util/helpers';
19+
import { deletedDoc, doc, filter, path } from '../../util/helpers';
2020

2121
import { describeSpec, specTest } from './describe_spec';
2222
import { client, spec } from './spec_builder';
@@ -155,6 +155,35 @@ describeSpec('Limits:', [], () => {
155155
}
156156
);
157157

158+
specTest('Limits are re-filled from cache', [], () => {
159+
// This test verifies that our Query handling backfills a limit query from
160+
// cache even if the backend has not told us that an existing
161+
// RemoteDocument is within the limit.
162+
const fullQuery = Query.atPath(path('collection')).addFilter(
163+
filter('matches', '==', true)
164+
);
165+
const limitQuery = Query.atPath(path('collection'))
166+
.addFilter(filter('matches', '==', true))
167+
.withLimit(2);
168+
const doc1 = doc('collection/a', 1001, { matches: true });
169+
const doc2 = doc('collection/b', 1002, { matches: true });
170+
const doc3 = doc('collection/c', 1000, { matches: true });
171+
return spec()
172+
.withGCEnabled(false)
173+
.userListens(fullQuery)
174+
.watchAcksFull(fullQuery, 1002, doc1, doc2, doc3)
175+
.expectEvents(fullQuery, { added: [doc1, doc2, doc3] })
176+
.userUnlistens(fullQuery)
177+
.userListens(limitQuery)
178+
.expectEvents(limitQuery, { added: [doc1, doc2], fromCache: true })
179+
.userSets('collection/a', { matches: false })
180+
.expectEvents(limitQuery, {
181+
added: [doc3],
182+
removed: [doc1],
183+
fromCache: true
184+
});
185+
});
186+
158187
specTest('Multiple docs in limbo in full limit query', [], () => {
159188
const query1 = Query.atPath(path('collection')).withLimit(2);
160189
const query2 = Query.atPath(path('collection'));

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,11 +1021,11 @@ abstract class TestRunner {
10211021
);
10221022
});
10231023
for (const expectedLimboDoc of this.expectedLimboDocs) {
1024-
expect(
1025-
actualLimboDocs.get(expectedLimboDoc),
1024+
expect(actualLimboDocs.get(expectedLimboDoc)).to.not.equal(
1025+
null,
10261026
'Expected doc to be in limbo, but was not: ' +
10271027
expectedLimboDoc.toString()
1028-
).to.be.ok;
1028+
);
10291029
actualLimboDocs = actualLimboDocs.remove(expectedLimboDoc);
10301030
}
10311031
expect(actualLimboDocs.size).to.equal(

0 commit comments

Comments
 (0)