Chris Prince
Chris Prince

Reputation: 7564

XCTests Failing on Physical Device: "Canceling tests due to timeout ..."

XCTests are failing with the message: *** Canceling tests due to timeout in Waiting for test process to check in... This just started coming up in the last few days. I'm using Xcode 7.3.1, with iOS 9.3.2 running on an iPhone 6. My app is written mostly in Swift.

I've seen some similar posts:

  1. Unable to run XCTests on iOS device
  2. iOS tests will not run on simulator when using Jenkins through JNLP

Those other posts talk about this issue as arising with code signing. Code signing does not seem to be my problem-- I've looked at the KeyChain Access utility and don't see any relevant expired certificates. Also, what so far is (very temporarily) fixing my problem is to restart my iPhone. (Unfortunately, that fix doesn't last long-- maybe a few runs of XCtests and the problem is coming up again). I'm not running Jenkins, just XCTests.

I have tried restarting Xcode and removing all files/folders from the DerivedData folder but neither of these resolves the problem.

I did just install Xcode8 (first beta release). But aside from having launched it once or twice, I'm not generally using it. It does seem oddly coincidental that this issue is arising after having just installed that.

Update 6/25/16

I've narrowed this issue down somewhat. Several other symptoms appear at the same time as the timeout issue:

  1. Console logging directly from print statements in the XCTest files stops.
  2. Timer's fail-- this is actually the root of the problem. My tests involve first waiting for some server interaction, which occurs. But the wait uses an NSTimer which never executes its callback.
  3. Breakpoints stop working.

It seems worthwhile to note that I'm running these XCTest's manually. That is, I am running each test separately, so each test involves a build.

Also, so far I have tested the following:

  1. Restarting Xcode (doesn't help)
  2. Restarting Mac OS X (doesn't help)
  3. Removing Derived Data contents (doesn't help)
  4. Restarting iPhone-- helps, but only again allows a few Xcode tests to run.
  5. Tried running with wifi versus hotspot on iPhone (no change to issue)
  6. TODO: Running with simulator
  7. Could this be a cable or USB port issue? Changing the cable connecting the device doesn't help.
  8. Deleting the app and reinstalling/rebuilding doesn't help.
  9. Tried on different hardware (iPad Air running iOS 9.3.2). Same issues.

My configuration is: iOS 9.3.2, Xcode 7.3.1, Mac OS X 10.11.5 (15F34).

Upvotes: 18

Views: 5846

Answers (6)

John
John

Reputation: 51

I wanted to add another solution here for others to check. If your laptop is subject to a strict antivirus, make sure that they have exempted ~/Library/Developer. I was running into this issue because my antivirus was quarantining ~/Library/Developer/CoreSimulator/Devices/......

Hard to run tests if the test process is quarantined.

Upvotes: 0

Dwayne Forde
Dwayne Forde

Reputation: 1394

While I think Werner Altewischer's answer is correct it's always important to look at the earliest error you're seeing, not the latest.

In my case, I was seeing the error that was posted in the question but there were numerous compilation errors before that.

ex.

Testing failed:
    '...' is not a postfix unary operator
    'count' is unavailable: there is no universally good answer, see the documentation comment for discussion
    Cannot convert value of type 'Int' to expected argument type 'IntMax' (aka 'Int64')
    Cannot convert value of type 'Int8' to expected argument type 'IntMax' (aka 'Int64')
    Cannot convert value of type 'Int16' to expected argument type 'IntMax' (aka 'Int64')
    Cannot convert value of type 'Int32' to expected argument type 'IntMax' (aka 'Int64')
    Cannot convert value of type 'UInt' to expected argument type 'UIntMax' (aka 'UInt64')
    Cannot convert value of type 'UInt8' to expected argument type 'UIntMax' (aka 'UInt64')
    Cannot convert value of type 'UInt16' to expected argument type 'UIntMax' (aka 'UInt64')
    Cannot convert value of type 'UInt32' to expected argument type 'UIntMax' (aka 'UInt64')

I eventually realized that I upgraded my environment without updating my targeted Xcode version in in TravisCI.

Changing...

osx_image: xcode8.3

to...

osx_image: xcode9.3

in my .travis.yml fixed this for me.

Upvotes: 0

Daniel Munoz
Daniel Munoz

Reputation: 1

This is issue caused by an infinite loop in your code. I had the same error but I removed the piece of code causing the problem and it worked fine. xcode doesn't give you much info to work. Some causes might be a global var and a singleton pointing to each other

Upvotes: -2

Werner Altewischer
Werner Altewischer

Reputation: 10466

The problem lies in the fact (or rather: serious bug in xcodebuild) that the timeout for connecting to the XCTest server starts at the moment you issue the command xcodebuild. The timeout is 120 seconds, so if your compilation + startup of the simulator takes longer than 2 minutes xcodebuild will give this "Canceling tests due to timeout" error.

The solution is to break up the build into two commands. One for building and one for running the tests:

> xcodebuild clean build build-for-testing <other options>
> xcodebuild test-without-building <other options>

This will solve the timeout issue, because the test-without-building action doesn't have to compile first.

Upvotes: 19

bharatmeda
bharatmeda

Reputation: 241

I had the same issue with 7.3.1, iPad 9.3.3, Mac 10.11.6

Provisioning profiles are fine and no issues on that front.

Taking hints from the steps mentioned by OP, the issue went away after restarting iPad and XCode twice (in that order). After restarting XCode, I had to unplug iPad and plug again.

Did not had to delete the Derived Data or restart the Mac.

My friend also faced similar issues and sought Apple tech support by providing sample project. Apple Tech support team responded by asking him to file a bug

Upvotes: 6

DaidoujiChen
DaidoujiChen

Reputation: 146

I have the same issue with you. I'm tried all the possible way like you. And still not find the root cause to solve it. The issue is like cause by Xcode8, but I can not find any device log or error message to proof it.

update: My Devices iPhone6s (9.3.1 -> 9.3.2) iPhone5 (9.3.1 -> 9.3.2) both of them appear this issue Xcode Version 7.3.1 (7D1014) Xcode-beta Version 8.0 (8S128D)

Upvotes: 3

Related Questions