Create analyzer for test projects that ensures all awaits have a timeout configured
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
A common cause of unit test hangs are awaiting a task that never completes because of a thread-safety issue. We get around this by calling an extension method that adds a time limit to the await.
https://github.com/aspnet/AspNetCore/blob/49c01eefecf1dbd75e5536aa803d689390c6770a/src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionTests.Protocol.cs#L78-L88
Instead of awaiting a task forever an exception will be thrown after 5 seconds, the test will fail, and the build will continue.
Today the timeout extension method is added ad-hoc. Someone might be contentious and always add the timeout when writing async code, or they add it later when they encounter a hang when running the tests locally or in CI.
It would be useful to have a Roslyn analyzer for test projects that remind developers to always add timeouts to their tests. ASP.NET Core tests would avoid annoying hangs and run more reliably.
Contributor guide
Assessment
This issue has not been assessed yet.