Skip to content

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

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
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -122,9 +122,12 @@ - (NSString *)toHashedId:(NSString *)docId {
// Asserts that the result of running the query while online (against the backend/emulator) is
// the same as running it while offline. The expected document Ids are hashed to match the
// actual document IDs created by the test helper.
- (void)assertOnlineAndOfflineResultsMatch:(FIRQuery *)query
- (void)assertOnlineAndOfflineResultsMatch:(FIRCollectionReference *)collection
withQuery:(FIRQuery *)query
expectedDocs:(NSArray<NSString *> *)expectedDocs {
[self checkOnlineAndOfflineQuery:query matchesResult:[self toHashedIds:expectedDocs]];
[self checkOnlineAndOfflineCollection:collection
query:query
matchesResult:[self toHashedIds:expectedDocs]];
}

// Asserts that the IDs in the query snapshot matches the expected Ids. The expected document
Expand Down Expand Up @@ -219,7 +222,8 @@ - (void)testOrQueriesWithCompositeIndexes {
[FIRFilter filterWhereField:@"a" isGreaterThan:@2], [FIRFilter filterWhereField:@"b"
isEqualTo:@1]
]]];
[self assertOnlineAndOfflineResultsMatch:[self compositeIndexQuery:query1]
[self assertOnlineAndOfflineResultsMatch:collRef
withQuery:[self compositeIndexQuery:query1]
expectedDocs:@[ @"doc5", @"doc2", @"doc3" ]];

// Test with limits (implicit order by ASC): (a==1) || (b > 0) LIMIT 2
Expand All @@ -228,7 +232,8 @@ - (void)testOrQueriesWithCompositeIndexes {
[FIRFilter filterWhereField:@"a" isEqualTo:@1], [FIRFilter filterWhereField:@"b"
isGreaterThan:@0]
]]];
[self assertOnlineAndOfflineResultsMatch:[[self compositeIndexQuery:query2] queryLimitedTo:2]
[self assertOnlineAndOfflineResultsMatch:collRef
withQuery:[[self compositeIndexQuery:query2] queryLimitedTo:2]
expectedDocs:@[ @"doc1", @"doc2" ]];

// Test with limits (explicit order by): (a==1) || (b > 0) LIMIT_TO_LAST 2
Expand All @@ -238,7 +243,8 @@ - (void)testOrQueriesWithCompositeIndexes {
[FIRFilter filterWhereField:@"a" isEqualTo:@1], [FIRFilter filterWhereField:@"b"
isGreaterThan:@0]
]]];
[self assertOnlineAndOfflineResultsMatch:[[[self compositeIndexQuery:query3] queryLimitedToLast:2]
[self assertOnlineAndOfflineResultsMatch:collRef
withQuery:[[[self compositeIndexQuery:query3] queryLimitedToLast:2]
queryOrderedByField:@"b"]
expectedDocs:@[ @"doc3", @"doc4" ]];

Expand All @@ -248,7 +254,8 @@ - (void)testOrQueriesWithCompositeIndexes {
[FIRFilter filterWhereField:@"a" isEqualTo:@2], [FIRFilter filterWhereField:@"b"
isEqualTo:@1]
]]];
[self assertOnlineAndOfflineResultsMatch:[[[self compositeIndexQuery:query4] queryLimitedTo:1]
[self assertOnlineAndOfflineResultsMatch:collRef
withQuery:[[[self compositeIndexQuery:query4] queryLimitedTo:1]
queryOrderedByField:@"a"]
expectedDocs:@[ @"doc5" ]];

Expand All @@ -258,7 +265,8 @@ - (void)testOrQueriesWithCompositeIndexes {
[FIRFilter filterWhereField:@"a" isEqualTo:@2], [FIRFilter filterWhereField:@"b"
isEqualTo:@1]
]]];
[self assertOnlineAndOfflineResultsMatch:[[[self compositeIndexQuery:query5] queryLimitedToLast:1]
[self assertOnlineAndOfflineResultsMatch:collRef
withQuery:[[[self compositeIndexQuery:query5] queryLimitedToLast:1]
queryOrderedByField:@"a"]
expectedDocs:@[ @"doc2" ]];
}
Expand Down Expand Up @@ -886,7 +894,8 @@ - (void)testMultipleInequalityFromCacheAndFromServer {
// implicit AND: a != 1 && b < 2
FIRQuery *query = [[collRef queryWhereField:@"a" isNotEqualTo:@1] queryWhereField:@"b"
isLessThan:@2];
[self assertOnlineAndOfflineResultsMatch:[self compositeIndexQuery:query]
[self assertOnlineAndOfflineResultsMatch:collRef
withQuery:[self compositeIndexQuery:query]
expectedDocs:@[ @"doc2" ]];

// explicit AND: a != 1 && b < 2
Expand All @@ -895,7 +904,8 @@ - (void)testMultipleInequalityFromCacheAndFromServer {
[FIRFilter filterWhereField:@"a" isNotEqualTo:@1], [FIRFilter filterWhereField:@"b"
isLessThan:@2]
]]];
[self assertOnlineAndOfflineResultsMatch:[self compositeIndexQuery:query]
[self assertOnlineAndOfflineResultsMatch:collRef
withQuery:[self compositeIndexQuery:query]
expectedDocs:@[ @"doc2" ]];

// explicit AND: a < 3 && b not-in [2, 3]
Expand All @@ -905,14 +915,16 @@ - (void)testMultipleInequalityFromCacheAndFromServer {
[FIRFilter filterWhereField:@"a" isLessThan:@3], [FIRFilter filterWhereField:@"b"
notIn:@[ @2, @3 ]]
]]];
[self assertOnlineAndOfflineResultsMatch:[self compositeIndexQuery:query]
[self assertOnlineAndOfflineResultsMatch:collRef
withQuery:[self compositeIndexQuery:query]
expectedDocs:@[ @"doc1", @"doc5", @"doc2" ]];

// a <3 && b != 0, ordered by: b desc, a desc, __name__ desc
query = [[[[collRef queryWhereField:@"a" isLessThan:@3] queryWhereField:@"b" isNotEqualTo:@0]
queryOrderedByField:@"b"
descending:YES] queryLimitedTo:2];
[self assertOnlineAndOfflineResultsMatch:[self compositeIndexQuery:query]
[self assertOnlineAndOfflineResultsMatch:collRef
withQuery:[self compositeIndexQuery:query]
expectedDocs:@[ @"doc4", @"doc2" ]];

// explicit OR: a>2 || b<1.
Expand All @@ -921,7 +933,8 @@ - (void)testMultipleInequalityFromCacheAndFromServer {
[FIRFilter filterWhereField:@"a" isGreaterThan:@2], [FIRFilter filterWhereField:@"b"
isLessThan:@1]
]]];
[self assertOnlineAndOfflineResultsMatch:[self compositeIndexQuery:query]
[self assertOnlineAndOfflineResultsMatch:collRef
withQuery:[self compositeIndexQuery:query]
expectedDocs:@[ @"doc1", @"doc3" ]];
}

Expand Down
Loading
Loading