@@ -175,17 +175,15 @@ - (void) testRemoteLogLevels {
175175
176176 // Set the remote log level to Debug.
177177 [NRLogger setRemoteLogLevel: NRLogLevelDebug];
178-
179- // Set up the expectation
180- XCTestExpectation *fileWrittenExpectation = [self expectationWithDescription: @" File has been modified" ];
181178
179+ __block BOOL operationCompleted = NO ;
182180 __block int count = 0 ;
183181 dispatch_source_set_event_handler (self.source , ^{
184182 count++;
185183 if (count == 7 ){
186184 // Fulfill the expectation when a write is detected
187185 sleep (1 );
188- [fileWrittenExpectation fulfill ] ;
186+ operationCompleted = YES ;
189187 }
190188 });
191189
@@ -206,13 +204,16 @@ - (void) testRemoteLogLevels {
206204 @" additionalAttribute1" : @" attribute1" ,
207205 @" additionalAttribute2" : @" attribute2"
208206 }];
209-
210- [self waitForExpectationsWithTimeout: 30 handler: ^(NSError * _Nullable error) {
211- if (error) {
212- // Handle timeout here
213- NSLog (@" Timeout occurred, but the test will not fail." );
214- }
215- }];
207+
208+ // Set a timeout duration
209+ NSTimeInterval timeout = 30.0 ;
210+ NSDate *timeoutDate = [NSDate dateWithTimeIntervalSinceNow: timeout];
211+
212+ // Run the run loop until the operation completes or the timeout is reached
213+ while (!operationCompleted && [timeoutDate timeIntervalSinceNow ] > 0 ) {
214+ // Allow other scheduled run loop activities to proceed
215+ [[NSRunLoop currentRunLoop ] runMode: NSDefaultRunLoopMode beforeDate: [NSDate dateWithTimeIntervalSinceNow: 0.1 ]];
216+ }
216217
217218 NSError * error;
218219 NSData * logData = [NRLogger logFileData: &error];
@@ -265,16 +266,14 @@ - (void) testLocalLogLevels {
265266 // Set the remote log level to Info.
266267 [NRLogger setRemoteLogLevel: NRLogLevelInfo];
267268
268- // Set up the expectation
269- XCTestExpectation *fileWrittenExpectation = [self expectationWithDescription: @" File has been modified" ];
270-
269+ __block BOOL operationCompleted = NO ;
271270 __block int count = 0 ;
272271 dispatch_source_set_event_handler (self.source , ^{
273272 count++;
274273 if (count == 4 ){
275274 // Fulfill the expectation when a write is detected
276275 sleep (1 );
277- [fileWrittenExpectation fulfill ] ;
276+ operationCompleted = YES ;
278277 }
279278 });
280279
@@ -295,12 +294,15 @@ - (void) testLocalLogLevels {
295294 @" additionalAttribute2" : @" attribute2"
296295 }];
297296
298- [self waitForExpectationsWithTimeout: 30 handler: ^(NSError * _Nullable error) {
299- if (error) {
300- // Handle timeout here
301- NSLog (@" Timeout occurred, but the test will not fail." );
302- }
303- }];
297+ // Set a timeout duration
298+ NSTimeInterval timeout = 30.0 ;
299+ NSDate *timeoutDate = [NSDate dateWithTimeIntervalSinceNow: timeout];
300+
301+ // Run the run loop until the operation completes or the timeout is reached
302+ while (!operationCompleted && [timeoutDate timeIntervalSinceNow ] > 0 ) {
303+ // Allow other scheduled run loop activities to proceed
304+ [[NSRunLoop currentRunLoop ] runMode: NSDefaultRunLoopMode beforeDate: [NSDate dateWithTimeIntervalSinceNow: 0.1 ]];
305+ }
304306
305307 NSError * error;
306308 NSData * logData = [NRLogger logFileData: &error];
@@ -351,16 +353,14 @@ - (void) testAutoCollectedLogs {
351353 [NRLogger setRemoteLogLevel: NRLogLevelDebug];
352354 XCTAssertTrue ([NRAutoLogCollector redirectStandardOutputAndError ]);
353355
354- // Set up the expectation
355- XCTestExpectation *fileWrittenExpectation = [self expectationWithDescription: @" File has been modified" ];
356-
356+ __block BOOL operationCompleted = NO ;
357357 __block int count = 0 ;
358358 dispatch_source_set_event_handler (self.source , ^{
359359 count++;
360360 if (count == 5 ){
361361 // Fulfill the expectation when a write is detected
362362 sleep (1 );
363- [fileWrittenExpectation fulfill ] ;
363+ operationCompleted = YES ;
364364 }
365365 });
366366
@@ -375,12 +375,15 @@ - (void) testAutoCollectedLogs {
375375 os_log_error (customLog, " This is an error os_log message.\n " );
376376 os_log_fault (customLog, " This is a fault os_log message.\n " );
377377
378- [self waitForExpectationsWithTimeout: 30 handler: ^(NSError * _Nullable error) {
379- if (error) {
380- // Handle timeout here
381- NSLog (@" Timeout occurred, but the test will not fail." );
382- }
383- }];
378+ // Set a timeout duration
379+ NSTimeInterval timeout = 30.0 ;
380+ NSDate *timeoutDate = [NSDate dateWithTimeIntervalSinceNow: timeout];
381+
382+ // Run the run loop until the operation completes or the timeout is reached
383+ while (!operationCompleted && [timeoutDate timeIntervalSinceNow ] > 0 ) {
384+ // Allow other scheduled run loop activities to proceed
385+ [[NSRunLoop currentRunLoop ] runMode: NSDefaultRunLoopMode beforeDate: [NSDate dateWithTimeIntervalSinceNow: 0.1 ]];
386+ }
384387
385388 [NRAutoLogCollector restoreStandardOutputAndError ];
386389
0 commit comments