xctest or xcodebuild hangs when running unit tests

When running a unit test target in any of my iOS/macOS framework projects, I am experiencing random/inconsistent locks/hangs in xctest or xcodebuild. A number of test suites will run and pass but then on a few suites in particular, xcodebuild will stop reporting test results to the console and it appears to be stuck in an infinite loop/deadlock. I've actually seen the lock break in a few cases after 25-30 minutes but for the most part I cancel the test run before seeing if it restarts again.


This is completely reproducible for me just by running xcodebuild's test-without-building in a while loop in the terminal.


```

while true; do

xcodebuild -destination 'platform=iOS Simulator,name=iPad Air 2,OS=12.2' -derivedDataPath <PATH_TO_DERIVED_DATA> -xctestrun '<PATH_TO_XCTESTRUN>/Framework_iphonesimulator12.2-x86_64.xctestrun' -only-testing:<UNIT_TEST_TARGET_NAME> test-without-building

done

```


In the middle of a test suite running, the console will freeze partway through the suite. Sometimes, the lock comes after the first few runs of the command and other times it takes 20+ runs for the lock to occur.


This is happening on Xcode 10.2 and 10.2.1 with the framework projects on Swift 5. I first started noticing this on CI when my unit test jobs would fail because they exceeded to timeout limit for a job not receiving any responses from the console. That's what led me to test xcodebuild locally on my machine.


I cannot find any information online about hanging tests with the same scenario that I'm experiencing. Hoping someone on here can help me out.


Something worth noting - I actually have the exact same test suites from a framework project in an app project which experience the lock on the framework, but the lock does not happen in the app project.


This happens both when parallelization and randomization are enabled or disabled.

Replies

I got the same issue!

Facing Same issue since Xcode-12.
For executing Unit test cases xcode freezes and it takes 15-20 mins to build unit test cases every time.

I have the same issue. I'm running my Unittests on an azure hosted mac build agent. After building and right before starting the tests, the process freezes for 15 minutes. Then the tests are executed normally as they would do on my local machine. On my local machine i don't have that issue. The build agent runs macos-13, since no newer version is available yet. The precise data is : OS Version: macOS 13.6 (22G120) Kernel Version: Darwin 22.6.0 Image Version: 20231025.2

On my local MacBook Pro M2 i am still running on macos 13.5.2 (22G91) But there i don't have this issues. Both machines run XCode 15. Has anyone yet found a solution for this issue? Also my UITest don't run at all on the azure hosted mac as they run into a timeout, whereas on my local machine i don't have such timeouts.