Skip to content

Instantly share code, notes, and snippets.

@drance
Last active August 29, 2015 13:57

Revisions

  1. drance revised this gist Mar 18, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    test(semaphore);

    while(dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW)) {
    [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:1]];
    [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:interval]];
    }
    }

  2. drance revised this gist Mar 18, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    NSAssert((test != NULL), @"Passed a NULL test block");
    test(semaphore);

    while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW)) {
    while(dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW)) {
    [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:1]];
    }
    }
  3. drance revised this gist Mar 18, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    - (void)sleepRunLoopForInterval:(NSTimeInterval) interval whileRunningAsynchronousTest:(void (^)(dispatch_semaphore_t semaphore))test {
    - (void)sleepRunLoopForInterval:(NSTimeInterval)interval whileRunningAsynchronousTest:(void (^)(dispatch_semaphore_t semaphore))test {
    dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);

    NSAssert((test != NULL), @"Passed a NULL test block");
  4. drance revised this gist Mar 18, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@

    - (void)testAsynchronousStuff {
    [self sleepRunLoopForInterval:1.0 whileRunningAsynchronousTest:^(dispatch_semaphore_t semaphore) {
    [self runThatThingWeNeedToTestWithCompletion:^{
    [self thatAPIWeNeedToTestWithCompletion:^{
    STAssertTrue(something, @"Noes");
    dispatch_semaphore_signal(semaphore);
    }];
    @@ -20,7 +20,7 @@

    - (void)testMoreAsynchronousStuff {
    [self sleepRunLoopForInterval:0.2 whileRunningAsynchronousTest:^(dispatch_semaphore_t semaphore) {
    [self runThatOtherThingWeNeedToTestWithCompletion:^(id result){
    [self thatOtherAPIWeNeedToTestWithCompletion:^(id result){
    STAssertNotNil(result, @"Noes");
    dispatch_semaphore_signal(semaphore);
    }]
  5. drance created this gist Mar 18, 2014.
    28 changes: 28 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    - (void)sleepRunLoopForInterval:(NSTimeInterval) interval whileRunningAsynchronousTest:(void (^)(dispatch_semaphore_t semaphore))test {
    dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);

    NSAssert((test != NULL), @"Passed a NULL test block");
    test(semaphore);

    while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW)) {
    [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:1]];
    }
    }

    - (void)testAsynchronousStuff {
    [self sleepRunLoopForInterval:1.0 whileRunningAsynchronousTest:^(dispatch_semaphore_t semaphore) {
    [self runThatThingWeNeedToTestWithCompletion:^{
    STAssertTrue(something, @"Noes");
    dispatch_semaphore_signal(semaphore);
    }];
    }];
    }

    - (void)testMoreAsynchronousStuff {
    [self sleepRunLoopForInterval:0.2 whileRunningAsynchronousTest:^(dispatch_semaphore_t semaphore) {
    [self runThatOtherThingWeNeedToTestWithCompletion:^(id result){
    STAssertNotNil(result, @"Noes");
    dispatch_semaphore_signal(semaphore);
    }]
    }
    }