Skip to content

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

Closed
@jcavar

Description

@jcavar

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions