Since Xcode 26 our tests are crashing due to the Main Thread not being able to deallocate WKNavigationResponse
.
Following an example:
import Foundation
import WebKit
final class WKNavigationResponeMock: WKNavigationResponse {
private let urlResponse: URLResponse
override var response: URLResponse { urlResponse }
init(urlResponse: URLResponse) {
self.urlResponse = urlResponse
super.init()
}
convenience init(httpUrlResponse: HTTPURLResponse) {
self.init(urlResponse: httpUrlResponse)
}
convenience init?(url: URL, statusCode: Int) {
guard let httpURLResponse = HTTPURLResponse(url: url, statusCode: statusCode, httpVersion: nil, headerFields: nil) else {
return nil
}
self.init(httpUrlResponse: httpURLResponse)
}
}
import WebKit
import XCTest
final class ExampleTests: XCTestCase {
@MainActor func testAllocAndDeallocWKNavigationResponse() {
let expectedURL = URL(string: "https://galaxus.ch/")!
let expectedStatusCode = 404
let instance = WKNavigationResponeMock()
// here it should dealloc/deinit `instance` automatically
}
Here the call stack:
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 CoreFoundation 0x101f3dd54 CFRetain.cold.1 + 16
1 CoreFoundation 0x101e14860 CFRetain + 104
2 WebKit 0x10864dd24 -[WKNavigationResponse dealloc] + 52