We have experienced the same issue. And we, too, have used the await Task.yield()
. What we've noticed is that there are certain machines where running the test repeatedly will fail much more often than other machines. For example, I'm using an M1 mac and my colleague is using a late model intel based mac and these types of test fail much more often for him. Sometimes even running the test once will fail for him. And sometimes tests with these yield statements will never fail for me even if I run the test hundreds of times repeatedly.
I would love to hear the preferred solution. Thank you for asking this question.