Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
54def19
Initial plan
Copilot Feb 17, 2026
a63af21
Fix flaky tests - improve timing and assertions
Copilot Feb 17, 2026
a14e8e7
Fix additional flaky tests - increase timeouts and add retry analyzer
Copilot Feb 18, 2026
95e09e1
Fix bulk query and Spark metrics race conditions
Copilot Feb 18, 2026
b3de6ed
Fix NullPointerException in circuit breaker tests - lazy init regions
Copilot Feb 18, 2026
479b995
Fix additional flaky tests - increase timeouts and add retry analyzers
Copilot Feb 19, 2026
b21694c
Address code review feedback - improve exception handling and NPE safety
Copilot Feb 20, 2026
0f35ec1
Fix flaky PartitionControllerImplTests.handleMerge - relax acquire ve…
Copilot Feb 20, 2026
7265d8c
Fix flaky PointWriterITest.createItemWithDuplicates - increase retry …
Copilot Feb 20, 2026
f375096
Fix flaky write retry tests - add retry analyzers and increase retry …
Copilot Feb 20, 2026
1954acc
Fix flaky SparkE2EWriteITest.supportUpserts - wait for onTaskEnd call…
Copilot Feb 20, 2026
2f76986
Fix ContainerCreateDeleteWithSameNameTest.bulk - increase indexing de…
Copilot Feb 20, 2026
26dfc86
Fix PointWriterITest.upsertItemsIfNotModified - use eventually block …
Copilot Feb 20, 2026
94d4b9a
Fix Scala compilation error - convert Int to Long for type compatibility
Copilot Feb 20, 2026
5736061
Merge branch 'main' into copilot/fix-flaky-tests-java-ci
kushagraThapar Feb 21, 2026
f48378e
Fix PartitionControllerImplTests.handleMerge - relax create verificat…
Copilot Feb 21, 2026
dc5c46b
Fix PartitionControllerImplTests.handleMerge - relax release verifica…
Copilot Feb 21, 2026
1d7cde2
Fix additional flaky Cosmos DB tests beyond PR #48025
kushagraThapar Feb 21, 2026
86cf1c4
Fix ReproTest assertion and increase ClientRetryPolicyE2ETests timeouts
kushagraThapar Feb 21, 2026
bb5686a
Add transient error retry to TestSuiteBase create methods
kushagraThapar Feb 21, 2026
75049e9
Fix remaining flaky tests from CI run buildId=5909542
Copilot Feb 22, 2026
963b2c7
Fix PartitionControllerImplTests.handleMerge - relax updateProperties…
Copilot Feb 22, 2026
9f99207
Merge branch 'copilot/fix-flaky-tests-java-ci' of github.com:Azure/az…
kushagraThapar Feb 22, 2026
a6cc421
Update sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/r…
kushagraThapar Feb 22, 2026
cb6394e
Update sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/r…
kushagraThapar Feb 22, 2026
085e502
Update sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/i…
kushagraThapar Feb 22, 2026
b227221
Update sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/c…
kushagraThapar Feb 22, 2026
e01f179
Update sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/E…
kushagraThapar Feb 22, 2026
60cab29
Replace fixed sleeps with retry-based polling for CI resilience
kushagraThapar Feb 22, 2026
2a5ecf9
Add missing static import for Mockito.timeout in PartitionControllerI…
kushagraThapar Feb 22, 2026
8ce5655
Fix PartitionControllerImplTests.handleMerge race condition
kushagraThapar Feb 23, 2026
9fa0a11
Fix flaky Cosmos DB tests for CI stability
kushagraThapar Feb 23, 2026
b6046ae
Fix PointWriterITest.upsertItemsIfNotModified indexing race condition
kushagraThapar Feb 23, 2026
5269dc0
Fix ExcludeRegionTests and add retry for transient CI failures
kushagraThapar Feb 23, 2026
0375371
Fix CosmosBulkGatewayTest 409 conflict in setup and upgrade FI test r…
kushagraThapar Feb 24, 2026
2617356
Merge branch 'main' into kushagrathapar/fix-additional-flaky-cosmos-t…
kushagraThapar Feb 24, 2026
d6c194a
Fix flaky Cosmos tests: add retry analyzers and polling waits
kushagraThapar Feb 24, 2026
98d8e01
Fix additional flaky Cosmos tests for CI stability
kushagraThapar Feb 24, 2026
76f877f
Fix flaky tests: add retryAnalyzer, increase e2e timeout, resilient c…
kushagraThapar Feb 25, 2026
ad2cc42
Fix flaky tests: add retry analyzers and increase 429 retry resilience
kushagraThapar Feb 25, 2026
6da00d0
Fix flaky tests: retry analyzers, timeouts, client leak prevention
kushagraThapar Feb 25, 2026
578e384
Fix flaky tests: ResourceTokenTest cleanup and IncrementalChangeFeedP…
kushagraThapar Feb 26, 2026
8a78419
Fix cascading test failures with retry logic in @BeforeClass setup me…
kushagraThapar Feb 26, 2026
30048f8
Fix CosmosItemTest.readManyWithTwoSecondariesNotReachable for Strong …
kushagraThapar Feb 26, 2026
98452ad
Fix ReadQuorumNotMet error message missing String.format
kushagraThapar Feb 26, 2026
c68210e
Fix ContainerCreateDeleteWithSameNameTest.bulk flakiness
kushagraThapar Feb 26, 2026
c47a46e
Fix flaky tests: 429 backoff, FI write timeout, retry analyzer, resil…
kushagraThapar Feb 27, 2026
fb2a594
Fix PointWriterITest.upsertItemsIfNotModified metrics race condition
kushagraThapar Feb 27, 2026
c74119f
Fix flaky tests: conflicts retry, FI setup retry, timeout increase
kushagraThapar Feb 27, 2026
a463297
Address all PR #48064 review comments
kushagraThapar Feb 27, 2026
b7d041c
Fix compilation error: lambda requires effectively final variable
kushagraThapar Feb 27, 2026
e092d8f
Fix SessionRetryOptionsTests flaky duration assertion
kushagraThapar Feb 28, 2026
1a2e343
Fix CosmosItemWriteRetriesTest.upsertItem flakiness
kushagraThapar Feb 28, 2026
e769107
Merge branch 'main' into kushagrathapar/fix-additional-flaky-cosmos-t…
FabianMeiswinkel Mar 2, 2026
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 @@ -272,9 +272,26 @@ public void before_WorkflowTest() {
options.setOfferThroughput(10000);
AsyncDocumentClient housekeepingClient = Utils.housekeepingClient();
database = Utils.createDatabaseForTest(housekeepingClient);
collection = housekeepingClient.createCollection("dbs/" + database.getId(),
getCollectionDefinitionWithRangeRangeIndex(),
options).block().getResource();
// Retry collection creation on transient failures (408, 429, 503)
int maxRetries = 3;
for (int attempt = 0; attempt <= maxRetries; attempt++) {
try {
collection = housekeepingClient.createCollection("dbs/" + database.getId(),
getCollectionDefinitionWithRangeRangeIndex(),
options).block().getResource();
break;
} catch (Exception e) {
if (attempt == maxRetries) {
throw e;
}
try {
Thread.sleep(5000);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw new RuntimeException(ie);
}
}
}
housekeepingClient.close();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import com.fasterxml.jackson.databind.node.ObjectNode
import org.apache.commons.lang3.RandomUtils
import org.apache.spark.MockTaskContext
import org.apache.spark.sql.types.{BooleanType, DoubleType, FloatType, IntegerType, LongType, StringType, StructField, StructType}
import org.scalatest.concurrent.Eventually.eventually
import org.scalatest.concurrent.Waiters.{interval, timeout}
import org.scalatest.time.SpanSugar.convertIntToGrainOfTime

import scala.collection.concurrent.TrieMap
import scala.collection.mutable
Expand Down Expand Up @@ -218,7 +221,7 @@ class PointWriterITest extends IntegrationSpec with CosmosClient with AutoCleana
val container = getContainer
val containerProperties = container.read().block().getProperties
val partitionKeyDefinition = containerProperties.getPartitionKeyDefinition
val writeConfig = CosmosWriteConfig(ItemWriteStrategy.ItemAppend, maxRetryCount = 0, bulkEnabled = false, bulkTransactional = false)
val writeConfig = CosmosWriteConfig(ItemWriteStrategy.ItemAppend, maxRetryCount = 3, bulkEnabled = false, bulkTransactional = false)
val pointWriter = new PointWriter(
container,
partitionKeyDefinition,
Expand Down Expand Up @@ -274,10 +277,19 @@ class PointWriterITest extends IntegrationSpec with CosmosClient with AutoCleana
}

pointWriter.flushAndClose()
val allItems = readAllItems()

allItems should have size items.size
metricsPublisher.getRecordsWrittenSnapshot() shouldEqual items.size
// Poll until all items are indexed and visible via query
// readAllItems() uses a query which depends on indexing completion
var allItems = readAllItems()
eventually(timeout(10.seconds), interval(500.milliseconds)) {
allItems = readAllItems()
allItems should have size items.size
}

// Poll until metrics are fully recorded after flush
eventually(timeout(10.seconds), interval(100.milliseconds)) {
metricsPublisher.getRecordsWrittenSnapshot() shouldEqual items.size
}
metricsPublisher.getBytesWrittenSnapshot() > 0 shouldEqual true
metricsPublisher.getTotalRequestChargeSnapshot() > 5 * items.size shouldEqual true
metricsPublisher.getTotalRequestChargeSnapshot() < 10 * items.size shouldEqual true
Expand All @@ -303,6 +315,13 @@ class PointWriterITest extends IntegrationSpec with CosmosClient with AutoCleana

pointWriter.flushAndClose()

// Wait for metrics to be fully aggregated after flush
// This prevents race conditions where metrics snapshot is taken before all writes are recorded
// Use eventually block to poll until the expected count is reached
eventually(timeout(10.seconds), interval(100.milliseconds)) {
metricsPublisher.getRecordsWrittenSnapshot() should be >= (2 * items.size).toLong
}

metricsPublisher.getRecordsWrittenSnapshot() shouldEqual 2 * items.size
metricsPublisher.getBytesWrittenSnapshot() > 0 shouldEqual true
metricsPublisher.getTotalRequestChargeSnapshot() > 5 * 2 * items.size shouldEqual true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class PointWriterSubpartitionITest extends IntegrationSpec with CosmosClient wit
val container = getContainer
val containerProperties = container.read().block().getProperties
val partitionKeyDefinition = containerProperties.getPartitionKeyDefinition
val writeConfig = CosmosWriteConfig(ItemWriteStrategy.ItemAppend, maxRetryCount = 0, bulkEnabled = false, bulkTransactional = false)
val writeConfig = CosmosWriteConfig(ItemWriteStrategy.ItemAppend, maxRetryCount = 3, bulkEnabled = false, bulkTransactional = false)
val pointWriter = new PointWriter(
container, partitionKeyDefinition, writeConfig, DiagnosticsConfig(), MockTaskContext.mockTaskContext(),new TestOutputMetricsPublisher)
val items = new mutable.HashMap[String, mutable.Set[ObjectNode]] with mutable.MultiMap[String, ObjectNode]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ class SparkE2EWriteITest
statusStore.executionsList().last.metricValues != null)
}

// Wait for onTaskEnd callback to update snapshot variables
// The callback fires asynchronously after metrics are computed
eventually(timeout(10.seconds), interval(10.milliseconds)) {
assert(recordsWrittenSnapshot > 0)
}

recordsWrittenSnapshot shouldEqual 1
bytesWrittenSnapshot > 0 shouldEqual true
if (!spark.sparkContext.version.startsWith("3.1.")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package com.azure.cosmos;

import com.azure.cosmos.FlakyTestRetryAnalyzer;
import com.azure.cosmos.implementation.AsyncDocumentClient;
import com.azure.cosmos.implementation.Configs;
import com.azure.cosmos.implementation.DiagnosticsProvider;
Expand Down Expand Up @@ -85,7 +86,7 @@ public ClientMetricsTest(CosmosClientBuilder clientBuilder) {
super(clientBuilder);
}

@Test(groups = { "fast" }, timeOut = TIMEOUT)
@Test(groups = { "fast" }, timeOut = SETUP_TIMEOUT)
public void maxValueExceedingDefinedLimitStillWorksWithoutException() throws Exception {

// Expected behavior is that higher values than the expected max value can still be recorded
Expand Down Expand Up @@ -133,7 +134,7 @@ public void maxValueExceedingDefinedLimitStillWorksWithoutException() throws Exc
}
}

@Test(groups = { "fast" }, timeOut = TIMEOUT)
@Test(groups = { "fast" }, timeOut = TIMEOUT, retryAnalyzer = FlakyTestRetryAnalyzer.class)
public void createItem() throws Exception {
boolean[] disableLatencyMeterTestCases = { false, true };

Expand Down Expand Up @@ -274,7 +275,10 @@ public void createItemWithAllMetrics() throws Exception {
}
}

@Test(groups = { "fast" }, timeOut = TIMEOUT)
// Increased timeout from TIMEOUT to SETUP_TIMEOUT to account for collection creation time
// during TestState initialization, especially in CI environments where collection creation
// can take longer than 40 seconds
@Test(groups = { "fast" }, timeOut = SETUP_TIMEOUT)
public void readItem() throws Exception {
try (TestState state = new TestState(getClientBuilder(), CosmosMetricCategory.DEFAULT)) {
InternalObjectNode properties = getDocumentDefinition(UUID.randomUUID().toString());
Expand Down Expand Up @@ -336,7 +340,7 @@ public void readNonExistingItem() throws Exception {
}
}

@Test(groups = { "fast" }, timeOut = TIMEOUT)
@Test(groups = { "fast" }, timeOut = TIMEOUT, retryAnalyzer = FlakyTestRetryAnalyzer.class)
public void readManySingleItem() throws Exception {
try (TestState state = new TestState(getClientBuilder(), CosmosMetricCategory.DEFAULT)) {
InternalObjectNode properties = getDocumentDefinition(UUID.randomUUID().toString());
Expand Down Expand Up @@ -464,7 +468,9 @@ public void readItemWithThresholdsApplied() throws Exception {
runReadItemTestWithThresholds(minThresholds, true);
}

@Test(groups = { "fast" }, timeOut = TIMEOUT)
// TestState constructor creates a new client and collection, which can exceed 40s in CI.
// Using SETUP_TIMEOUT (60s) instead of SuperFlakyTestRetryAnalyzer to give adequate time.
@Test(groups = { "fast" }, timeOut = SETUP_TIMEOUT, retryAnalyzer = FlakyTestRetryAnalyzer.class)
public void replaceItem() throws Exception {
try (TestState state = new TestState(getClientBuilder(), CosmosMetricCategory.DEFAULT)) {
InternalObjectNode properties = getDocumentDefinition(UUID.randomUUID().toString());
Expand Down Expand Up @@ -657,7 +663,7 @@ <T> CosmosItemResponse verifyExists(TestState state, String id, PartitionKey pk,
return response;
}

@Test(groups = { "fast" }, timeOut = TIMEOUT, retryAnalyzer = SuperFlakyTestRetryAnalyzer.class)
@Test(groups = { "fast" }, timeOut = SETUP_TIMEOUT, retryAnalyzer = FlakyTestRetryAnalyzer.class)
public void readAllItemsWithDetailMetricsWithExplicitPageSize() throws Exception {
try (TestState state = new TestState(getClientBuilder(),
CosmosMetricCategory.DEFAULT,
Expand Down Expand Up @@ -993,7 +999,7 @@ public void batchMultipleItemExecution() throws Exception {
}
}

@Test(groups = { "fast" }, timeOut = TIMEOUT)
@Test(groups = { "fast" }, timeOut = TIMEOUT * 2)
public void effectiveMetricCategoriesForDefault() throws Exception {
try (TestState state = new TestState(getClientBuilder(), CosmosMetricCategory.fromString("DeFAult"))) {
assertThat(state.getEffectiveMetricCategories().size()).isEqualTo(5);
Expand Down Expand Up @@ -1082,7 +1088,7 @@ public void effectiveMetricCategoriesForAll() throws Exception {
}
}

@Test(groups = { "fast" }, timeOut = TIMEOUT)
@Test(groups = { "fast" }, timeOut = SETUP_TIMEOUT, retryAnalyzer = FlakyTestRetryAnalyzer.class)
public void endpointMetricsAreDurable() throws Exception {
try (TestState state = new TestState(getClientBuilder(), CosmosMetricCategory.ALL)){
if (state.client.asyncClient().getConnectionPolicy().getConnectionMode() != ConnectionMode.DIRECT) {
Expand Down Expand Up @@ -1111,7 +1117,7 @@ public void endpointMetricsAreDurable() throws Exception {
}
}

@Test(groups = { "fast" }, timeOut = TIMEOUT)
@Test(groups = { "fast" }, timeOut = TIMEOUT * 2)
public void effectiveMetricCategoriesForAllLatebound() throws Exception {
try (TestState state = new TestState(getClientBuilder(), CosmosMetricCategory.DEFAULT)) {
EnumSet<MetricCategory> effectiveMetricCategories =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

import com.azure.cosmos.FlakyTestRetryAnalyzer;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;

Expand All @@ -63,19 +65,22 @@ public CosmosBulkAsyncTest(CosmosClientBuilder clientBuilder) {
@BeforeClass(groups = {"fast"}, timeOut = SETUP_TIMEOUT)
public void before_CosmosBulkAsyncTest() {
assertThat(this.bulkClient).isNull();
ThrottlingRetryOptions throttlingOptions = new ThrottlingRetryOptions()
.setMaxRetryAttemptsOnThrottledRequests(1000000)
.setMaxRetryWaitTime(Duration.ofDays(1));
this.bulkClient = getClientBuilder().throttlingRetryOptions(throttlingOptions).buildAsyncClient();
bulkAsyncContainer = getSharedMultiPartitionCosmosContainer(this.bulkClient);
executeWithRetry(() -> {
safeClose(this.bulkClient);
ThrottlingRetryOptions throttlingOptions = new ThrottlingRetryOptions()
.setMaxRetryAttemptsOnThrottledRequests(1000000)
.setMaxRetryWaitTime(Duration.ofDays(1));
this.bulkClient = getClientBuilder().throttlingRetryOptions(throttlingOptions).buildAsyncClient();
bulkAsyncContainer = getSharedMultiPartitionCosmosContainer(this.bulkClient);
}, 3, "CosmosBulkAsyncTest setup");
}

@AfterClass(groups = {"fast"}, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true)
public void afterClass() {
safeClose(this.bulkClient);
}

@Test(groups = {"fast"}, timeOut = TIMEOUT * 2)
@Test(groups = {"fast"}, timeOut = TIMEOUT * 2, retryAnalyzer = FlakyTestRetryAnalyzer.class)
public void createItem_withBulkAndThroughputControlAsDefaultGroup() throws InterruptedException {
runBulkTest(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.
package com.azure.cosmos;

import com.azure.cosmos.FlakyTestRetryAnalyzer;
import com.azure.cosmos.implementation.DatabaseAccount;
import com.azure.cosmos.implementation.DatabaseAccountLocation;
import com.azure.cosmos.implementation.GlobalEndpointManager;
Expand Down Expand Up @@ -170,7 +171,7 @@ public void conflictCustomLWW() throws InterruptedException {
}
}

@Test(groups = {"flaky-multi-master"}, timeOut = CONFLICT_TIMEOUT)
@Test(groups = {"flaky-multi-master"}, timeOut = CONFLICT_TIMEOUT, retryAnalyzer = FlakyTestRetryAnalyzer.class)
public void conflictCustomSproc() throws InterruptedException {
if (this.regionalClients.size() > 1) {
CosmosAsyncDatabase database = getSharedCosmosDatabase(globalClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ public Object[][] useAsyncParameterProvider() {
};
}

@Test(groups = {"fast"}, dataProvider = "useAsyncParameterProvider")
public void openConnectionsAndInitCachesForDirectMode(boolean useAsync) {
@Test(groups = {"fast"}, dataProvider = "useAsyncParameterProvider", retryAnalyzer = FlakyTestRetryAnalyzer.class)
public void openConnectionsAndInitCachesForDirectMode(boolean useAsync) throws InterruptedException {
CosmosAsyncContainer asyncContainer = useAsync ? directCosmosAsyncContainer : directCosmosContainer.asyncContainer;
CosmosAsyncClient asyncClient = useAsync ? directCosmosAsyncClient : directCosmosClient.asyncClient();

Expand Down Expand Up @@ -180,8 +180,20 @@ public void openConnectionsAndInitCachesForDirectMode(boolean useAsync) {

assertThat(provider.count()).isEqualTo(endpoints.size());

// Wait for channels to be established - connection opening is asynchronous
int minChannels = Configs.getMinConnectionPoolSizePerEndpoint();
int maxWaitIterations = 20;
for (int i = 0; i < maxWaitIterations; i++) {
boolean allReady = provider.list()
.allMatch(ep -> ep.channelsMetrics() >= minChannels);
if (allReady) {
break;
}
Thread.sleep(500);
}

// Validate for each RntbdServiceEndpoint, is at least Configs.getMinConnectionPoolSizePerEndpoint()) channel is being opened
provider.list().forEach(rntbdEndpoint -> assertThat(rntbdEndpoint.channelsMetrics()).isGreaterThanOrEqualTo(Configs.getMinConnectionPoolSizePerEndpoint()));
provider.list().forEach(rntbdEndpoint -> assertThat(rntbdEndpoint.channelsMetrics()).isGreaterThanOrEqualTo(minChannels));

// Test for real document requests, it will not open new channels
for (int i = 0; i < 5; i++) {
Expand All @@ -191,7 +203,7 @@ public void openConnectionsAndInitCachesForDirectMode(boolean useAsync) {
directCosmosContainer.createItem(TestObject.create());
}
}
provider.list().forEach(rntbdEndpoint -> assertThat(rntbdEndpoint.channelsMetrics()).isGreaterThanOrEqualTo(Configs.getMinConnectionPoolSizePerEndpoint()));
provider.list().forEach(rntbdEndpoint -> assertThat(rntbdEndpoint.channelsMetrics()).isGreaterThanOrEqualTo(minChannels));
}

@Test(groups = {"fast"}, dataProvider = "useAsyncParameterProvider")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,14 @@ private CosmosContainer getContainer(CosmosClientBuilder builder) {
this.safeCloseCosmosClient();

assertThat(builder).isNotNull();
this.client = builder.buildClient();
CosmosAsyncContainer asyncContainer = getSharedMultiPartitionCosmosContainer(this.client.asyncClient());
return this.client.getDatabase(asyncContainer.getDatabase().getId()).getContainer(asyncContainer.getId());
final CosmosContainer[] result = new CosmosContainer[1];
executeWithRetry(() -> {
this.safeCloseCosmosClient();
this.client = builder.buildClient();
CosmosAsyncContainer asyncContainer = getSharedMultiPartitionCosmosContainer(this.client.asyncClient());
result[0] = this.client.getDatabase(asyncContainer.getDatabase().getId()).getContainer(asyncContainer.getId());
}, 3, "CosmosDiagnosticsE2ETest getContainer");
return result[0];
}

private CosmosDiagnostics executeDocumentOperation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,23 @@ public void directDiagnosticsOnException() throws Exception {
CosmosItemResponse<InternalObjectNode> createResponse = null;
try {
createResponse = containerDirect.createItem(internalObjectNode);

// Verify item creation is fully propagated before testing with wrong partition key
// Use retry-based polling instead of fixed sleep for CI resilience
String itemId = BridgeInternal.getProperties(createResponse).getId();
int maxRetries = 5;
int retryCount = 0;
boolean itemReadable = false;
while (retryCount < maxRetries && !itemReadable) {
try {
containerDirect.readItem(itemId, new PartitionKey(itemId), InternalObjectNode.class);
itemReadable = true;
} catch (CosmosException e) {
retryCount++;
Thread.sleep(200);
}
}

CosmosItemRequestOptions cosmosItemRequestOptions = new CosmosItemRequestOptions();
ModelBridgeInternal.setPartitionKey(cosmosItemRequestOptions, new PartitionKey("wrongPartitionKey"));
CosmosItemResponse<InternalObjectNode> readResponse =
Expand Down Expand Up @@ -1108,7 +1125,7 @@ public void directDiagnosticsOnException() throws Exception {
}
}

@Test(groups = {"fast"}, dataProvider = "gatewayAndDirect", timeOut = TIMEOUT)
@Test(groups = {"fast"}, dataProvider = "gatewayAndDirect", timeOut = TIMEOUT, retryAnalyzer = FlakyTestRetryAnalyzer.class)
public void diagnosticsKeywordIdentifiers(CosmosContainer container) {
InternalObjectNode internalObjectNode = getInternalObjectNode();
HashSet<String> keywordIdentifiers = new HashSet<>();
Expand Down
Loading
Loading