Created
February 13, 2013 00:02
-
-
Save koke/4774784 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AsyncTestHelper.h | |
// WordPress | |
// | |
// Created by Jorge Bernal on 2/12/13. | |
// Copyright (c) 2013 WordPress. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
#import <SenTestingKit/SenTestingKit.h> | |
extern dispatch_semaphore_t ATHSemaphore; | |
extern const NSTimeInterval AsyncTestCaseDefaultTimeout; | |
#define ATHStart() do {\ | |
ATHSemaphore = dispatch_semaphore_create(0);\ | |
} while (0) | |
#define ATHNotify() do {\ | |
dispatch_semaphore_signal(ATHSemaphore);\ | |
} while (0) | |
#define ATHWait() do {\ | |
BOOL timedOut;\ | |
NSDate *timeoutDate = [NSDate dateWithTimeIntervalSinceNow:AsyncTestCaseDefaultTimeout];\ | |
long lockStatus = 0;\ | |
while ((lockStatus = dispatch_semaphore_wait(ATHSemaphore, DISPATCH_TIME_NOW)) && [timeoutDate compare:[NSDate date]] == NSOrderedDescending)\ | |
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode\ | |
beforeDate:[NSDate dateWithTimeIntervalSinceNow:10]];\ | |
timedOut = (lockStatus != 0);\ | |
dispatch_release(ATHSemaphore);\ | |
STAssertFalse(timedOut, @"Lock timed out");\ | |
} while (0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AsyncTestHelper.m | |
// WordPress | |
// | |
// Created by Jorge Bernal on 2/12/13. | |
// Copyright (c) 2013 WordPress. All rights reserved. | |
// | |
#import "AsyncTestHelper.h" | |
dispatch_semaphore_t ATHSemaphore; | |
const NSTimeInterval AsyncTestCaseDefaultTimeout = 10; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment