In unit testing, there are times were the SUT has to be exercised asynchronously.
How can we wait for the exercise to complete execution?
- An instance of the SUT can be created on the main thread.
- The main (waiting) thread spins in user mode while starting the exercise of the SUT asynchronously.
- Once the result has been received, the execution continues on the main thread.
- The assertion takes place.
- Once the
Taskhas been created it is immediately scheduled for execution by calling the
- As long as the unit test runs fast, the waiting thread spins in user mode, which is a good thing.
There is also a SpinUntil overload accepting a TimeSpan timeout.