mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
fix(companion): capture snapshots on the main thread inside the catch bridge
This commit is contained in:
1 parent
665d757dce
commit
00e203b8f6
1 file changed
+20
-5
@@ -4,14 +4,29 @@ import XCTest
|
||||
enum Snapshot {
|
||||
// Produces the flat element array for the given bundle identifier. Falls back
|
||||
// to springboard if the requested app is not running or its snapshot throws.
|
||||
// Snapshot resolution can demand the test's execution context, which lives
|
||||
// on the main thread, and a framework assertion raises an exception that
|
||||
// would kill the server; so the capture runs on main inside the catch
|
||||
// bridge, and an assertion yields an empty dump, which upstream treats as
|
||||
// collapsed and retries.
|
||||
static func elements(bundleIdentifier: String) -> [[String: Any]] {
|
||||
if let captured = try? capture(bundleIdentifier: bundleIdentifier) {
|
||||
return captured
|
||||
var result: [[String: Any]] = []
|
||||
var caughtError: NSError?
|
||||
let work = {
|
||||
_ = CompanionRunCatching({
|
||||
if let captured = try? capture(bundleIdentifier: bundleIdentifier) {
|
||||
result = captured
|
||||
} else if let fallback = try? capture(bundleIdentifier: "com.apple.springboard") {
|
||||
result = fallback
|
||||
}
|
||||
}, &caughtError)
|
||||
}
|
||||
if let fallback = try? capture(bundleIdentifier: "com.apple.springboard") {
|
||||
return fallback
|
||||
if Thread.isMainThread {
|
||||
work()
|
||||
} else {
|
||||
DispatchQueue.main.sync(execute: work)
|
||||
}
|
||||
return []
|
||||
return result
|
||||
}
|
||||
|
||||
private static func capture(bundleIdentifier: String) throws -> [[String: Any]] {
|
||||
|
||||
Reference in new issue
Block a user