Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deadlock when assertSnapshot called on main thread but not on main queue #961

Closed
jcavar opened this issue Mar 24, 2025 · 0 comments · Fixed by #962
Closed

Deadlock when assertSnapshot called on main thread but not on main queue #961

jcavar opened this issue Mar 24, 2025 · 0 comments · Fixed by #962

Comments

@jcavar
Copy link

jcavar commented Mar 24, 2025

Describe the bug

This commit changes the approach to detect if a snapshot is generated on the main thread. However, as discussed in GRDBSnapshotTests issue, this is a breaking change for certain code patterns.

To Reproduce

Download GRDBSnapshotTesting and add the following test case:

// Crash
func test_issue_5() throws {
    let dbQueue = try DatabaseQueue()
    try dbQueue.read { db in
        assertSnapshot(of: "SELECT 'Hello, world!'", as: .dump(db))
    }
}

Or:

// On the main thread
let queue = DispatchQueue(label: "test")
queue.sync {
    print("Hello")

    // Success: we're on the main thread
    assert(Thread.isMainThread)

    // assertSnapshot ...
}

Expected behavior
A snapshot is successfully recorded and generated

Environment

  • swift-snapshot-testing version 1.18.0 and higher
  • Xcode 16.2
  • Swift 6
  • OS: iOS 18
stephencelis added a commit that referenced this issue Mar 26, 2025
Unfortunately #946 introduced a deadlock when `assertSnapshot` is called
on the main thread but not the main queue, so let's revert to the old
code path for now with an explicit `Test.current` check to avoid the
original issue.

Fixes #961.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant