-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Non inline tests not working for read
based APIs
#5
Comments
Thank you for the report @jcavar, I can reproduce indeed. This crashes because the snapshot is created, from the main thread, but not from This deadlock was introduced in swift-snapshot-testing version 1.18.0, due to pointfreeco/swift-snapshot-testing#946. // Crash
func test_issue_5() throws {
let dbQueue = try DatabaseQueue()
try dbQueue.read { db in
assertSnapshot(of: "SELECT 'Hello, world!'", as: .dump(db))
}
} This is, strictly speaking, a breaking change in swift-snapshot-testing. I recommend that you open an issue in this repository. You have two possible workarounds:
|
Thank you for your response @groue. Which Xcode version are you running your passing example with? Your example crashes for me with "Current context must not be nil" in Xcode 16.2. ![]() |
OK, I just ran it in Xcode 16.2, and swift-snapshot-testing crashes on the first run (but the snapshot is created). The test passes on the second run. Sorry I did not spot this crash in my previous comment. If this not acceptable, you can use the first workaround, which is using swift-snapshot-testing 1.17.7 (right before it has introduced the breaking change). Or use inline snapshots, that work too. |
This is true, but it also crashes if the test fails (e.g. change "SELECT 'Hello, world!" to "SELECT 'world!")
I was considering this, but my output is quite large for inline snapshot tests
We use snapshot tests quite heavily for other things, so I am worried to fix this dependency to an old version to workaround this. Appreciate your support! |
Sorry I do not suggest anything better. We face a breaking change in a dependency. This should be notified to the maintainers of swift-snapshot-testing. If you don't know how to do it, I can help. But basically, it is opening an issue that describes what happens to your app, with a link to this issue, since it describes exactly how and when the breaking change happened. |
No problem, I can open the issue in the original repository - I would just like to understand the scope of it first. For me, even with 1.17.7 swift-snapshot-testing, It seems to me that there are 2 issues here:
Let me know your thoughts. |
For me as well there are two issues.
|
Thanks @groue! Just to clarify this:
The issue is that:
Is my understanding correct? |
Correct 👍
The main thread is not blocked. You can run, on the main thread, some code inside a DispatchQueue which is not DispatchQueue.main: // On the main thread
let queue = DispatchQueue(label: "test")
queue.sync {
print("Hello")
// Success: we're on the main thread
assert(Thread.isMainThread)
// Failure: we're not on the main DispatchQueue
dispatchPrecondition(condition: .onQueue(.main))
}
Yes 👍
Correct 👍 This deadlock, in recent SDK releases, crashes instead of just dead-locking. |
I understand, thank you. Report created here: |
Currently, all GRDBSnapshotTesting tests pass, but none of them are using
assertSnapshot
inside ofread
closure.I've added a test that crashes when run:
I think this might be an issue with the upstream library (or XCTest, which requires attachments to be recorded on the main thread), but it might be worth revisiting this API so that the issue can be worked around.
The text was updated successfully, but these errors were encountered: