File tree Expand file tree Collapse file tree 1 file changed +17
-5
lines changed
FirebasePerformance/Tests/Unit Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments