erikdoe / ocmock

Mock objects for Objective-C
http://ocmock.org
Apache License 2.0
2.16k stars 606 forks source link

Occasional crashes using OCMock #447

Closed drdaz closed 4 years ago

drdaz commented 4 years ago

I help maintain the iOS Parse SDK. We have a few tests using OCMock there that fail occasionally, and I'm not sure that it's anything we're doing (though it might be, of course 🙂).

We have a test called testDownloadStreamSharesOperations here that fails like so:

Application Specific Information:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[PFFileManager ocmock_replaced_moveItemAsyncAtPath:toPath:]: unrecognized selector sent to class 0x10010f16a898'
terminating with uncaught exception of type NSException
abort() called
CoreSimulator 704.12.2 - Device: iPhone 11 (2A659368-F5F7-4EF1-A215-DA479CD53F04) - Runtime: iOS 13.6 (17G64) - DeviceType: iPhone 11

Application Specific Backtrace 1:
0   CoreFoundation                      0x00007fff23e3de6e __exceptionPreprocess + 350
1   libobjc.A.dylib                     0x00007fff512539b2 objc_exception_throw + 48
2   CoreFoundation                      0x00007fff23e5ea94 +[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3   CoreFoundation                      0x00007fff23e4286c ___forwarding___ + 1436
4   CoreFoundation                      0x00007fff23e44b58 _CF_forwarding_prep_0 + 120
5   CoreFoundation                      0x00007fff23e44dec __invoking___ + 140
6   CoreFoundation                      0x00007fff23e41fd1 -[NSInvocation invoke] + 321
7   OCMock                              0x000010010f7a631c -[OCClassMockObject forwardInvocationForClassObject:] + 3788
8   CoreFoundation                      0x00007fff23e42616 ___forwarding___ + 838
9   CoreFoundation                      0x00007fff23e44b58 _CF_forwarding_prep_0 + 120
10  ParseUnitTests-iOS                  0x000010010eb720b0 __52-[PFFileController _cacheFileAsyncWithState:atPath:]_block_invoke + 816
11  ParseUnitTests-iOS                  0x000010010ee5ce53 __62-[BFTask continueWithExecutor:successBlock:cancellationToken:]_block_invoke + 1331
12  ParseUnitTests-iOS                  0x000010010ee59ae0 __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke + 1264
13  ParseUnitTests-iOS                  0x000010010ee67144 __29+[BFExecutor defaultExecutor]_block_invoke_2 + 1716
14  ParseUnitTests-iOS                  0x000010010ee6b1d8 -[BFExecutor execute:] + 632
15  ParseUnitTests-iOS                  0x000010010ee5b4b2 __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke.104 + 338
16  ParseUnitTests-iOS                  0x000010010ee57316 -[BFTask runContinuations] + 3494
17  ParseUnitTests-iOS                  0x000010010ee548e9 -[BFTask trySetResult:] + 1609
18  ParseUnitTests-iOS                  0x000010010ee45a9b -[BFTaskCompletionSource setResult:] + 683
19  ParseUnitTests-iOS                  0x000010010ee5a52c __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke + 3900
20  libclang_rt.asan_iossim_dynamic.dyl 0x000000010826b55b __wrap_dispatch_async_block_invoke + 203
21  libdispatch.dylib                   0x00007fff5208d951 _dispatch_call_block_and_release + 12
22  libdispatch.dylib                   0x00007fff5208e8cb _dispatch_client_callout + 8
23  libdispatch.dylib                   0x00007fff52090922 _dispatch_queue_override_invoke + 834
24  libdispatch.dylib                   0x00007fff5209dcc5 _dispatch_root_queue_drain + 350
25  libdispatch.dylib                   0x00007fff5209e46a _dispatch_worker_thread2 + 102
26  libsystem_pthread.dylib             0x00007fff522b39f7 _pthread_wqthread + 220
27  libsystem_pthread.dylib             0x00007fff522b2b77 start_wqthread + 15

Thread 0:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib          0x00007fff52205dfa mach_msg_trap + 10
1   libsystem_kernel.dylib          0x00007fff52206170 mach_msg + 60
2   com.apple.CoreFoundation        0x00007fff23da14f5 __CFRunLoopServiceMachPort + 165
3   com.apple.CoreFoundation        0x00007fff23d9c127 __CFRunLoopRun + 1383
4   com.apple.CoreFoundation        0x00007fff23d9b8a4 CFRunLoopRunSpecific + 404
5   com.apple.Foundation            0x00007fff25957c71 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 211
6   com.apple.Foundation            0x00007fff25957ee0 -[NSRunLoop(NSRunLoop) runUntilDate:] + 72
7   com.parse.unit.ios              0x000010010e792153 -[FileControllerTests testDownloadStreamSharesOperations] + 29811 (FileControllerTests.m:379)
8   com.apple.CoreFoundation        0x00007fff23e44dec __invoking___ + 140
9   com.apple.CoreFoundation        0x00007fff23e41fd1 -[NSInvocation invoke] + 321
10  com.apple.dt.XCTest             0x0000000109055fa7 __24-[XCTestCase invokeTest]_block_invoke_2 + 52
11  com.apple.dt.XCTest             0x0000000109055f53 __24-[XCTestCase invokeTest]_block_invoke.206 + 320
12  com.apple.dt.XCTest             0x00000001090b0d32 +[XCTestCase(Failures) performFailableBlock:testCase:testCaseRun:shouldInterruptTest:] + 69
13  com.apple.dt.XCTest             0x00000001090b0c44 -[XCTestCase(Failures) _performTurningExceptionsIntoFailuresInterruptAfterHandling:block:] + 115
14  com.apple.dt.XCTest             0x0000000109055966 -[XCTestCase invokeTest] + 1183
15  com.apple.dt.XCTest             0x0000000109057299 __26-[XCTestCase performTest:]_block_invoke_2 + 43
16  com.apple.dt.XCTest             0x00000001090b0d32 +[XCTestCase(Failures) performFailableBlock:testCase:testCaseRun:shouldInterruptTest:] + 69
17  com.apple.dt.XCTest             0x00000001090b0c44 -[XCTestCase(Failures) _performTurningExceptionsIntoFailuresInterruptAfterHandling:block:] + 115
18  com.apple.dt.XCTest             0x00000001090571d0 __26-[XCTestCase performTest:]_block_invoke.359 + 86
19  com.apple.dt.XCTest             0x00000001090c397d +[XCTContext runInContextForTestCase:block:] + 211
20  com.apple.dt.XCTest             0x0000000109056a84 -[XCTestCase performTest:] + 566
21  com.apple.dt.XCTest             0x000000010909d2fe -[XCTest runTest] + 57
22  com.apple.dt.XCTest             0x0000000109050cc0 __27-[XCTestSuite performTest:]_block_invoke + 354
23  com.apple.dt.XCTest             0x0000000109050412 __59-[XCTestSuite _performProtectedSectionForTest:testSection:]_block_invoke + 24
24  com.apple.dt.XCTest             0x00000001090c397d +[XCTContext runInContextForTestCase:block:] + 211
25  com.apple.dt.XCTest             0x00000001090503c9 -[XCTestSuite _performProtectedSectionForTest:testSection:] + 148
26  com.apple.dt.XCTest             0x000000010905072e -[XCTestSuite performTest:] + 348
27  com.apple.dt.XCTest             0x000000010909d2fe -[XCTest runTest] + 57
28  com.apple.dt.XCTest             0x0000000109050cc0 __27-[XCTestSuite performTest:]_block_invoke + 354
29  com.apple.dt.XCTest             0x0000000109050412 __59-[XCTestSuite _performProtectedSectionForTest:testSection:]_block_invoke + 24
30  com.apple.dt.XCTest             0x00000001090c397d +[XCTContext runInContextForTestCase:block:] + 211
31  com.apple.dt.XCTest             0x00000001090503c9 -[XCTestSuite _performProtectedSectionForTest:testSection:] + 148
32  com.apple.dt.XCTest             0x000000010905072e -[XCTestSuite performTest:] + 348
33  com.apple.dt.XCTest             0x000000010909d2fe -[XCTest runTest] + 57
34  com.apple.dt.XCTest             0x0000000109050cc0 __27-[XCTestSuite performTest:]_block_invoke + 354
35  com.apple.dt.XCTest             0x0000000109050412 __59-[XCTestSuite _performProtectedSectionForTest:testSection:]_block_invoke + 24
36  com.apple.dt.XCTest             0x00000001090c397d +[XCTContext runInContextForTestCase:block:] + 211
37  com.apple.dt.XCTest             0x00000001090503c9 -[XCTestSuite _performProtectedSectionForTest:testSection:] + 148
38  com.apple.dt.XCTest             0x000000010905072e -[XCTestSuite performTest:] + 348
39  com.apple.dt.XCTest             0x000000010909d2fe -[XCTest runTest] + 57
40  com.apple.dt.XCTest             0x00000001090d2e84 __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke + 171
41  com.apple.dt.XCTest             0x00000001090d2f71 __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke.100 + 96
42  com.apple.dt.XCTest             0x000000010906b6b6 -[XCTestObservationCenter _observeTestExecutionForBlock:] + 682
43  com.apple.dt.XCTest             0x00000001090d2c0f -[XCTTestRunSession runTestsAndReturnError:] + 615
44  com.apple.dt.XCTest             0x00000001090346b4 -[XCTestDriver runTestsAndReturnError:] + 456
45  com.apple.dt.XCTest             0x00000001090bf5bc _XCTestMain + 2496
46  libXCTestBundleInject.dylib     0x0000000108eecbfa __RunTests_block_invoke_2 + 13
47  com.apple.CoreFoundation        0x00007fff23da1abc __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
48  com.apple.CoreFoundation        0x00007fff23da11b3 __CFRunLoopDoBlocks + 195
49  com.apple.CoreFoundation        0x00007fff23d9bfa3 __CFRunLoopRun + 995
50  com.apple.CoreFoundation        0x00007fff23d9b8a4 CFRunLoopRunSpecific + 404
51  com.apple.GeoServices           0x00007fff38c39bbe GSEventRunModal + 139
52  com.apple.UIKitCore             0x00007fff49325968 UIApplicationMain + 1605
53  com.parse.ParseUnitTests-iOS-host   0x000000010816e8d3 main + 275 (main.m:14)
54  libdyld.dylib                   0x00007fff520ce1fd start + 1

I believe I've also seen it fail in the same spot with a similar error, just without ´ocmockreplaced´ in the selector name.

We also have a testRunFileUpload here that occasionally fails like so:

Application Specific Information:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '** Cannot use mock object OCClassMockObject(PFURLSession) at 0x6070000422e0. This error usually occurs when a mock object is used after stopMocking has been called on it. In most cases it is not necessary to call stopMocking. If you know you have to, please make sure that the mock object is not used afterwards.'
terminating with uncaught exception of type NSException
abort() called
CoreSimulator 704.12.2 - Device: iPhone 11 (2A659368-F5F7-4EF1-A215-DA479CD53F04) - Runtime: iOS 13.6 (17G64) - DeviceType: iPhone 11

Application Specific Backtrace 1:
0   CoreFoundation                      0x00007fff23e3de6e __exceptionPreprocess + 350
1   libobjc.A.dylib                     0x00007fff512539b2 objc_exception_throw + 48
2   CoreFoundation                      0x00007fff23e3dcac +[NSException raise:format:] + 188
3   OCMock                              0x000010010c669a17 -[OCMockObject assertInvocationsArrayIsPresent] + 2935
4   OCMock                              0x000010010c67e278 -[OCMockObject handleInvocation:] + 728
5   OCMock                              0x000010010c67b496 -[OCMockObject forwardInvocation:] + 502
6   CoreFoundation                      0x00007fff23e42616 ___forwarding___ + 838
7   CoreFoundation                      0x00007fff23e44b58 _CF_forwarding_prep_0 + 120
8   ParseUnitTests-iOS                  0x000010010bb55699 -[PFURLSessionCommandRunner dealloc] + 697
9   libobjc.A.dylib                     0x00007fff51269a16 _ZN11objc_object17sidetable_releaseEb + 174
10  ParseUnitTests-iOS                  0x000010010a0c31ad __destroy_helper_block_e8_32s40s48s + 205
11  libsystem_blocks.dylib              0x00007fff521209ba _Block_release + 101
12  ParseUnitTests-iOS                  0x000010010a0fc22b __destroy_helper_block_e8_32s40s48s56s + 203
13  libsystem_blocks.dylib              0x00007fff521209ba _Block_release + 101
14  ParseUnitTests-iOS                  0x000010010a0a586f __destroy_helper_block_e8_32s40s + 159
15  libsystem_blocks.dylib              0x00007fff521209ba _Block_release + 101
16  CoreFoundation                      0x00007fff23d53106 -[__NSArrayM removeAllObjects] + 246
17  ParseUnitTests-iOS                  0x000010010bd53a3e -[BFTask runContinuations] + 4654
18  ParseUnitTests-iOS                  0x000010010bd50b89 -[BFTask trySetResult:] + 1609
19  ParseUnitTests-iOS                  0x000010010bd41d3b -[BFTaskCompletionSource setResult:] + 683
20  ParseUnitTests-iOS                  0x000010010bd4eb7f __24+[BFTask taskWithDelay:]_block_invoke + 271
21  libclang_rt.asan_iossim_dynamic.dyl 0x000000010525583b __wrap_dispatch_after_block_invoke + 203
22  libdispatch.dylib                   0x00007fff5208d951 _dispatch_call_block_and_release + 12
23  libdispatch.dylib                   0x00007fff5208e8cb _dispatch_client_callout + 8
24  libdispatch.dylib                   0x00007fff52090922 _dispatch_queue_override_invoke + 834
25  libdispatch.dylib                   0x00007fff5209dcc5 _dispatch_root_queue_drain + 350
26  libdispatch.dylib                   0x00007fff5209e46a _dispatch_worker_thread2 + 102
27  libsystem_pthread.dylib             0x00007fff522b39f7 _pthread_wqthread + 220
28  libsystem_pthread.dylib             0x00007fff522b2b77 start_wqthread + 15

Thread 0:: Dispatch queue: com.apple.main-thread
0   com.apple.CoreFoundation        0x00007fff23da3278 _CFRelease + 120
1   libobjc.A.dylib                 0x00007fff5126b077 AutoreleasePoolPage::releaseUntil(objc_object**) + 147
2   libobjc.A.dylib                 0x00007fff5126af96 objc_autoreleasePoolPop + 199
3   com.apple.dt.XCTest             0x000000010603ff64 __24-[XCTestCase invokeTest]_block_invoke.206 + 337
4   com.apple.dt.XCTest             0x000000010609ad32 +[XCTestCase(Failures) performFailableBlock:testCase:testCaseRun:shouldInterruptTest:] + 69
5   com.apple.dt.XCTest             0x000000010609ac44 -[XCTestCase(Failures) _performTurningExceptionsIntoFailuresInterruptAfterHandling:block:] + 115
6   com.apple.dt.XCTest             0x000000010603f966 -[XCTestCase invokeTest] + 1183
7   com.apple.dt.XCTest             0x0000000106041299 __26-[XCTestCase performTest:]_block_invoke_2 + 43
8   com.apple.dt.XCTest             0x000000010609ad32 +[XCTestCase(Failures) performFailableBlock:testCase:testCaseRun:shouldInterruptTest:] + 69
9   com.apple.dt.XCTest             0x000000010609ac44 -[XCTestCase(Failures) _performTurningExceptionsIntoFailuresInterruptAfterHandling:block:] + 115
10  com.apple.dt.XCTest             0x00000001060411d0 __26-[XCTestCase performTest:]_block_invoke.359 + 86
11  com.apple.dt.XCTest             0x00000001060ad97d +[XCTContext runInContextForTestCase:block:] + 211
12  com.apple.dt.XCTest             0x0000000106040a84 -[XCTestCase performTest:] + 566
13  com.apple.dt.XCTest             0x00000001060872fe -[XCTest runTest] + 57
14  com.apple.dt.XCTest             0x000000010603acc0 __27-[XCTestSuite performTest:]_block_invoke + 354
15  com.apple.dt.XCTest             0x000000010603a412 __59-[XCTestSuite _performProtectedSectionForTest:testSection:]_block_invoke + 24
16  com.apple.dt.XCTest             0x00000001060ad97d +[XCTContext runInContextForTestCase:block:] + 211
17  com.apple.dt.XCTest             0x000000010603a3c9 -[XCTestSuite _performProtectedSectionForTest:testSection:] + 148
18  com.apple.dt.XCTest             0x000000010603a72e -[XCTestSuite performTest:] + 348
19  com.apple.dt.XCTest             0x00000001060872fe -[XCTest runTest] + 57
20  com.apple.dt.XCTest             0x000000010603acc0 __27-[XCTestSuite performTest:]_block_invoke + 354
21  com.apple.dt.XCTest             0x000000010603a412 __59-[XCTestSuite _performProtectedSectionForTest:testSection:]_block_invoke + 24
22  com.apple.dt.XCTest             0x00000001060ad97d +[XCTContext runInContextForTestCase:block:] + 211
23  com.apple.dt.XCTest             0x000000010603a3c9 -[XCTestSuite _performProtectedSectionForTest:testSection:] + 148
24  com.apple.dt.XCTest             0x000000010603a72e -[XCTestSuite performTest:] + 348
25  com.apple.dt.XCTest             0x00000001060872fe -[XCTest runTest] + 57
26  com.apple.dt.XCTest             0x000000010603acc0 __27-[XCTestSuite performTest:]_block_invoke + 354
27  com.apple.dt.XCTest             0x000000010603a412 __59-[XCTestSuite _performProtectedSectionForTest:testSection:]_block_invoke + 24
28  com.apple.dt.XCTest             0x00000001060ad97d +[XCTContext runInContextForTestCase:block:] + 211
29  com.apple.dt.XCTest             0x000000010603a3c9 -[XCTestSuite _performProtectedSectionForTest:testSection:] + 148
30  com.apple.dt.XCTest             0x000000010603a72e -[XCTestSuite performTest:] + 348
31  com.apple.dt.XCTest             0x00000001060872fe -[XCTest runTest] + 57
32  com.apple.dt.XCTest             0x00000001060bce84 __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke + 171
33  com.apple.dt.XCTest             0x00000001060bcf71 __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke.100 + 96
34  com.apple.dt.XCTest             0x00000001060556b6 -[XCTestObservationCenter _observeTestExecutionForBlock:] + 682
35  com.apple.dt.XCTest             0x00000001060bcc0f -[XCTTestRunSession runTestsAndReturnError:] + 615
36  com.apple.dt.XCTest             0x000000010601e6b4 -[XCTestDriver runTestsAndReturnError:] + 456
37  com.apple.dt.XCTest             0x00000001060a95bc _XCTestMain + 2496
38  libXCTestBundleInject.dylib     0x0000000105ed6bfa __RunTests_block_invoke_2 + 13
39  com.apple.CoreFoundation        0x00007fff23da1abc __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
40  com.apple.CoreFoundation        0x00007fff23da11b3 __CFRunLoopDoBlocks + 195
41  com.apple.CoreFoundation        0x00007fff23d9bfa3 __CFRunLoopRun + 995
42  com.apple.CoreFoundation        0x00007fff23d9b8a4 CFRunLoopRunSpecific + 404
43  com.apple.GeoServices           0x00007fff38c39bbe GSEventRunModal + 139
44  com.apple.UIKitCore             0x00007fff49325968 UIApplicationMain + 1605
45  com.parse.ParseUnitTests-iOS-host   0x00000001051588d3 main + 275 (main.m:14)
46  libdyld.dylib                   0x00007fff520ce1fd start + 1

Any guidance in debugging these crashes would be greatly appreciated 🙏🏼.

drdaz commented 4 years ago

I believe I've also seen it fail in the same spot with a similar error, just without ´ocmockreplaced´ in the selector name.

So it's not quite in the same spot, but it looks like sometimes we're hitting the mock object, and sometimes not?

Application Specific Information:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[PFFileManager moveItemAsyncAtPath:toPath:]: unrecognized selector sent to class 0x10f6d6998'
abort() called
terminating with uncaught exception of type NSException

Application Specific Backtrace 1:
0   CoreFoundation                      0x00007fff33697b57 __exceptionPreprocess + 250
1   libobjc.A.dylib                     0x00007fff6c4de5bf objc_exception_throw + 48
2   CoreFoundation                      0x00007fff33716b37 __CFExceptionProem + 0
3   CoreFoundation                      0x00007fff335fc165 ___forwarding___ + 829
4   CoreFoundation                      0x00007fff335fbd98 _CF_forwarding_prep_0 + 120
5   Parse                               0x000000010f125605 __52-[PFFileController _cacheFileAsyncWithState:atPath:]_block_invoke + 805
6   Bolts                               0x0000000106dcee6c __62-[BFTask continueWithExecutor:successBlock:cancellationToken:]_block_invoke + 1372
7   Bolts                               0x0000000106dcb75b __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke + 1275
8   Bolts                               0x0000000106dd94e9 __29+[BFExecutor defaultExecutor]_block_invoke_2 + 1753
9   Bolts                               0x0000000106ddd740 -[BFExecutor execute:] + 656
10  Bolts                               0x0000000106dcd2cc __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke.106 + 348
11  Bolts                               0x0000000106dc8ed2 -[BFTask runContinuations] + 3570
12  Bolts                               0x0000000106dc63a0 -[BFTask trySetResult:] + 1632
13  Bolts                               0x0000000106db63db -[BFTaskCompletionSource setResult:] + 651
14  Bolts                               0x0000000106dcc1dc __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke + 3964
15  libclang_rt.asan_osx_dynamic.dylib  0x0000000104663cdb __wrap_dispatch_async_block_invoke + 203
16  libdispatch.dylib                   0x00007fff6d62c6c4 _dispatch_call_block_and_release + 12
17  libdispatch.dylib                   0x00007fff6d62d658 _dispatch_client_callout + 8
18  libdispatch.dylib                   0x00007fff6d62f4b0 _dispatch_queue_override_invoke + 763
19  libdispatch.dylib                   0x00007fff6d63b957 _dispatch_root_queue_drain + 326
20  libdispatch.dylib                   0x00007fff6d63c097 _dispatch_worker_thread2 + 92
21  libsystem_pthread.dylib             0x00007fff6d8879f7 _pthread_wqthread + 220
22  libsystem_pthread.dylib             0x00007fff6d886b77 start_wqthread + 15

Thread 0:: Dispatch queue: com.apple.main-thread
0   libobjc.A.dylib                 0x00007fff6c4d182e objc_msgSend + 46
1   com.mulle-kybernetik.OCMock     0x0000000106e66764 +[OCMConstraint constraint] + 388 (OCMConstraint.m:24)
2   com.mulle-kybernetik.OCMock     0x0000000106e5d386 +[OCMArg isNotNil] + 326 (OCMArg.m:52)
3   com.parse.unit.macOS            0x000000010d992cef -[FileControllerTests testDownloadStreamSharesOperations] + 4927 (FileControllerTests.m:343)
4   com.apple.CoreFoundation        0x00007fff335fd8ac __invoking___ + 140
5   com.apple.CoreFoundation        0x00007fff335fd751 -[NSInvocation invoke] + 303
6   com.apple.dt.XCTest             0x0000000105505e52 __24-[XCTestCase invokeTest]_block_invoke_3 + 52
7   com.apple.dt.XCTest             0x0000000105505e06 __24-[XCTestCase invokeTest]_block_invoke_2 + 297
8   com.apple.dt.XCTest             0x000000010559398a -[XCTMemoryChecker _assertInvalidObjectsDeallocatedAfterScope:] + 51
9   com.apple.dt.XCTest             0x00000001055115e6 -[XCTestCase assertInvalidObjectsDeallocatedAfterScope:] + 116
10  com.apple.dt.XCTest             0x0000000105505cae __24-[XCTestCase invokeTest]_block_invoke.206 + 213
11  com.apple.dt.XCTest             0x000000010557b4b3 +[XCTestCase(Failures) performFailableBlock:testCase:testCaseRun:shouldInterruptTest:] + 69
12  com.apple.dt.XCTest             0x000000010557b3c4 -[XCTestCase(Failures) _performTurningExceptionsIntoFailuresInterruptAfterHandling:block:] + 115
13  com.apple.dt.XCTest             0x0000000105505744 -[XCTestCase invokeTest] + 1144
14  com.apple.dt.XCTest             0x000000010550709f __26-[XCTestCase performTest:]_block_invoke_2 + 43
15  com.apple.dt.XCTest             0x000000010557b4b3 +[XCTestCase(Failures) performFailableBlock:testCase:testCaseRun:shouldInterruptTest:] + 69
16  com.apple.dt.XCTest             0x000000010557b3c4 -[XCTestCase(Failures) _performTurningExceptionsIntoFailuresInterruptAfterHandling:block:] + 115
17  com.apple.dt.XCTest             0x0000000105506fd6 __26-[XCTestCase performTest:]_block_invoke.366 + 86
18  com.apple.dt.XCTest             0x000000010558b45e +[XCTContext runInContextForTestCase:block:] + 211
19  com.apple.dt.XCTest             0x000000010550688a -[XCTestCase performTest:] + 566
20  com.apple.dt.XCTest             0x000000010555a345 -[XCTest runTest] + 57
21  com.apple.dt.XCTest             0x0000000105500beb __27-[XCTestSuite performTest:]_block_invoke + 354
22  com.apple.dt.XCTest             0x0000000105500374 __59-[XCTestSuite _performProtectedSectionForTest:testSection:]_block_invoke + 24
23  com.apple.dt.XCTest             0x000000010558b45e +[XCTContext runInContextForTestCase:block:] + 211
24  com.apple.dt.XCTest             0x000000010550032b -[XCTestSuite _performProtectedSectionForTest:testSection:] + 148
25  com.apple.dt.XCTest             0x0000000105500659 -[XCTestSuite performTest:] + 348
26  com.apple.dt.XCTest             0x000000010555a345 -[XCTest runTest] + 57
27  com.apple.dt.XCTest             0x00000001055a6cb1 __102-[XCTTestRunSession executeTestIdentifiers:skippingTestIdentifiers:completionHandler:completionQueue:]_block_invoke + 256
28  com.apple.dt.XCTest             0x00000001055a6813 __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke.100 + 96
29  com.apple.dt.XCTest             0x000000010552846b -[XCTestObservationCenter _observeTestExecutionForBlock:] + 692
30  com.apple.dt.XCTest             0x00000001055a64b7 -[XCTTestRunSession runTestsAndReturnError:] + 615
31  com.apple.dt.XCTest             0x00000001054e3d86 -[XCTestDriver runTestsAndReturnError:] + 458
32  com.apple.dt.XCTest             0x0000000105587181 _XCTestMain + 2485
33  xctest                          0x0000000104615fee main + 245
34  libdyld.dylib                   0x00007fff6d686cc9 start + 1
dmaclach commented 4 years ago

Can you get the first issue to happen consistently if you turn on Guard Malloc in the Diagnostics pane of the scheme for the test?

The second issue appears to be due to using a mock in a callback after you have called stopMocking on it. Do you explicitly call stopMocking around that test somewhere?

drdaz commented 4 years ago

Can you get the first issue to happen consistently if you turn on Guard Malloc in the Diagnostics pane of the scheme for the test?

I'm afraid not.

The second issue appears to be due to using a mock in a callback after you have called stopMocking on it. Do you explicitly call stopMocking around that test somewhere?

It's called in the tearDown call chain (in the test case's superclass).

drdaz commented 4 years ago

I haven't been able to reproduce any of these errors since removing the call to stopMocking.

Has using it always been a generally bad idea? I ask since I wasn't around when the code was written, and the author isn't around. So I'm a little interested in why it was there.

erikdoe commented 4 years ago

The general guideline was always to only use stopMocking when you know you have to. Mostly that's when you are aware that there is an unavoidable retain cycle involving the mock. There were some issues originally, especially in 2014 when OCMock 3 came out with the verify-style that increased the chances for retain cycles, but over the years OCMock got better and better at memory handling. Still, there is some (IMHO incorrect) advice out there to call stopMocking "just in case...". Theoretically, there isn't a downside to calling stopMocking though, but sometimes, like it seems in your case, calling it before the mock is released (technically: de-allocated) can highlight other issues. Hope this makes sense.

drdaz commented 4 years ago

It makes perfect sense. Thanks for the answer.

I'd have expected the mocks to be dealloc'ed before we were calling it, but that's not something we control. So it looks to have been timing related.

dmaclach commented 4 years ago

@drdaz pr #454 and #455 may help a lot of your issues across threads. It sounds like getting rid of the stopMocking probably is just keeping your mocks around long enough, but #454 and #455 put better (But not perfect) guardrails around making sure that mocks work a little better across threads.

Either way, I think we can probably close this issue?

drdaz commented 4 years ago

Oh those changes look important 🙂. I look forward to seeing those in a release.

Yeah, let's close this. Thanks for the help!