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
QuickConfiguration
could inherit @MainActor
attribute from spec class.
#1182
Comments
Huh. I 100% missed that line in SE-0316 prior to this. I don't think we should do this. I think that tagging the configuration closure with I'm going to leave this open for now. I'd like to see more evidence/arguments for why you think this is desirable. But I don't think this is a convincing-enough reason to do this. |
Yeah, I honestly don't know if this suggestion would be a bad practice or if it's even possible. Let's say I have a spec that is testing a UIView. Because this test is interacting with a UI element, I have to add the The problem is that the QuickConfiguration subclass won't run on the main actor, and Xcode will complain that a UI element that was in the main thread is now being run on another thread. We could add the I came up with a """workaround""", but I'm not proud of it. final class MyConfiguration: QuickConfiguration {
override class func configure(_ configuration: QCKConfiguration) {
let isMainThread = Thread.isMainThread
configuration.afterEach { _ in
if isMainThread {
await MainActor.run { /* do something */ }
} else {
/* do something */
}
}
}
} |
Any updates on this? 👀 |
This isn't an issue as of Quick 7. QuickConfiguration only lets you specify synchronous setup/teardown methods, which will all run on the main thread. |
What did you do?
When you have a
QuickSpec
with the@MainActor
and aQuickConfiguration
with (for example) anafterEach
, the closure of thisafterEach
won't use the main actor.The example below is using NSLog to show which process Id each closure is being run from. This is to easily tell from the console whether they’re both running on the same thread or not.
What did you expect to happen?
The process ID from the spec and configuration classes should match.
What actually happened instead?
The process ID from the spec and configuration classes don't match.
Adding
configuration.afterEach { @MainActor in
makes the process IDs match.Environment
List the software versions you're using:
Please also mention which package manager you used and its version. Delete the
other package managers in this list:
The text was updated successfully, but these errors were encountered: