views:

33

answers:

1

The Problem

I run my unit tests. At one point, I wait using:

[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];

for an NSOperationQueue to be empty. When my app reaches this line, it terminates immediately. It's run this exact same line with other tests. All tests were working perfectly recently. It also sometimes terminates my app on startup immediately.

What on earth is going on?

A: 

I've posted this for me to provide an answer in case others run into the same problem, as I've spent a full day on this and thanks to the awesomeness of git, have finally tracked down the issue.

I added:

-(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {
    return YES;
}

into my app delegate as I wanted my app to terminate on window close. It turns out that this is the cause of the apparently random termination.

I do hide my window on startup, so I can only think this is what's causing the app to terminate immediately, although this doesn't happen every time on launch of the actual app.

I just know it was terminating consistently on that unit test, which made me think it was something to do with this code or my test. It wasn't.

I got rid of the above line and now everything works as expected.

John Gallagher
By “hide”, do you mean close (i.e., send it a `close` message)? If so, that counts, even if you aren't releasing the window (e.g., with release-when-closed). It's probably a delayed perform that triggers the application to see about terminating; delayed performs go through the run loop.
Peter Hosey
By hide, I meant `orderOut:`. So I'm puzzled why this is happening.
John Gallagher