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

swift 6.0.1 crash when running tests swift testing with @MainActor annotation only on linux #919

Open
doozMen opened this issue Oct 17, 2024 · 1 comment

Comments

@doozMen
Copy link
Contributor

doozMen commented Oct 17, 2024

Describe the bug
Only happens on linux

  1. clone https://github.com/doozMen/swift-testing-main-bug
  2. run unit tests with visual studio in debug

You will see it crashes. The docs state that Thread.isMainThread is not available. Weirdly it is on macOS just not on linux.

To Reproduce
run the test project on linux and maybe add code

    #expect(Thread.isMainThread == true)

This will work on mac and not on linux

Expected behavior

Not creating deadlock because of doing dispach on main in sync from main

Screenshots
Screenshot 2024-10-17 at 16 16 31

Environment

  • swift-snapshot-testing version [1.17..5]
  • Swift [6.0.1]
  • OS: aarch64-unknown-linux-gnu

Additional context
Maybe also a bug in swift but not sure as when you the check is unavailable in async context according to the docs. So you should not rely on it?

Maybe have a asser option that is marked with @mainactor might be better?

@stephencelis
Copy link
Member

@doozMen Thanks for the report. We're running SnapshotTesting on Linux for pointfree.co, but are on a particular branch that uses this logic to dispatch to the main queue instead:

static func registerIfNeeded() {
DispatchQueue.mainSync {
if !registered {
registered = true
XCTestObservationCenter.shared.addTestObserver(CleanCounterBetweenTestCases())
}
}
}

Would you be open to exploring if this fix would address the problem for you when applied to the main branch?

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

No branches or pull requests

2 participants