-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
TransactionScope not working with HttpClient in integration tests #18001
Comments
Similar issue: dotnet/efcore#18657 |
All yours @javiercn |
I'm in the exact same boat. Upgrading from 2.2 to 3.1. Existing code is using the The Entity Framework guys seem to say "it's working for us" ... but I'm not using EF, I'm using Dapper... so I don't have "DbContext" to put into DI... so maybe they have more control over the situation? Thinking maybe I should just use DI to register a custom Db Connection Factory where I can have more explicit control over the connections/transaction-enlistment, rather than relying on the "magic" in Ambient Transactions? Do I really need to do all that tho? I feels like something is missing? |
This is by design but there’s a flag to get the old behavior back on TestServer called PreserveExecutionContext. We basically by default want to avoid it flowing from client to server by default but for more esoteric cases, you can turn it on |
@davidfowl Thanks! This line fixed the problem |
it's a 🎄 miracle! thank you! |
Yes @NickFranceschina, a xmas miracle indeed! Thank you @niksloter74 @davidfowl for this xmas gift 😄 |
@davidfowl: I'm curious as to why you made such a breaking change without giving notice? It should definitively be in this document: https://docs.microsoft.com/en-us/dotnet/core/compatibility/2.2-3.1 |
We should document this change @Tratcher |
Describe the bug
After upgrading from .net core 2.2 to 3.1, integration tests are failing.
All tests are wrapped in TransactionScope so that all changes to db should be revered (scope.Complete() is not called).
When call to the data access layer is made through api (HttpClient) records are created in the database, but they should not be since the entire test is wrapped in TransactionScope.
To Reproduce
`
There are many files/classes involved so I've created a example repository
Example tests that are failing are in https://github.com/niksloter74/web-api-integration-test/tree/master/netcore3.1
Working example in .net core 2.2
https://github.com/niksloter74/web-api-integration-test/tree/master/netcore2.2
Direct test for service layer is working correctly
`
Further technical details
.NET Core SDK (reflecting any global.json):
Version: 3.1.100
Commit: cd82f021f4
Runtime Environment:
OS Name: Windows
OS Version: 6.3.9600
OS Platform: Windows
RID: win81-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.100\
Host (useful for support):
Version: 3.1.0
Commit: 65f04fb6db
.NET Core SDKs installed:
2.1.2 [C:\Program Files\dotnet\sdk]
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.505 [C:\Program Files\dotnet\sdk]
2.1.507 [C:\Program Files\dotnet\sdk]
2.1.700 [C:\Program Files\dotnet\sdk]
2.1.701 [C:\Program Files\dotnet\sdk]
2.2.107 [C:\Program Files\dotnet\sdk]
2.2.300 [C:\Program Files\dotnet\sdk]
2.2.301 [C:\Program Files\dotnet\sdk]
3.1.100 [C:\Program Files\dotnet\sdk]
The text was updated successfully, but these errors were encountered: