-
Notifications
You must be signed in to change notification settings - Fork 102
add a timeout to confirmation expectation #978
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
Comments
nit - I don't know how |
You can resolve your issue by running your
It is not the same mechanism as |
Duplicate of #788 |
I should clarify: we are tracking whether or not we should add a timeout, however most needs for one in Swift Testing tend to be solvable using Swift concurrency. An experimental implementation is available at #789. |
I am aware that I COULD, but I have it in its own task to make sure the stream gets cleaned up with ARC after completion. I don't recall if I tested both ways, tbh, but I don't think the stream gets cleaned up until the end of scope, which wouldn't trigger the Maybe I didn't run it, I don't remember anymore. I do a lot of iterations. :D Anyways, good to know it's on the team's radar. |
|
Yes, but AsyncStream has a couple subtypes for storage and context that are (and have deinits that trigger cleanup, including the Honestly, I can't remember what my original thinking was anymore. Perhaps the intent was that the Task was simulating an isolated concurrency context? I don't know. I was writing tests for my custom AsyncSequence implementation and happened upon a weird situation resembling the other issue where the expectation would fire, but the test was failing with a claim that there were no expectations completing. Once I realized it was a race condition, I simply tweaked things until it would be something that would consistently demonstrate the issue to post here. Thank you for your explanations though! |
Happy to help—sorry if this wasn't a productive discussion! Please feel free to reach out in the forums if you run into further problems. |
Oh it was though! I learned and introspected several times :) |
Motivation
Here's a situation where running tests with an asynchronous expectation causes
confirmation
to conclude that the expectation never ran, but prematurely.If you run this as is,
confirmation
concludes thatterminatedExpectation
will never get called, therefore the test fails. However, if we uncomment the last line and add a short delay to give what I assume is ARC and stack unwinding to cleanup the Task contents, causingonTermination
's closure to trigger prior toconfirmation
finishing, we are all good.Proposed solution
Add a timeout to
Testing.Confirmation
. This would replicate my simple fix that was commented out in the sample code above.Now, I realize this is a bit fuzzy and potentially indeterminate... What if the system is running slow enough that the cleanup doesn't happen in time for the timeout? However, I don't see any other way to refactor this test that wouldn't be susceptible to this. And the default could be set to zero so it's identical to what it does now unless deliberately overridden.
Alternatives considered
Refactor the test in some way that would alleviate this issue, but I'm not seeing a way to do so.
Additional information
No response
The text was updated successfully, but these errors were encountered: