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
+19
-4
@@ -4,14 +4,29 @@ import XCTest
|
|||||||
enum Snapshot {
|
enum Snapshot {
|
||||||
// Produces the flat element array for the given bundle identifier. Falls back
|
// 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.
|
// 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]] {
|
static func elements(bundleIdentifier: String) -> [[String: Any]] {
|
||||||
|
var result: [[String: Any]] = []
|
||||||
|
var caughtError: NSError?
|
||||||
|
let work = {
|
||||||
|
_ = CompanionRunCatching({
|
||||||
if let captured = try? capture(bundleIdentifier: bundleIdentifier) {
|
if let captured = try? capture(bundleIdentifier: bundleIdentifier) {
|
||||||
return captured
|
result = captured
|
||||||
|
} else if let fallback = try? capture(bundleIdentifier: "com.apple.springboard") {
|
||||||
|
result = fallback
|
||||||
}
|
}
|
||||||
if let fallback = try? capture(bundleIdentifier: "com.apple.springboard") {
|
}, &caughtError)
|
||||||
return fallback
|
|
||||||
}
|
}
|
||||||
return []
|
if Thread.isMainThread {
|
||||||
|
work()
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.sync(execute: work)
|
||||||
|
}
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
private static func capture(bundleIdentifier: String) throws -> [[String: Any]] {
|
private static func capture(bundleIdentifier: String) throws -> [[String: Any]] {
|
||||||
|
|||||||
Reference in new issue
Block a user