Skip to content

Commit 3e6f108

Browse files
committed
Fix the failing test.
1 parent f881286 commit 3e6f108

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

FirebasePerformance/Tests/Unit/FPRTraceBackgroundActivityTrackerTest.m

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,25 @@ - (void)testForegroundTracking {
3838

3939
/** Validates if the foreground & background state is captured correctly. */
4040
- (void)testBackgroundTracking {
41+
XCTestExpectation *expectation = [self expectationWithDescription:@"Application state change"];
42+
4143
FPRTraceBackgroundActivityTracker *tracker = [[FPRTraceBackgroundActivityTracker alloc] init];
4244
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
43-
[defaultCenter postNotificationName:UIApplicationDidBecomeActiveNotification
44-
object:[UIApplication sharedApplication]];
45-
[defaultCenter postNotificationName:UIApplicationDidEnterBackgroundNotification
46-
object:[UIApplication sharedApplication]];
47-
XCTAssertEqual(tracker.traceBackgroundState, FPRTraceStateBackgroundAndForeground);
45+
dispatch_async(dispatch_get_main_queue(), ^{
46+
[defaultCenter postNotificationName:UIApplicationDidBecomeActiveNotification
47+
object:[UIApplication sharedApplication]];
48+
[defaultCenter postNotificationName:UIApplicationDidEnterBackgroundNotification
49+
object:[UIApplication sharedApplication]];
50+
[expectation fulfill];
51+
});
52+
53+
[self waitForExpectationsWithTimeout:5.0 handler:^(NSError * _Nullable error) {
54+
if (error) {
55+
XCTFail(@"Expectation failed with error: %@", error);
56+
} else {
57+
XCTAssertEqual(tracker.traceBackgroundState, FPRTraceStateBackgroundAndForeground);
58+
}
59+
}];
4860
}
4961

5062
@end

0 commit comments

Comments
 (0)