@@ -175,17 +175,15 @@ - (void) testRemoteLogLevels {
175
175
176
176
// Set the remote log level to Debug.
177
177
[NRLogger setRemoteLogLevel: NRLogLevelDebug];
178
-
179
- // Set up the expectation
180
- XCTestExpectation *fileWrittenExpectation = [self expectationWithDescription: @" File has been modified" ];
181
178
179
+ __block BOOL operationCompleted = NO ;
182
180
__block int count = 0 ;
183
181
dispatch_source_set_event_handler (self.source , ^{
184
182
count++;
185
183
if (count == 7 ){
186
184
// Fulfill the expectation when a write is detected
187
185
sleep (1 );
188
- [fileWrittenExpectation fulfill ] ;
186
+ operationCompleted = YES ;
189
187
}
190
188
});
191
189
@@ -206,13 +204,16 @@ - (void) testRemoteLogLevels {
206
204
@" additionalAttribute1" : @" attribute1" ,
207
205
@" additionalAttribute2" : @" attribute2"
208
206
}];
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
+ }
216
217
217
218
NSError * error;
218
219
NSData * logData = [NRLogger logFileData: &error];
@@ -265,16 +266,14 @@ - (void) testLocalLogLevels {
265
266
// Set the remote log level to Info.
266
267
[NRLogger setRemoteLogLevel: NRLogLevelInfo];
267
268
268
- // Set up the expectation
269
- XCTestExpectation *fileWrittenExpectation = [self expectationWithDescription: @" File has been modified" ];
270
-
269
+ __block BOOL operationCompleted = NO ;
271
270
__block int count = 0 ;
272
271
dispatch_source_set_event_handler (self.source , ^{
273
272
count++;
274
273
if (count == 4 ){
275
274
// Fulfill the expectation when a write is detected
276
275
sleep (1 );
277
- [fileWrittenExpectation fulfill ] ;
276
+ operationCompleted = YES ;
278
277
}
279
278
});
280
279
@@ -295,12 +294,15 @@ - (void) testLocalLogLevels {
295
294
@" additionalAttribute2" : @" attribute2"
296
295
}];
297
296
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
+ }
304
306
305
307
NSError * error;
306
308
NSData * logData = [NRLogger logFileData: &error];
@@ -351,16 +353,14 @@ - (void) testAutoCollectedLogs {
351
353
[NRLogger setRemoteLogLevel: NRLogLevelDebug];
352
354
XCTAssertTrue ([NRAutoLogCollector redirectStandardOutputAndError ]);
353
355
354
- // Set up the expectation
355
- XCTestExpectation *fileWrittenExpectation = [self expectationWithDescription: @" File has been modified" ];
356
-
356
+ __block BOOL operationCompleted = NO ;
357
357
__block int count = 0 ;
358
358
dispatch_source_set_event_handler (self.source , ^{
359
359
count++;
360
360
if (count == 5 ){
361
361
// Fulfill the expectation when a write is detected
362
362
sleep (1 );
363
- [fileWrittenExpectation fulfill ] ;
363
+ operationCompleted = YES ;
364
364
}
365
365
});
366
366
@@ -375,12 +375,15 @@ - (void) testAutoCollectedLogs {
375
375
os_log_error (customLog, " This is an error os_log message.\n " );
376
376
os_log_fault (customLog, " This is a fault os_log message.\n " );
377
377
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
+ }
384
387
385
388
[NRAutoLogCollector restoreStandardOutputAndError ];
386
389
0 commit comments