Browse Source

Ensure pending scheduled callbacks have executed in "run" APIs

Pierre-Olivier Latour 11 years ago
parent
commit
1b12a7bd14
1 changed files with 12 additions and 0 deletions
  1. 12 0
      GCDWebServer/Core/GCDWebServer.m

+ 12 - 0
GCDWebServer/Core/GCDWebServer.m

@@ -678,6 +678,11 @@ static inline NSString* _EncodeBase64(NSString* string) {
       [self stop];
       success = YES;
     }
+    while (1) {
+      if (CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, true) == kCFRunLoopRunTimedOut) {  // Ensure pending scheduled callbacks have been executed
+        break;
+      }
+    }
     signal(SIGINT, intHandler);
     signal(SIGTERM, termHandler);
   }
@@ -966,6 +971,7 @@ static void _LogResult(NSString* format, ...) {
 }
 
 - (NSInteger)runTestsWithOptions:(NSDictionary*)options inDirectory:(NSString*)path {
+  DCHECK([NSThread isMainThread]);
   NSArray* ignoredHeaders = @[@"Date", @"Etag"];  // Dates are always different by definition and ETags depend on file system node IDs
   NSInteger result = -1;
   if ([self startWithOptions:options error:NULL]) {
@@ -1069,6 +1075,12 @@ static void _LogResult(NSString* format, ...) {
     }
     
     [self stop];
+    
+    while (1) {
+      if (CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, true) == kCFRunLoopRunTimedOut) {  // Ensure pending scheduled callbacks have been executed
+        break;
+      }
+    }
   }
   return result;
 }