Error from Xcode-Test Step
Testing failed:
UnitTest Unit Tests:
StockTwits encountered an error (Failed to establish communication with the test runner. If you believe this error represents a bug, please attach the result bundle at /var/folders/11/nh0v1jld7zd7b9zqm1774gtm0000gn/T/XCUITestOutput3248020570/Test-StockTwits(Production).xcresult. (Underlying Error: Error retrieving daemon unix domain socket from simulator, failed after 30 attempts.; getenv error: Error Domain=com.apple.CoreSimulator.SimError Code=405 "Unable to getenv("TESTMANAGERD_SIM_SOCK") while not booting or booted. Current state: Shutdown" UserInfo={NSLocalizedDescription=Unable to getenv("TESTMANAGERD_SIM_SOCK") while not booting or booted. Current state: Shutdown}))
** TEST FAILED **
Issue
The root cause of this error is that the simulator was not warmed up before testing, and thus the communication failed.
This seems to be a long-existing issue of the Xcode Simulator and it only happens sporadically. Here's a related thread:https://github.com/travis-ci/travis-ci/issues/6675
Solution
I created a workaround script based on the thread discussion.
It will grep the simulator UID of the preinstalled iPhone 8 Plus with the latest OS version and warm up the simulator.
The customer can add the script step at the top of their workflow.
# xcrun xctrace list devices 2>&1: print out all available simulator# awk -F " " '{print $6}': print out the UID of iPhone 8 Plus simulators# td -d "(): remove parentheses# tail -1: the simulators are sorted ascendingly, based on the OS version. This will print out the latest one.IOS_SIMULATOR_UDID=`xcrun xctrace list devices 2>&1 | grep "iPhone 8 Plus" | awk -F " " '{print $NF}' | tr -d "()" |tail -1`echo $IOS_SIMULATOR_UDID# warm up the simulator before testingopen -a "simulator" --args -CurrentDeviceUDID $IOS_SIMULATOR_UDID