Reliably testing code that adopts Swift Concurrency?

Not resurrecting this thread to suggest relying on Task.yield() is a good idea (though I imagine folks will rely on it till there are better tools to assist testing async code), but I did notice that this behavior has gotten much worse in the Xcode 14 betas. Previously, the single Task.yield() would result in a passing test 99% of the time, but now if fails far more often than not. I need to do a "mega" yield for it to consistently pass on my machine:

await Task.detached(priority: .low) { await Task.yield() }.value
await Task.detached(priority: .low) { await Task.yield() }.value
await Task.detached(priority: .low) { await Task.yield() }.value

This is just to let the team know that there may be performance regressions in the latest concurrency runtime.

9 Likes