Repository navigation
Fix Cosmos tests when running against a real endpoint - #38710
Merged
Merged
Conversation
Co-authored-by: AndriySvyryd <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the reliability of EF Core Cosmos functional tests when running against a real Azure Cosmos DB endpoint (token credential auth or non-emulator keys), avoiding emulator-specific assumptions and brittle service error message checks.
Changes:
- Updates
CosmosSessionTokensTest.Read_item_uses_session_tokento assert onCosmosException.StatusCode(BadRequest) instead of matching a specificResponseBodymessage. - Fixes two
CosmosTransactionalBatchTestcases by selectingTokenCredentialvsAuthTokenbased onCosmosTestEnvironment.UseTokenCredential, preventing 401s against real endpoints.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/EFCore.Cosmos.FunctionalTests/CosmosTransactionalBatchTest.cs | Adjusts options setup to work with token-credential auth when running against real Cosmos endpoints. |
| test/EFCore.Cosmos.FunctionalTests/CosmosSessionTokensTest.cs | Makes the point-read session token assertion resilient to service-side error message wording changes. |
Comments suppressed due to low confidence (1)
test/EFCore.Cosmos.FunctionalTests/CosmosTransactionalBatchTest.cs:107
- This test can use CosmosTestStore.AddProviderOptions to handle the token-credential vs auth-key selection and ApplyConfiguration, avoiding duplicated branching and keeping the setup consistent with other Cosmos functional tests.
var store = (CosmosTestStore)Fixture.TestStore;
var optionsBuilder = new DbContextOptionsBuilder<TransactionalBatchContext>();
if (CosmosTestEnvironment.UseTokenCredential)
{
optionsBuilder.UseCosmos(store.ConnectionUri, store.TokenCredential, Fixture.TestStore.Name, cfg => cfg.ApplyConfiguration());
…seCosmos(lambda) Co-authored-by: AndriySvyryd <[email protected]>
AndriySvyryd
marked this pull request as ready for review
July 29, 2026 01:00
AndriySvyryd
enabled auto-merge (squash)
July 29, 2026 01:00
cincuranet
approved these changes
Jul 30, 2026
This was referenced Jul 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three tests fail when running against a real Azure Cosmos DB endpoint (token credential auth or non-emulator key).
Changes
CosmosSessionTokensTest.Read_item_uses_session_token: The Cosmos service changed the error message for invalid session tokens on point reads (ReadItemAsync), while the query API path still returns the old wording. Replaced the brittleResponseBodystring check withAssert.Equal(HttpStatusCode.BadRequest, ex.StatusCode).CosmosTransactionalBatchTest(two tests): Both tests manually constructedDbContextOptionsBuilderhardcoded to useAuthToken. WhenUseTokenCredential=true,AuthTokenis still the emulator default key, causing 401 Unauthorized against a real endpoint. Fixed by mirroring theCosmosTestStore.AddProviderOptionspattern — conditionally selectingTokenCredentialorAuthTokenbased onCosmosTestEnvironment.UseTokenCredential: