XCUiTest: What causes NSInternalInconsistencyException?

Hello,


When we run our XCode UI Tests on our build servers we frequently get random failures that we don't experience on our own local machines. Can someone explain what is the cause and potential solution to this error message?


failed: caught "NSInternalInconsistencyException", "Activity cannot be used after its scope has completed."


Thanks

Replies

I'm seeing the exact same thing. On my local machine everything works fine, but on my build server it fails with the error you posted. Out if intererest, which CI are you using? We are on Travis, maybe it's an issue with them.

Same issue here. I am using fastlane - it is possible to reproduce issue even on my local machine - if I running uitests from command line.

The problem occurs offen on simulators: iPhone 5s, iPhone SE, iPad's

The problem seems to not occur on simulators: iPhone X, iPhone 8, iPhone 8 Plus

Getting this too (including another assertion failure in this log output, maybe it's relevant):


2017-10-05 14:46:18.837773+0200 FlashlightUITests-Runner[980:1157829] Running tests...
2017-10-05 14:46:19.828570+0200 FlashlightUITests-Runner[980:1157829] Continuing to run tests in the background with task ID 1
Test Suite 'All tests' started at 2017-10-05 14:46:19.912
Test Suite 'FlashlightUITests.xctest' started at 2017-10-05 14:46:19.913
Test Suite 'DashboardUITests' started at 2017-10-05 14:46:19.913
Test Case '-[FlashlightUITests.DashboardUITests testDashboardDisplaysValuesFromXXXXXXXX]' started.
    t =     0.00s Start Test at 2017-10-05 14:46:19.914
    t =     0.17s Set Up
    t =     0.19s     Open com.xxxxxxxx.Flashlight
    t =     0.34s         Launch com.xxxxxxxx.Flashlight
writeDictToFile:1278 ==== Successfully wrote Manifest cache to /var/folders/z9/6hbzfm7s5jv4k6cl6k06zmbm0000gn/C/com.apple.DeveloperTools/All/Xcode/EmbeddedAppDeltas/3355435a13029f4f09b0f386081f976e/2452e1bfb283cbebaf53dd2b36a8cd6a60ed516e/ManifestCache.plist
    t =     5.67s             Wait for com.xxxxxxxx.Flashlight to idle
    t =     6.06s                 Unable to monitor animations
    t =     6.06s                 Unable to monitor event loop
    t =     7.10s Tap "gettingStartedButton" Button
    t =     7.10s     Wait for com.xxxxxxxx.Flashlight to idle
    t =     7.28s         Assertion Failure: <unknown>:0: com.xxxxxxxx.Flashlight crashed in <external symbol>
2017-10-05 14:46:27.414729+0200 FlashlightUITests-Runner[980:1157829] *** Assertion failure in -[XCActivityRecord _synchronized_ensureValid], /Library/Caches/com.apple.xbs/Sources/XCTest_iOS/XCTest-13201/Sources/XCTestFramework/Activities/XCActivityRecord.m:354
    t =     7.50s Tear Down
    t =     7.51s Assertion Failure: <unknown>:0: failed: caught "NSInternalInconsistencyException", "Activity cannot be used after its scope has completed."
(
  0   CoreFoundation                      0x0000000183662ff8 <redacted> + 148
  1   libobjc.A.dylib                     0x00000001820c4538 objc_exception_throw + 56
  2   CoreFoundation                      0x0000000183662eb4 <redacted> + 0
  3   Foundation                          0x00000001840fb760 <redacted> + 112
  4   XCTest                              0x000000010015049c -[XCActivityRecord _synchronized_ensureValid] + 160
  5   XCTest                              0x000000010014ff14 -[XCActivityRecord _synchronized_addAttachment:] + 44
  6   XCTest                              0x00000001001500c8 -[XCActivityRecord addAttachment:] + 44
  7   XCTest                              0x000000010013d050 -[XCActivityRecord(UITesting) attachAutomaticScreenshot] + 248
  8   XCTest                              0x0000000100157050 __67-[XCUIApplicationProcess waitForQuiescenceIncludingAnimationsIdle:]_block_invoke + 96
  9   XCTest                              0x000000010018e258 -[XCTContext _runActivityNamed:type:block:] + 204
  10  XCTest                              0x0000000100156fdc -[XCUIApplicationProcess waitForQuiescenceIncludingAnimationsIdle:] + 176
  11  XCTest                              0x00000001001a69ec __63-[XCUIElement(XCUIElementEventSynthesis) _dispatchEvent:block:]_block_invoke + 64
  12  XCTest                              0x000000010018e258 -[XCTContext _runActivityNamed:type:block:] + 204
  13  XCTest                              0x00000001001a692c -[XCUIElement(XCUIElementEventSynthesis) _dispatchEvent:block:] + 272
  14  XCTest                              0x00000001001a8544 -[XCUIElement(XCUIElementTouchEvents) tap] + 124
  15  FlashlightUITests                   0x0000000102271028 _T0So10XCTestCaseC17FlashlightUITestsE15connectXXXXXXXXySo15XCUIApplicationC3app_Sb6isFaketF + 404
  16  FlashlightUITests                   0x000000010227244c _T0So10XCTestCaseC17FlashlightUITestsE15connectXXXXXXXXySo15XCUIApplicationC3app_Sb6isFaketFTo + 92
  17  FlashlightUITests                   0x000000010226d8dc _T017FlashlightUITests09DashboardB0C04testC26DisplaysValuesFromXXXXXXXXyyF + 224
  18  FlashlightUITests                   0x000000010226e134 _T017FlashlightUITests09DashboardB0C04testC26DisplaysValuesFromXXXXXXXXyyFTo + 40
  19  CoreFoundation                      0x0000000183668e80 <redacted> + 144
  20  CoreFoundation                      0x000000018355e2c4 <redacted> + 292
  21  XCTest                              0x00000001001440a8 __24-[XCTestCase invokeTest]_block_invoke.275 + 48
  22  XCTest                              0x0000000100190f08 -[XCTMemoryChecker _assertInvalidObjectsDeallocatedAfterScope:] + 56
  23  XCTest                              0x0000000100143e58 __24-[XCTestCase invokeTest]_block_invoke + 680
  24  XCTest                              0x0000000100189780 -[XCUITestContext performInScope:] + 208
  25  XCTest                              0x0000000100143ba0 -[XCTestCase invokeTest] + 136
  26  XCTest                              0x0000000100144c78 __26-[XCTestCase performTest:]_block_invoke.382 + 48
  27  XCTest                              0x000000010018e778 +[XCTContext runInContextForTestCase:block:] + 164
  28  XCTest                              0x0000000100144674 -[XCTestCase performTest:] + 596
  29  XCTest                              0x0000000100140868 __27-[XCTestSuite performTest:]_block_invoke + 288
  30  XCTest                              0x0000000100140290 -[XCTestSuite _performProtectedSectionForTest:testSection:] + 44
  31  XCTest                              0x00000001001404a0 -[XCTestSuite performTest:] + 236
  32  XCTest                              0x0000000100140868 __27-[XCTestSuite performTest:]_block_invoke + 288
  33  XCTest                              0x0000000100140290 -[XCTestSuite _performProtectedSectionForTest:testSection:] + 44
  34  XCTest                              0x00000001001404a0 -[XCTestSuite performTest:] + 236
  35  XCTest                              0x0000000100140868 __27-[XCTestSuite performTest:]_block_invoke + 288
  36  XCTest                              0x0000000100140290 -[XCTestSuite _performProtectedSectionForTest:testSection:] + 44
  37  XCTest                              0x00000001001404a0 -[XCTestSuite performTest:] + 236
  38  XCTest                              0x0000000100197f5c __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke + 44
  39  XCTest                              0x00000001001533e8 -[XCTestObservationCenter _observeTestExecutionForBlock:] + 420
  40  XCTest                              0x0000000100197dd8 -[XCTTestRunSession runTestsAndReturnError:] + 292
  41  XCTest                              0x000000010012fed0 -[XCTestDriver runTestsAndReturnError:] + 312
  42  XCTest                              0x000000010018d920 _XCTestMain + 620
  43  CoreFoundation                      0x000000018361130c <redacted> + 20
  44  CoreFoundation                      0x0000000183610b28 <redacted> + 288
  45  CoreFoundation                      0x000000018360e998 <redacted> + 728
  46  CoreFoundation                      0x000000018353eda4 CFRunLoopRunSpecific + 424
  47  GraphicsServices                    0x0000000184fa9074 GSEventRunModal + 100
  48  UIKit                               0x00000001897f9c9c UIApplicationMain + 208
  49  FlashlightUITests-Runner            0x0000000100080430 FlashlightUITests-Runner + 33840
  50  libdyld.dylib                       0x000000018254d59c <redacted> + 4

This failure is an internal XCTest error. If you are seeing this, please file a Radar with whatever logging you have available on the system running your tests. Thanks!