Skip to content

Commit a44438b

Browse files
authored
Apply main thread fix to assertInlineSnapshot. (#1012)
We made changes in #962 to fix an issue with main thread checking and dispatch queues in `assertSnapshot`, but didn't apply the fix to a similar situation in `assertInlineSnapshot`.
1 parent b198a56 commit a44438b

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

Sources/InlineSnapshotTesting/AssertInlineSnapshot.swift

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -340,24 +340,15 @@ public struct InlineSnapshotSyntaxDescriptor: Hashable {
340340
writeInlineSnapshots()
341341
}
342342
}
343-
DispatchQueue.mainSync {
343+
if Thread.isMainThread {
344344
XCTestObservationCenter.shared.addTestObserver(InlineSnapshotObserver())
345+
} else {
346+
DispatchQueue.main.sync {
347+
XCTestObservationCenter.shared.addTestObserver(InlineSnapshotObserver())
348+
}
345349
}
346350
}()
347351

348-
extension DispatchQueue {
349-
private static let key = DispatchSpecificKey<UInt8>()
350-
private static let value: UInt8 = 0
351-
352-
fileprivate static func mainSync<R>(execute block: () -> R) -> R {
353-
Self.main.setSpecific(key: key, value: value)
354-
if getSpecific(key: key) == value {
355-
return block()
356-
} else {
357-
return main.sync(execute: block)
358-
}
359-
}
360-
}
361352

362353
@_spi(Internals) public struct File: Hashable {
363354
public let path: StaticString

0 commit comments

Comments
 (0)