Okay... the primary problem was the queues for AFNetworking AND the Notification were on the main thread. The semaphore is blocking the main thread, so both responses were blocked.
For the testing, a new NSOperationQueue had to be specified in place of the mainQueue. For the networking class, a new completionQueue had to be specified. There doesn't seem to be a way of setting a default completionQueue on these methods. Issue has been opened regarding this.
New test code and subset of the network shown below.
@implementation NetworkTests
NSOperationQueue * testOperationQueue;
- (void)setUp {
[super setUp];
testOperationQueue = [[NSOperationQueue alloc] init];
}
- (void)testLogin {
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
[[NSNotificationCenter defaultCenter] addObserverForName:kLoginComplete
object:nil
queue:testOperationQueue
usingBlock:^(NSNotification *note) {
XCTAssertTrue(true, @"login Complete"); // expand on this when I get basic premise working
NSLog(@"asserted true");
dispatch_semaphore_signal(sema);
}];
[Network loginWithUserName:@"testname" password:@"password"];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
}
@end
For the network, it has this:
static dispatch_queue_t completionQueue; // initialized when the _gatewayClient object is created
+ (void)loginWithUserName:(NSString *)userName password:(NSString *)password {
AFHTTPRequestOperation *outerOperation =
[Network.gatewayClient
GET:[self baseURLForType:@"auth"
method:@"getpubtoken"]
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) {
// do stuff here
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSDictionary *userInfo = @{ @"error": error };
[[NSNotificationCenter defaultCenter] postNotificationName:kLoginComplete
object:nil
userInfo:userInfo];
}];
outerOperation.completionQueue = completionQueue;
}