Skip to content

Commit 69c3e4b

Browse files
authored
Add an integration test for callbacks on the main thread (#6054)
1 parent 2ceb9d6 commit 69c3e4b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Firestore/Example/Tests/Integration/API/FIRDatabaseTests.mm

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,30 @@ - (void)testListenerCallbackCanCallRemoveWithoutBlocking {
15921592
XCTAssertEqualObjects(steps, @"12");
15931593
}
15941594

1595+
- (void)testListenerCallbacksHappenOnMainThread {
1596+
// Verify that callbacks occur on the main thread if settings.dispatchQueue is not specified.
1597+
XCTestExpectation *invoked = [self expectationWithDescription:@"listener invoked"];
1598+
invoked.assertForOverFulfill = false;
1599+
1600+
FIRDocumentReference *doc = [self documentRef];
1601+
[self writeDocumentRef:doc data:@{@"foo" : @"bar"}];
1602+
1603+
__block bool callbackThreadIsMainThread;
1604+
__block NSString *callbackThreadDescription;
1605+
1606+
[doc addSnapshotListener:^(FIRDocumentSnapshot *, NSError *) {
1607+
callbackThreadIsMainThread = NSThread.isMainThread;
1608+
callbackThreadDescription = [NSString stringWithFormat:@"%@", NSThread.currentThread];
1609+
[invoked fulfill];
1610+
}];
1611+
1612+
[self awaitExpectation:invoked];
1613+
XCTAssertTrue(callbackThreadIsMainThread,
1614+
@"The listener callback was expected to occur on the main thread, but instead it "
1615+
@"occurred on the thread %@",
1616+
callbackThreadDescription);
1617+
}
1618+
15951619
- (void)testWaitForPendingWritesCompletes {
15961620
FIRDocumentReference *doc = [self documentRef];
15971621
FIRFirestore *firestore = doc.firestore;

0 commit comments

Comments
 (0)