Skip to content

Commit

Permalink
attempt to reproduce #8286
Browse files Browse the repository at this point in the history
  • Loading branch information
jmwski committed Sep 3, 2021
1 parent e480aaa commit 9234066
Showing 1 changed file with 64 additions and 1 deletion.
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,
FIRDatabaseReference* _Nonnull ref) {
XCTAssertNil(error);
done = YES;
}];

WAIT_FOR(done);
done = NO;

[[children childByAutoId] setValue:@{@"name" : @1}
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);

__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

0 comments on commit 9234066

Please sign in to comment.