Open CraigSiemens opened 4 months ago
Yeah. This is unsurprising, but still disappointing. It's also a bug with Quick, not Nimble - you'd get similar behavior if you tried the following code:
class AsyncConfiguration: QuickConfiguration {
override class func configuration(_ configuration: QCKConfiguration) {
configuration.beforeEach {
let start = Date()
RunLoop.main.run(until: Date(timeIntervalSinceNow: 2))
expect(date.timeIntervalSince(start)).to(beCloseTo(2, within: 0.01)) // this assertion will fail when run with an async spec.
}
}
}
AsyncExample will run the stuff in your QuickConfiguration
, as a matter of fact. This is desired because using any kind of waiting behavior in that kind of global configuration is an edge case (QuickConfiguration
is meant more for doing stuff like configuring your test suite, not waiting for stuff to be available).
This is an issue when you try to run the sync versions of waitUntil
, toEventually
, etc. because those use APIs which no-op when run in an async context.
Possibly we might be able to get around this by detecting these cases and run them on the main actor using MainActor.run
, similar to what we do for the suite hooks (i.e. the beforeSuite
and afterSuite
things) (see https://github.com/Quick/Quick/blob/main/Sources/Quick/Examples/AsyncExample.swift#L38-L40).
What did you do?
If a
QuickConfiguration
contains a call towaitUntil
, it will always timeout when running anAsyncSpec
. In our case, we're using beforeSuite and afterSuite to call asynchronous methods to save and restore the values in the keychain to avoidBelow is the simplest way I could find to reproduce it. The test will always fail with the message
What did you expect to happen?
waitUntil
doesn't timeout when the test is a subclass ofQuickSpec
.What actually happened instead?
The closure passed to
waitUntil
is never called. Neither a breakpoint or a print are called until afterwaitUntil
has timed out.Increasing the timeout interval has no affect. The test will always wait the full timeout before failing.
The test failed with the following message.
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:
Project that demonstrates the issue
I reproduced it with the Quick repo, since I wasn't sure which repo was the cause of the issue.
pbpaste | git apply