Closed finestructure closed 1 month ago
I should add that this feels like a sendable/concurrency bug upstream but I thought I'd raise it here first in case you have some ideas where to best report/address it.
Oh, never mind. I just saw this is a duplicate of https://github.com/pointfreeco/swift-snapshot-testing/issues/822 and that I should be marking those tests @MainActor
!
The issue is slightly more complicated than a missing @MainActor
annotation and the solution might be helpful for others.
We had tests like the following:
@MainActor
func test_documentation_routes_current() async throws {
...
try await app.test(.GET, "/owner/package/~/documentation/target") { @Sendable res in
...
assertSnapshot(of: body, as: .html, named: "index")
...
}
...
}
and these were leading to crashes on when recording. The fix is to move the @MainActor
annotation into the closure instead of the @Sendable
:
func test_documentation_routes_current() async throws {
...
try await app.test(.GET, "/owner/package/~/documentation/target") { @MainActor res in
...
assertSnapshot(of: body, as: .html, named: "index")
...
}
...
}
Hey @finestructure, thanks for documenting this! We do have plans to overhaul the sendability of the library, and we even have an experimental async branch that we use on the Point-Free codebase. We just need to clean things up, and see if it's possible to do in a backwards compatible way.
I mentioned this crash to @stephencelis a couple of weeks ago when we first saw it with Xcode 16b2 but it had "disappeared" when I revisited our tests with Xcode 16b3.
Turns out it didn't really disappear but the conditions to trigger it changed in our project (SPI-Server). The conditions in that project are now:
@Sendable
__XCODE_BUILT_PRODUCTS_DIR_PATHS
env variable check), not when the test are run viaswift test
NB: we see the crash also with Xcode 15.4 and it seems to be related to the
@Sendable
changes we introduced while making the project ready for Swift 6. Reverting to a non-sendable closure makes the snapshot write succeed.However, I've just set up a new project and it's much simpler to trigger the crash there: https://github.com/finestructure/snapshot-testing-crash
NB: This test crashes on both Xcode 15.4 and Xcode 16b3. The culprit seems to be the
async
attribute on the test. It does not crash without it: