Skip to content
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

attempt to reproduce #8286 #8618

Closed
wants to merge 1 commit into from
Closed
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
65 changes: 64 additions & 1 deletion FirebaseDatabase/Tests/Integration/FIRDatabaseQueryTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

#import "FirebaseDatabase/Tests/Integration/FIRDatabaseQueryTests.h"
#import "FirebaseCore/Sources/Public/FirebaseCore/FIROptions.h"
//#import "FirebaseCore/Sources/Public/FirebaseCore/FIROptions.h" doesn't work with swift?
#import "FirebaseDatabase/Sources/Api/Private/FIRDatabaseQuery_Private.h"
#import "FirebaseDatabase/Sources/Constants/FConstants.h"
#import "FirebaseDatabase/Sources/Core/FQuerySpec.h"
Expand Down Expand Up @@ -4468,4 +4468,67 @@ - (void)testGetSkipsPersistenceCacheWhenOnline {
WAIT_FOR(done);
}

- (void)testGetTriggersListener {
FIRDatabase* db = [self databaseForURL:self.databaseURL name:@"fir-multi-shards"];

FIRDatabaseReference* ref = [db referenceWithPath:@"james"];
FIRDatabaseReference* children = [ref child:@"children"];

__block BOOL done = NO;

[children removeValueWithCompletionBlock:^(NSError* _Nullable error,
Copy link
Contributor

Choose a reason for hiding this comment

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

You could use an autoId instead of children (via [FTestHelpers getRandomNode]). Then you won't have to do a delete.

FIRDatabaseReference* _Nonnull ref) {
XCTAssertNil(error);
done = YES;
}];

WAIT_FOR(done);
done = NO;

[[children childByAutoId] setValue:@{@"name" : @1}
Copy link
Contributor

Choose a reason for hiding this comment

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

One difference between this test and the issue is that the test does not write values from the same instance, but rather all values exist on the backend. We can emulate this using a reader/writer test setup.

withCompletionBlock:^(NSError* error, FIRDatabaseReference* ref) {
XCTAssertNil(error);
done = YES;
}];

WAIT_FOR(done);
done = NO;

[[children childByAutoId] setValue:@{@"name" : @2}
withCompletionBlock:^(NSError* error, FIRDatabaseReference* ref) {
XCTAssertNil(error);
done = YES;
}];

WAIT_FOR(done);
done = NO;

__block BOOL nextDone = NO;

[children observeEventType:FIRDataEventTypeValue
withBlock:^(FIRDataSnapshot* snapshot) {
if (done == YES) {
XCTAssertTrue(snapshot.childrenCount == 2U);
nextDone = YES;
return;
}
XCTAssertTrue(snapshot.childrenCount == 2U);
done = YES;
}];

WAIT_FOR(done);
Copy link
Contributor

Choose a reason for hiding this comment

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

The original repo also does not wait for "done". It runs both operation in parallel.


__block BOOL getDone = NO;

[[[children queryOrderedByChild:@"name"] queryEqualToValue:@2]
getDataWithCompletionBlock:^(NSError* _Nullable error, FIRDataSnapshot* _Nonnull snapshot) {
XCTAssertNil(error);
XCTAssertTrue([snapshot exists]);
getDone = YES;
}];

WAIT_FOR(getDone);
// WAIT_FOR(nextDone); // when uncommented, test times out.
}

@end