Skip to content

Improve the integration test coverage for online vs offline comparisons. #8975

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 4 commits into from
Apr 28, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ apiDescribe('Composite Index Queries', persistence => {
return testHelper.withTestDocs(persistence, testDocs, async coll => {
// a == 1, limit 2, b - desc
await testHelper.assertOnlineAndOfflineResultsMatch(
coll,
testHelper.query(
coll,
where('a', '==', 1),
Expand All @@ -97,6 +98,7 @@ apiDescribe('Composite Index Queries', persistence => {
return testHelper.withTestDocs(persistence, testDocs, async coll => {
// with one inequality: a>2 || b==1.
await testHelper.assertOnlineAndOfflineResultsMatch(
coll,
testHelper.compositeQuery(
coll,
or(where('a', '>', 2), where('b', '==', 1))
Expand All @@ -108,6 +110,7 @@ apiDescribe('Composite Index Queries', persistence => {

// Test with limits (implicit order by ASC): (a==1) || (b > 0) LIMIT 2
await testHelper.assertOnlineAndOfflineResultsMatch(
coll,
testHelper.compositeQuery(
coll,
or(where('a', '==', 1), where('b', '>', 0)),
Expand All @@ -120,6 +123,7 @@ apiDescribe('Composite Index Queries', persistence => {
// Test with limits (explicit order by): (a==1) || (b > 0) LIMIT_TO_LAST 2
// Note: The public query API does not allow implicit ordering when limitToLast is used.
await testHelper.assertOnlineAndOfflineResultsMatch(
coll,
testHelper.compositeQuery(
coll,
or(where('a', '==', 1), where('b', '>', 0)),
Expand All @@ -132,6 +136,7 @@ apiDescribe('Composite Index Queries', persistence => {

// Test with limits (explicit order by ASC): (a==2) || (b == 1) ORDER BY a LIMIT 1
await testHelper.assertOnlineAndOfflineResultsMatch(
coll,
testHelper.compositeQuery(
coll,
or(where('a', '==', 2), where('b', '==', 1)),
Expand All @@ -143,6 +148,7 @@ apiDescribe('Composite Index Queries', persistence => {

// Test with limits (explicit order by DESC): (a==2) || (b == 1) ORDER BY a LIMIT_TO_LAST 1
await testHelper.assertOnlineAndOfflineResultsMatch(
coll,
testHelper.compositeQuery(
coll,
or(where('a', '==', 2), where('b', '==', 1)),
Expand Down Expand Up @@ -857,12 +863,14 @@ apiDescribe('Composite Index Queries', persistence => {
return testHelper.withTestDocs(persistence, testDocs, async coll => {
// implicit AND: a != 1 && b < 2
await testHelper.assertOnlineAndOfflineResultsMatch(
coll,
testHelper.query(coll, where('a', '!=', 1), where('b', '<', 2)),
'doc2'
);

// explicit AND: a != 1 && b < 2
await testHelper.assertOnlineAndOfflineResultsMatch(
coll,
testHelper.compositeQuery(
coll,
and(where('a', '!=', 1), where('b', '<', 2))
Expand All @@ -873,6 +881,7 @@ apiDescribe('Composite Index Queries', persistence => {
// explicit AND: a < 3 && b not-in [2, 3]
// Implicitly ordered by: a asc, b asc, __name__ asc
await testHelper.assertOnlineAndOfflineResultsMatch(
coll,
testHelper.compositeQuery(
coll,
and(where('a', '<', 3), where('b', 'not-in', [2, 3]))
Expand All @@ -884,6 +893,7 @@ apiDescribe('Composite Index Queries', persistence => {

// a <3 && b != 0, implicitly ordered by: a asc, b asc, __name__ asc
await testHelper.assertOnlineAndOfflineResultsMatch(
coll,
testHelper.query(
coll,
where('b', '!=', 0),
Expand All @@ -896,6 +906,7 @@ apiDescribe('Composite Index Queries', persistence => {

// a <3 && b != 0, ordered by: b desc, a desc, __name__ desc
await testHelper.assertOnlineAndOfflineResultsMatch(
coll,
testHelper.query(
coll,
where('a', '<', 3),
Expand All @@ -909,6 +920,7 @@ apiDescribe('Composite Index Queries', persistence => {

// explicit OR: multiple inequality: a>2 || b<1.
await testHelper.assertOnlineAndOfflineResultsMatch(
coll,
testHelper.compositeQuery(
coll,
or(where('a', '>', 2), where('b', '<', 1))
Expand Down
40 changes: 34 additions & 6 deletions packages/firestore/test/integration/api/database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,14 +780,19 @@ apiDescribe('Database', persistence => {

return withTestCollection(persistence, docs, async randomCol => {
const orderedQuery = query(randomCol, orderBy('embedding'));
await checkOnlineAndOfflineResultsMatch(orderedQuery, ...documentIds);
await checkOnlineAndOfflineResultsMatch(
randomCol,
orderedQuery,
...documentIds
);

const orderedQueryLessThan = query(
randomCol,
orderBy('embedding'),
where('embedding', '<', vector([1, 2, 100, 4, 4]))
);
await checkOnlineAndOfflineResultsMatch(
randomCol,
orderedQueryLessThan,
...documentIds.slice(2, 11)
);
Expand All @@ -798,6 +803,7 @@ apiDescribe('Database', persistence => {
where('embedding', '>', vector([1, 2, 100, 4, 4]))
);
await checkOnlineAndOfflineResultsMatch(
randomCol,
orderedQueryGreaterThan,
...documentIds.slice(12, 13)
);
Expand Down Expand Up @@ -2396,6 +2402,7 @@ apiDescribe('Database', persistence => {
'a'
];
await checkOnlineAndOfflineResultsMatch(
collectionRef,
orderedQuery,
...expectedDocs
);
Expand All @@ -2416,6 +2423,7 @@ apiDescribe('Database', persistence => {
'Aa'
];
await checkOnlineAndOfflineResultsMatch(
collectionRef,
filteredQuery,
...expectedDocs
);
Expand Down Expand Up @@ -2467,7 +2475,11 @@ apiDescribe('Database', persistence => {

unsubscribe();

await checkOnlineAndOfflineResultsMatch(orderedQuery, ...expectedDocs);
await checkOnlineAndOfflineResultsMatch(
collectionRef,
orderedQuery,
...expectedDocs
);
});
});

Expand Down Expand Up @@ -2499,7 +2511,11 @@ apiDescribe('Database', persistence => {

unsubscribe();

await checkOnlineAndOfflineResultsMatch(orderedQuery, ...expectedDocs);
await checkOnlineAndOfflineResultsMatch(
collectionRef,
orderedQuery,
...expectedDocs
);
});
});

Expand Down Expand Up @@ -2531,7 +2547,11 @@ apiDescribe('Database', persistence => {

unsubscribe();

await checkOnlineAndOfflineResultsMatch(orderedQuery, ...expectedDocs);
await checkOnlineAndOfflineResultsMatch(
collectionRef,
orderedQuery,
...expectedDocs
);
});
});

Expand Down Expand Up @@ -2563,7 +2583,11 @@ apiDescribe('Database', persistence => {

unsubscribe();

await checkOnlineAndOfflineResultsMatch(orderedQuery, ...expectedDocs);
await checkOnlineAndOfflineResultsMatch(
collectionRef,
orderedQuery,
...expectedDocs
);
});
});

Expand Down Expand Up @@ -2608,7 +2632,11 @@ apiDescribe('Database', persistence => {

unsubscribe();

await checkOnlineAndOfflineResultsMatch(orderedQuery, ...expectedDocs);
await checkOnlineAndOfflineResultsMatch(
collectionRef,
orderedQuery,
...expectedDocs
);
});
});

Expand Down
Loading
Loading