If I have a method:
public async Task<string> Get()
{
Task<string> a = _db.GetSomething();
Task<string> b = _db.GetSomethingElse();
await Task.WhenAll(a, b);
return a.Result + b.Result;
}
I don't fully control the code in _db
, and would like a way to programatically verify that they are using non-blocking io inside. Yes, they have converted to a Task
based api, but that could easily be accomplished with Task.Factory.StartNew
and still use blocking IO underneath. That would be undesired in this case.
I do have access to the code, so I can see that they are indeed using Task Factory inside, so decompiling is not really what I am looking for. Ideally I could write a unit test to verify the threading behaviour moving forward.
Is there a way I can somehow check the worker thread count at various points and verify that threads are or are not being blocked in any of these child tasks?