Archive

Monthly Archives: November 2015

First thing, the setup I am using to not get error:

timed out waiting 120 seconds for simulator to boot

Before Integration Script:
open -b com.apple.iphonesimulator

After Integration Script:
xcrun simctl shutdown booted
xcrun simctl erase all
killall "Simulator"

A bit of background:
The app I am developing has a sync process that begins right away as soon as the app is installed for the very first time (and subsequently each 24h). This first time the app runs, it stores in Keychain the credentials, so Login screen will never show up again in any future sync processes.

I am integrating now KIF integration tests and I want to run them on a Bot with XCode Server on an OSX Server.

I have built a test that does this sync process: waits for a notification, waits for login screen, enters credentials, clicks login, waits for notification when sync process is finished.

The first time this runs with the XCode Server bot, it works perfectly. But on the next ones, the app has already all the data and has already the credentials stored in Keychain, so this test would fail since none of the notification would be posted and the login screen would never appear.

Which means the simulator isn’t stateless, it has a state and a different one than the first time it is being launched.

To the point
Since I want to test this first sync process and don’t want to add if statements in my tests, I want to reset the Contents and Settings of the Simulator, before or after each continuous integration.

I have tried to trigger scripts before with:
xcrun simctl erase

But I was getting this error
Unable to erase contents and settings in current state: Booted

Then I added
xcrun simctl shutdown booted

But then the server wasn’t able to boot it. So I tried to boot it with the boot command but, it didn’t work. So I decided to try to clean after.

So now the after trigger script looked like this:

xcrun simctl shutdown booted
xcrun simctl erase all

Then I began to get the famous error
timed out waiting 120 seconds for simulator to boot

With all those tests and errors I was getting, the server always went into an inconsistent state, so I had to restart my machine to being able to test again.

Since the cleaning after wasn’t working, but still made sense to me. I ran the 2 line script, on my terminal on my machine with my user (not the server), and there the simulator went also into an inconsistent state. In the means of, it erased everything, but it didn’t look like it because it still was open and the app still seemed to be installed, until I restarted manually the simulator, then the app was gone.

So I thought, could be happening the same with the simulator on the server. This blog post http://joshuabrauer.com/2015/04/xcode-server-and-continuous-integration-ios gave me the hint to access with the server user.

Changed the password and just log in my computer as _xcsbuildd, with my new password. It might ask to add a new entry in the Keychain since I didn’t know the previous password.
There I saw the open simulator with the installed app.

————
By the way, it was quite some time before I realized that the simulator I was using for running my app, wasn’t the same as the one the server was using. My reasoning was, if the server is asking me what xcode it should use, why doesn’t it use the same simulator. Actually it seems that uses the same simulator, but different path for the device folders.
Anyway I got it when I saw the logs of the bot, the list of available devices inside a mysterious unaccessible _xcsbuildd folder.
————

I added
killall "Simulator"
To the after script.

This one seemed to be working, that way I wasn’t getting anymore error
timed out waiting 120 seconds for simulator to boot

But now I am getting error:

Assertion: Lost connection to test manager service

So I thought it might be because it can’t boot it, so I added a before trigger to force the boot.
open -b com.apple.iphonesimulator

So far it is being stable, but I am still testing. I am still getting sometimes the
Assertion: Lost connection to test manager service
error but, as I said, I am still finding it out. I might add a sleep after the booting of the simulator to give it time, hopefully that solves it.

Overall the feeling is that all this setup of Apple is not very stable, and finding out the issues is hard since it takes long and previous issues might be influencing good solutions.

Just google
timed out waiting 120 seconds for simulator to boot
and you’ll see so many entries of people getting this error and everybody trying different things.