TSan Breaks Exception Expectations

Yesterday, Apple released Xcode 15 β3 (15A195k) and I noticed that my tests started failing. These tests verified that an expectation was thrown from calling a method that should be unavailable. However, these tests were failing with an uncaught exception: xctest(8933,0x1f2049e00) malloc: nano zone abandoned due to inability to reserve vm space. Test Suite 'ExampleClassTest' started at 2023-07-06 07:40:43.904. Test Case '-[ExampleClassTest testInit]' started. 2023-07-06 07:40:43.907915-0500 xctest[8933:99736] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'init is unavailable for class ExampleClass' *** First throw call stack: ( 0 CoreFoundation 0x00000001971a3154 __exceptionPreprocess + 176 1 libobjc....

Handling Flaky Tests

When running tests, sometimes you may discover that some tests just fail sporadically. This may be due to conditions on the test host or perhaps some unexpected downtime in a service. It could even be caused by using test randomization. Regardless of the cause, the goal is to have all tests passing at all times and that does become difficult if there are external dependencies or resource issues. XCTest provides some utilities to help us make robust tests that can handle this....