Asynchronous tests cases timeout instantly when attempting to access torn down singeltons in another test

26 views
Skip to first unread message

Ashik Manandhar

unread,
Apr 18, 2013, 4:07:40 PM4/18/13
to ghu...@googlegroups.com
I'm running into this issue where random asynchronous test cases will timeout instantly if another test attempts to access a torn down singleton while tearing down.

For example

MySingelton :
__strong MySingelton *sharedInstance = nil;

+ (MySingelton *)sharedInstance {
   return sharedInstance;
}

+ (void)setSharedInstance:(MySingleton *)sharedSingelton {
   sharedInstance = sharedSingleton;
}

Test 1:
- (void)setUp {
    [super setUp];
    [MySingleton setShareInstance:[[MySingelton alloc] init]];
}

- (void)tearDown {
    [MySingleton setSharedInstance:nil];
    NSLog(@"%@", [MySingleton sharedInstance]);
}

Test 2:
- (void)testAsync {
   [self prepare];
   [self performSelector:@selector(_confirmAsync) withObject:nil afterDelay:0.1];
   [self waitForStatus:kGHUnitWaitStatusSuccess timeout:1];
}

- (void)_confirmAsync {
   [self notify:kGHUnitWaitStatusSuccess forSelector:@selector(testAsync)];
}

In this example, the waitForStatus:timeout: in Test 2 will timeout instantly without ever making the call to _confirmAsync. Any ideas? Thanks!
Reply all
Reply to author
Forward
0 new messages