Created
September 7, 2020 15:27
-
-
Save marcpalmer/ca97e6e56544d4cd869b2ba9b1a1c97f to your computer and use it in GitHub Desktop.
Example of infinite recursion crash when asking for URL.bookmarkData in a unit test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// | |
/// Example of infinite recursion crash when asking for URL.bookmarkData in a unit test, | |
/// from a non-main queue. | |
/// | |
import XCTest | |
class BookmarkDataIssueTests: XCTestCase { | |
func testExample() throws { | |
let dir = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true) | |
let fileURL = dir.appendingPathComponent(UUID().uuidString) | |
let fileData = "Hello, world".data(using: .utf8)! | |
try fileData.write(to: fileURL) | |
// This works fine | |
do { | |
let _ = try fileURL.bookmarkData() | |
} catch let error { | |
XCTFail("Couldn't get bookmark data: \(error)") | |
} | |
// This crashes inside Foundation | |
let asyncBookmark = expectation(description: "asyncBookmark") | |
DispatchQueue.global().async { | |
do { | |
let _ = try fileURL.bookmarkData() | |
} catch let error { | |
XCTFail("Couldn't get bookmark data: \(error)") | |
} | |
asyncBookmark.fulfill() | |
} | |
wait(for: [asyncBookmark], timeout: 10) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment