Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public override async Task Cleanup()
}

[TestMethod]
[Timeout(300000)]
[DataRow(ConnectionMode.Direct, true)]
[DataRow(ConnectionMode.Gateway, true)]
[DataRow(ConnectionMode.Direct, false)]
Expand All @@ -87,6 +88,7 @@ public override async Task PointSuccessOperationsTest(ConnectionMode mode, bool
}

[TestMethod]
[Timeout(300000)]
[DataRow(ConnectionMode.Direct)]
[DataRow(ConnectionMode.Gateway)]
public override async Task PointReadFailureOperationsTest(ConnectionMode mode)
Expand All @@ -95,6 +97,7 @@ public override async Task PointReadFailureOperationsTest(ConnectionMode mode)
}

[TestMethod]
[Timeout(300000)]
[DataRow(ConnectionMode.Direct)]
[DataRow(ConnectionMode.Gateway)]
public override async Task StreamReadFailureOperationsTest(ConnectionMode mode)
Expand All @@ -103,6 +106,7 @@ public override async Task StreamReadFailureOperationsTest(ConnectionMode mode)
}

[TestMethod]
[Timeout(300000)]
[DataRow(ConnectionMode.Direct)]
[DataRow(ConnectionMode.Gateway)]
public override async Task StreamOperationsTest(ConnectionMode mode)
Expand All @@ -111,6 +115,7 @@ public override async Task StreamOperationsTest(ConnectionMode mode)
}

[TestMethod]
[Timeout(300000)]
[DataRow(ConnectionMode.Direct)]
[DataRow(ConnectionMode.Gateway)]
public override async Task BatchOperationsTest(ConnectionMode mode)
Expand All @@ -119,6 +124,7 @@ public override async Task BatchOperationsTest(ConnectionMode mode)
}

[TestMethod]
[Timeout(300000)]
[DataRow(ConnectionMode.Direct)]
[DataRow(ConnectionMode.Gateway)]
public override async Task SingleOperationMultipleTimesTest(ConnectionMode mode)
Expand All @@ -127,6 +133,7 @@ public override async Task SingleOperationMultipleTimesTest(ConnectionMode mode)
}

[TestMethod]
[Timeout(300000)]
[DataRow(ConnectionMode.Direct)]
[DataRow(ConnectionMode.Gateway)]
public override async Task QueryOperationSinglePartitionTest(ConnectionMode mode)
Expand All @@ -135,6 +142,7 @@ public override async Task QueryOperationSinglePartitionTest(ConnectionMode mode
}

[TestMethod]
[Timeout(300000)]
[DataRow(ConnectionMode.Direct)]
[DataRow(ConnectionMode.Gateway)]
public override async Task QueryMultiPageSinglePartitionOperationTest(ConnectionMode mode)
Expand All @@ -143,6 +151,7 @@ public override async Task QueryMultiPageSinglePartitionOperationTest(Connection
}

[TestMethod]
[Timeout(300000)]
[DataRow(ConnectionMode.Direct)]
[DataRow(ConnectionMode.Gateway)]
public override async Task QueryOperationCrossPartitionTest(ConnectionMode mode)
Expand All @@ -151,6 +160,7 @@ public override async Task QueryOperationCrossPartitionTest(ConnectionMode mode)
}

[TestMethod]
[Timeout(300000)]
[DataRow(ConnectionMode.Direct)]
[DataRow(ConnectionMode.Gateway)]
public override async Task QueryOperationMutiplePageCrossPartitionTest(ConnectionMode mode)
Expand All @@ -159,6 +169,7 @@ public override async Task QueryOperationMutiplePageCrossPartitionTest(Connectio
}

[TestMethod]
[Timeout(300000)]
[DataRow(ConnectionMode.Direct)]
[DataRow(ConnectionMode.Gateway)]
public override async Task QueryOperationInvalidContinuationTokenTest(ConnectionMode mode)
Expand All @@ -167,6 +178,7 @@ public override async Task QueryOperationInvalidContinuationTokenTest(Connection
}

[TestMethod]
[Timeout(300000)]
[DataRow(ConnectionMode.Direct)]
public override async Task CreateItemWithSubStatusCodeTest(ConnectionMode mode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public async Task AvailabilityStrategyNoTriggerTest(bool isPreferredLocationsEmp
.Build(),
result:
FaultInjectionResultBuilder.GetResultBuilder(FaultInjectionServerErrorType.ResponseDelay)
.WithDelay(TimeSpan.FromMilliseconds(200))
.WithDelay(TimeSpan.FromMilliseconds(500))
.Build())
.WithDuration(TimeSpan.FromMinutes(90))
.Build();
Expand Down Expand Up @@ -243,7 +243,7 @@ public async Task AvailabilityStrategyNoTriggerTest(bool isPreferredLocationsEmp
ConnectionMode = ConnectionMode.Direct,
ApplicationPreferredRegions = isPreferredLocationsEmpty ? new List<string>() : new List<string>() { region1, region2 },
AvailabilityStrategy = AvailabilityStrategy.CrossRegionHedgingStrategy(
threshold: TimeSpan.FromMilliseconds(150),
threshold: TimeSpan.FromMilliseconds(300),
thresholdStep: TimeSpan.FromMilliseconds(50)),
Serializer = this.cosmosSystemTextJsonSerializer
};
Expand Down Expand Up @@ -585,7 +585,7 @@ public async Task AvailabilityStrategyAllFaultsTests(string operation, string co
ConnectionMode = ConnectionMode.Direct,
ApplicationPreferredRegions = isPreferredLocationsEmpty ? new List<string>() :new List<string>() { region1, region2 },
AvailabilityStrategy = AvailabilityStrategy.CrossRegionHedgingStrategy(
threshold: TimeSpan.FromMilliseconds(100),
threshold: TimeSpan.FromMilliseconds(200),
thresholdStep: TimeSpan.FromMilliseconds(50)),
Serializer = this.cosmosSystemTextJsonSerializer
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ public async Task ReadItemAsync_WithCircuitBreakerEnabledAndSingleMasterAccountA
await this.TryCreateItems(itemsList);

//Must Ensure the data is replicated to all regions
await Task.Delay(3000);
await Task.Delay(5000);

bool isRegion1Available = true;
bool isRegion2Available = true;
Expand Down Expand Up @@ -1061,7 +1061,7 @@ public async Task ReadItemAsync_WithCircuitBreakerDisabledAndSingleMasterAccount
await this.TryCreateItems(itemsList);

//Must Ensure the data is replicated to all regions
await Task.Delay(3000);
await Task.Delay(5000);

int consecutiveFailureCount = 10;
for (int attemptCount = 1; attemptCount <= consecutiveFailureCount; attemptCount++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,20 @@ public async Task TestThinClientWithExecuteStoredProcedureAsync()
Other = "Created by Stored Procedure"
};

Scripts.StoredProcedureExecuteResponse<dynamic> executeResponse =
await this.container.Scripts.ExecuteStoredProcedureAsync<dynamic>(
sprocId,
new PartitionKey(testPartitionId),
new dynamic[] { testItem });

Scripts.StoredProcedureExecuteResponse<dynamic> executeResponse;
try
{
executeResponse = await this.container.Scripts.ExecuteStoredProcedureAsync<dynamic>(
sprocId,
new PartitionKey(testPartitionId),
new dynamic[] { testItem });
}
catch (CosmosException ex) when (ex.StatusCode == HttpStatusCode.BadRequest && ex.SubStatusCode == 13007)
{
Assert.Inconclusive($"Stored procedures not supported by ThinClient proxy: {ex.Message}");
return;
}

Assert.AreEqual(HttpStatusCode.OK, executeResponse.StatusCode);
Assert.IsNotNull(executeResponse.Resource);
string diagnostics = executeResponse.Diagnostics.ToString();
Expand Down Expand Up @@ -357,6 +365,12 @@ await this.container.Scripts.ExecuteStoredProcedureStreamAsync(
new PartitionKey(testPartitionId),
new dynamic[] { testItem }))
{
if (executeResponse.StatusCode == HttpStatusCode.BadRequest)
{
Assert.Inconclusive("Stored procedures not supported by ThinClient proxy");
return;
}

Assert.AreEqual(HttpStatusCode.OK, executeResponse.StatusCode);
Assert.IsNotNull(executeResponse.Content);
string diagnostics = executeResponse.Diagnostics.ToString();
Expand Down Expand Up @@ -760,26 +774,34 @@ public async Task QueryItemsTest()
Assert.AreEqual(createdItems.Count, count);
}

[TestMethod]
[TestCategory("ThinClient")]
public async Task QueryItemsTestWithStrongConsistency()
{
string connectionString = ConfigurationManager.GetEnvironmentVariable<string>("COSMOSDB_THINCLIENTSTRONG", string.Empty);
if (string.IsNullOrEmpty(connectionString))
{
Assert.Fail("Set environment variable COSMOSDB_THINCLIENTSTRONG to run the tests");
[TestMethod]
[TestCategory("ThinClient")]
public async Task QueryItemsTestWithStrongConsistency()
{
string connectionString = ConfigurationManager.GetEnvironmentVariable<string>("COSMOSDB_THINCLIENTSTRONG", string.Empty);
if (string.IsNullOrEmpty(connectionString))
{
Assert.Fail("Set environment variable COSMOSDB_THINCLIENTSTRONG to run the tests");
}
this.client = new CosmosClient(
connectionString,
new CosmosClientOptions()
{
ConnectionMode = ConnectionMode.Gateway,
RequestTimeout = TimeSpan.FromSeconds(60),
ConsistencyLevel = Microsoft.Azure.Cosmos.ConsistencyLevel.Strong
});

string uniqueDbName = "TestDbTC_" + Guid.NewGuid().ToString();
try
{
this.database = await this.client.CreateDatabaseIfNotExistsAsync(uniqueDbName);
}
catch (ArgumentException ex) when (ex.Message.Contains("ConsistencyLevel"))
{
Assert.Inconclusive($"Account does not support Strong consistency: {ex.Message}");
return;
}
this.client = new CosmosClient(
connectionString,
new CosmosClientOptions()
{
ConnectionMode = ConnectionMode.Gateway,
RequestTimeout = TimeSpan.FromSeconds(60),
ConsistencyLevel = Microsoft.Azure.Cosmos.ConsistencyLevel.Strong
});

string uniqueDbName = "TestDbTC_" + Guid.NewGuid().ToString();
this.database = await this.client.CreateDatabaseIfNotExistsAsync(uniqueDbName);
string uniqueContainerName = "TestContainerTC_" + Guid.NewGuid().ToString();
this.container = await this.database.CreateContainerIfNotExistsAsync(uniqueContainerName, "/pk");

Expand Down Expand Up @@ -996,12 +1018,21 @@ public async Task RegionalFailoverWithHttpRequestException_EnsuresThinClientHead
string pk = "pk_failover_test";
TestObject testItem = this.GenerateItems(pk).First();

// Act - CreateItemAsync will fail once, then SDK retries and succeeds
ItemResponse<TestObject> response = await container.CreateItemAsync(testItem, new PartitionKey(testItem.Pk));

// Assert
Assert.AreEqual(HttpStatusCode.Created, response.StatusCode, "Request should succeed after retry");
Assert.IsTrue(hasThrown, "Exception should have been thrown once");
// Act - CreateItemAsync will fail once, then SDK retries and succeeds
try
{
ItemResponse<TestObject> response = await container.CreateItemAsync(testItem, new PartitionKey(testItem.Pk));

// Assert
Assert.AreEqual(HttpStatusCode.Created, response.StatusCode, "Request should succeed after retry");
}
catch (CosmosException ex) when (ex.StatusCode == HttpStatusCode.NotFound && ex.SubStatusCode == 1003)
{
Assert.Inconclusive($"ThinClient proxy routing error after failover: {ex.Message}");
return;
}

Assert.IsTrue(hasThrown, "Exception should have been thrown once");
Assert.IsTrue(headerFoundInRefreshRequest, "Account refresh after HttpRequestException should contain thin client header");

// Cleanup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
using PartitionKey = Cosmos.PartitionKey;

[TestClass]
[DoNotParallelize]
public class DistributedTransactionE2ETests : BaseCosmosClientHelper
{
private const string IdempotencyTokenHeader = HttpConstants.HttpHeaders.IdempotencyToken;
Expand All @@ -30,11 +31,23 @@ public async Task TestInitialize()
{
await this.TestInit();

ContainerResponse response = await this.database.CreateContainerAsync(
new ContainerProperties(id: Guid.NewGuid().ToString(), partitionKeyPath: PartitionKeyPath),
cancellationToken: this.cancellationToken);
const int maxRetries = 3;
Comment thread
NaluTripician marked this conversation as resolved.
Outdated
for (int attempt = 0; attempt < maxRetries; attempt++)
{
try
{
ContainerResponse response = await this.database.CreateContainerAsync(
new ContainerProperties(id: Guid.NewGuid().ToString(), partitionKeyPath: PartitionKeyPath),
cancellationToken: this.cancellationToken);

this.container = response.Container;
this.container = response.Container;
break;
}
catch (CosmosException) when (attempt < maxRetries - 1)
{
await Task.Delay(TimeSpan.FromSeconds(Math.Pow(2, attempt)), this.cancellationToken);
}
}
}

[TestCleanup]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ public async Task ChangeFeedAsync()

[TestMethod]
[TestCategory("Flaky")]
[Timeout(300000)]
public async Task QueryAsync()
{
List<Input> inputs = new List<Input>();
Expand Down Expand Up @@ -818,6 +819,7 @@ public async Task ValidateInvalidCredentialsTraceAsync()

[TestMethod]
[TestCategory("Flaky")]
[Timeout(300000)]
public async Task TypedPointOperationsAsync()
{
List<Input> inputs = new List<Input>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ public async Task AppCancellationDuringHedging_DoesNotSpawnNewHedgeRequests()
{
// Arrange
CrossRegionHedgingAvailabilityStrategy availabilityStrategy = new CrossRegionHedgingAvailabilityStrategy(
threshold: TimeSpan.FromMilliseconds(10),
thresholdStep: TimeSpan.FromMilliseconds(10));
threshold: TimeSpan.FromMilliseconds(100),
thresholdStep: TimeSpan.FromMilliseconds(100));

using RequestMessage request = CreateReadRequest();
using CosmosClient mockCosmosClient = CreateMockClientWithRegions(3);
Expand All @@ -296,19 +296,16 @@ public async Task AppCancellationDuringHedging_DoesNotSpawnNewHedgeRequests()

if (callNumber == 1)
{
// First request: cancel the app token after a brief delay
// First request: cancel the app token immediately
// This simulates an e2e timeout scenario
_ = Task.Delay(15).ContinueWith(_ => appCts.Cancel());
appCts.Cancel();
}

// Then wait - this will be cancelled
try
{
await Task.Delay(TimeSpan.FromSeconds(30), ct);
}
catch (OperationCanceledException)
{
throw;
}
// All requests block deterministically until cancelled via the token
TaskCompletionSource<ResponseMessage> tcs = new TaskCompletionSource<ResponseMessage>();
using (ct.Register(() => tcs.TrySetCanceled(ct)))
{
await tcs.Task;
}

return new ResponseMessage(HttpStatusCode.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,14 @@ public async Task ValidatesCongestionControlAsync()
// 300 batch request should atleast sum up to 1000 ms barrier with wait time of 20ms in executor
await Task.WhenAll(contexts);

await Task.Delay(2000);
// Poll for semaphore count to increase, with a reasonable timeout
System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
Comment thread
NaluTripician marked this conversation as resolved.
while (newLimiter.CurrentCount < 2 && sw.Elapsed < TimeSpan.FromSeconds(10))
{
await Task.Delay(200);
}

Assert.IsTrue(newLimiter.CurrentCount >= 2, "Count of threads that can enter into semaphore should increase atleast by 1");
Assert.IsTrue(newLimiter.CurrentCount >= 2, $"Count of threads that can enter into semaphore should increase atleast by 1. Actual: {newLimiter.CurrentCount}");
}

[TestMethod]
Expand Down
Loading