-
Notifications
You must be signed in to change notification settings - Fork 10k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove blocking APIs in asp.net core integration tests code #43353
Comments
That TestServer constructor is no longer necessary, it was replaced by the following and only remains for back-compat, we could consider obsoleting it.
That Start extension method is also not necessary, it's only there for convenience. In a normal app it would only be called once and would be harmless. I agree it is a bit of a trap though. |
@Tratcher I'm not sure I understand. |
I meant it's harmless when the app is run in a development or production environment where there's only one instance per process. I see how it's problematic in a parallel test environment with many instances. |
Triage: we could do a bunch of |
@adityamandaleeka no way of making it truly async? |
@gdoron async versions of these APIs already exist. The only thing we can change here is discouraging people from using the old sync ones. |
@Tratcher how can one use the async versions when using \ deriving from |
Fair point, I hadn't reviewed WebApplicationFactory. This usage looks async safe:
This one looks unsafe, CreateHost should be async:
|
@Tratcher any chance having this sorted for 8.0 or even a minor version of 7? |
Yes, we plan to look at it in 8. If you want to try fixing it that would be helpful. |
@Tratcher just making sure this was not forgotten. |
Possible workaround mentioned here https://www.strathweb.com/2021/05/the-curious-case-of-asp-net-core-integration-test-deadlock/ Subclass WebApplicationFactory:
|
This would still be a huge improvement to integration tests, especially those that use async methods to seed data. Ideally we would add a |
@ardalis I doubt we'll be able to get to it in 9.0, but I've flagged it for review in 10.0. |
Is there an existing issue for this?
Describe the bug
Even on our very powerful Macbook pros, when we are running one of our integration test projects that has hundreds of tests, many of which use WebApplicationFactory we often get into deadlocks.
We set xunit to use unlimited amount of threads (-1), we have overridden a bunch of xunit stuff to implement a semaphore to limit the number of concurrent tests.
And yet, often we get into deadlocks after the ~600 tests completed mark.
After verifying we have no sync-over-async, we found this beauty in asp.net core code itself...
https://github.com/dotnet/aspnetcore/blob/main/src/Hosting/TestHost/src/TestServer.cs#L101
As well as this: https://github.com/dotnet/runtime/blob/2be87c9c976c0cd21b66ea12ae406a559aacaac0/src/libraries/Microsoft.Extensions.Hosting.Abstractions/src/HostingAbstractionsHostExtensions.cs#L19
later on when we managed to reproduce the deadlock (after a very high number of attempts).
Bear in mind, xUnit which is by far the number 1 testing framework for .NET Core has SynchronizationContexts, even if this issue would be solved, there is still the
MaxConcurrencySyncContext
which I can only assume would still be used by default.Can we please remove the sync over async anti pattern from our beloved framework?
Best,
Doron
The text was updated successfully, but these errors were encountered: