Skip to content

Commit cd565c7

Browse files
committed
Fix tests
1 parent abc6b83 commit cd565c7

1 file changed

Lines changed: 11 additions & 21 deletions

File tree

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ReadConsistencyStrategyTests.cs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -232,19 +232,14 @@ public async Task ReadManyWithReadConsistencyStrategy()
232232
Assert.AreEqual(itemsToRead.Count, response.Count, "ReadMany with ReadConsistencyStrategy should return all requested items");
233233
}
234234

235-
/// <summary>
236-
/// Verifies that the Direct layer's ServerStoreModel rejects requests when both
237-
/// x-ms-consistency-level and x-ms-cosmos-read-consistency-strategy headers are set.
238-
/// This guards against SDK regressions that accidentally send both headers.
239-
/// </summary>
240235
[TestMethod]
241-
public async Task DualConsistencyHeadersRejectedWithBadRequest()
236+
public async Task DualConsistencyHeadersAcceptedReadConsistencyStrategyTakesPrecedence()
242237
{
243238
ToDoActivity testItem = ToDoActivity.CreateRandomToDoActivity();
244239
await this.Container.CreateItemAsync(testItem);
245240

246241
// Inject both headers manually via a custom handler to bypass SDK's logic
247-
// that normally prevents this.
242+
// that normally only sends one of them.
248243
RequestHandlerHelper headerInjector = new RequestHandlerHelper();
249244
headerInjector.UpdateRequestMessage = (request) =>
250245
{
@@ -253,7 +248,7 @@ public async Task DualConsistencyHeadersRejectedWithBadRequest()
253248
{
254249
request.Headers.Set(
255250
HttpConstants.HttpHeaders.ConsistencyLevel,
256-
Cosmos.ConsistencyLevel.Session.ToString());
251+
Cosmos.ConsistencyLevel.Eventual.ToString());
257252
request.Headers.Set(
258253
HttpConstants.HttpHeaders.ReadConsistencyStrategy,
259254
ReadConsistencyStrategy.Session.ToString());
@@ -269,20 +264,15 @@ public async Task DualConsistencyHeadersRejectedWithBadRequest()
269264
using CosmosClient customClient = TestCommon.CreateCosmosClient(clientOptions);
270265
Container container = customClient.GetContainer(this.database.Id, this.Container.Id);
271266

272-
try
273-
{
274-
await container.ReadItemAsync<ToDoActivity>(
275-
testItem.id,
276-
new Cosmos.PartitionKey(testItem.pk));
267+
ItemResponse<ToDoActivity> response = await container.ReadItemAsync<ToDoActivity>(
268+
testItem.id,
269+
new Cosmos.PartitionKey(testItem.pk));
277270

278-
Assert.Fail("Expected BadRequest when both ConsistencyLevel and ReadConsistencyStrategy headers are set");
279-
}
280-
catch (CosmosException ex) when (ex.StatusCode == HttpStatusCode.BadRequest)
281-
{
282-
Assert.IsTrue(
283-
ex.Message.Contains("Cannot specify both"),
284-
$"Error should mention dual header conflict. Got: {ex.Message}");
285-
}
271+
Assert.AreEqual(
272+
HttpStatusCode.OK,
273+
response.StatusCode,
274+
"Read with both ConsistencyLevel and ReadConsistencyStrategy headers should succeed (Direct package 3.43.1+ contract).");
275+
Assert.AreEqual(testItem.id, response.Resource.id);
286276
}
287277
}
288278
}

0 commit comments

Comments
 (0)