Skip to content

Commit 0d3040f

Browse files
Addressing left-over test code review comments from PR#49639 (#49728)
* Add more verbose asserts * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Fix NITs in tests * Update PerPartitionCircuitBreakerE2ETests.java * Update ReadFeedStoredProceduresTest.java * Update CosmosItemTest.java * Update StoredProcedureUpsertReplaceTest.java * Update FaultInjectionServerErrorRuleOnDirectTests.java * Update FaultInjectionServerErrorRuleOnDirectTests.java * Update StoredProcedureQueryTest.java * Fix SP tests * More SP test fixes * Update CosmosContainerChangeFeedTest.java * Fix test flakiness * Update CosmosSyncStoredProcTest.java * Fix test flakiness * Update TestSuiteBase.java * Changing test regions * Update TestSuiteBase.java * Update CosmosDiagnosticsTest.java * Update KafkaCosmosConnectContainer.java * Fix test issues * Update TestSuiteBase.java * Update ClientMetricsTest.java * Update ClientMetricsTest.java * Update EndToEndTimeOutValidationTests.java * Update CosmosItemTest.java * Fix test flakiness * Address flakiness * Systemically fixing container creation race * Update TestSuiteBase.java * Update TransactionalBatchAsyncContainerTest.java * Update EndToEndTimeOutValidationTests.java * Update EndToEndTimeOutValidationTests.java * Update EndToEndTimeOutValidationTests.java * Update CosmosItemTest.java * Update CosmosBulkTest.java * Update AzureKeyCredentialTest.java * Update CosmosContainerOpenConnectionsAndInitCachesTest.java * Update OperationPoliciesTest.java * Update ProactiveConnectionManagementTest.java * Fixed flaky tests * Update CosmosItemContentResponseOnWriteTest.java * Make getFeedRanges from tests more robust * Update GatewayAddressCacheTest.java * Update CustomerWorkflowPartitionLevelCircuitBreakerTest.java * Fix Test flakiness * Update CosmosItemTest.java * Increasing setup timeouts * More robustness imprvements * More robustness fixes * Update LocationCacheTest.java * Update FaultInjectionWithAvailabilityStrategyTestsBase.java * Update TestSuiteBase.java * Fix FI unit tests * Fixing test flakiness * Update TestSuiteBase.java * fix bulk test failures * Update FaultInjectionWithAvailabilityStrategyTestsBase.java * Update TestSuiteBase.java * Update OperationPoliciesTest.java * Fixes ReadManyByPK bug in Spark connector resulting in duplicates and possibly missing first record * Updating changelogs * Update CosmosReadManyByPartitionKeyReader.scala * Reacting to code review feedback * Fixing remaining test failures * Fixing remaining test flakiness * Update ClientMetricsTest.java * Update FaultInjectionServerErrorRuleOnDirectTests.java * Update ChangeFeedTest.java --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent e900b80 commit 0d3040f

3 files changed

Lines changed: 49 additions & 22 deletions

File tree

sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/ClientMetricsTest.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public ClientMetricsTest(CosmosClientBuilder clientBuilder) {
8181
super(clientBuilder);
8282
}
8383

84-
@Test(groups = { "fast" }, timeOut = SETUP_TIMEOUT)
84+
@Test(groups = { "fast" }, timeOut = SETUP_TIMEOUT, retryAnalyzer = FlakyTestRetryAnalyzer.class)
8585
public void maxValueExceedingDefinedLimitStillWorksWithoutException() throws Exception {
8686

8787
// Expected behavior is that higher values than the expected max value can still be recorded
@@ -129,7 +129,7 @@ public void maxValueExceedingDefinedLimitStillWorksWithoutException() throws Exc
129129
}
130130
}
131131

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

@@ -200,7 +200,7 @@ public void createItem() throws Exception {
200200
}
201201
}
202202

203-
@Test(groups = { "fast" }, timeOut = TIMEOUT)
203+
@Test(groups = { "fast" }, timeOut = SETUP_TIMEOUT, retryAnalyzer = FlakyTestRetryAnalyzer.class)
204204
public void createItemWithAllMetrics() throws Exception {
205205

206206
boolean[] suppressConsistencyLevelTagTestCases = { false, true };
@@ -273,7 +273,7 @@ public void createItemWithAllMetrics() throws Exception {
273273
// Increased timeout from TIMEOUT to SETUP_TIMEOUT to account for collection creation time
274274
// during TestState initialization, especially in CI environments where collection creation
275275
// can take longer than 40 seconds
276-
@Test(groups = { "fast" }, timeOut = SETUP_TIMEOUT)
276+
@Test(groups = { "fast" }, timeOut = SETUP_TIMEOUT, retryAnalyzer = FlakyTestRetryAnalyzer.class)
277277
public void readItem() throws Exception {
278278
try (TestState state = new TestState(getClientBuilder(), CosmosMetricCategory.DEFAULT)) {
279279
InternalObjectNode properties = getDocumentDefinition(UUID.randomUUID().toString());
@@ -306,7 +306,7 @@ public void readItem() throws Exception {
306306
}
307307
}
308308

309-
@Test(groups = { "fast" }, timeOut = TIMEOUT)
309+
@Test(groups = { "fast" }, timeOut = SETUP_TIMEOUT, retryAnalyzer = FlakyTestRetryAnalyzer.class)
310310
public void readNonExistingItem() throws Exception {
311311
try (TestState state = new TestState(getClientBuilder(), CosmosMetricCategory.DEFAULT)) {
312312

@@ -454,7 +454,7 @@ private void runReadItemTestWithThresholds(
454454
}
455455
}
456456

457-
@Test(groups = { "fast" }, timeOut = TIMEOUT)
457+
@Test(groups = { "fast" }, timeOut = SETUP_TIMEOUT, retryAnalyzer = FlakyTestRetryAnalyzer.class)
458458
public void readItemWithThresholdsApplied() throws Exception {
459459
CosmosDiagnosticsThresholds maxThresholds = new CosmosDiagnosticsThresholds()
460460
.setPointOperationLatencyThreshold(Duration.ofDays(1));
@@ -502,7 +502,7 @@ public void replaceItem() throws Exception {
502502
}
503503
}
504504

505-
@Test(groups = { "fast" }, timeOut = TIMEOUT)
505+
@Test(groups = { "fast" }, timeOut = SETUP_TIMEOUT, retryAnalyzer = FlakyTestRetryAnalyzer.class)
506506
public void deleteItem() throws Exception {
507507
try (TestState state = new TestState(getClientBuilder(), CosmosMetricCategory.DEFAULT)) {
508508
InternalObjectNode properties = getDocumentDefinition(UUID.randomUUID().toString());
@@ -531,7 +531,7 @@ public void deleteItem() throws Exception {
531531
}
532532
}
533533

534-
@Test(groups = { "fast" }, timeOut = TIMEOUT)
534+
@Test(groups = { "fast" }, timeOut = SETUP_TIMEOUT, retryAnalyzer = FlakyTestRetryAnalyzer.class)
535535
public void readAllItems() throws Exception {
536536
try (TestState state = new TestState(getClientBuilder(), CosmosMetricCategory.DEFAULT)) {
537537
InternalObjectNode properties = getDocumentDefinition(UUID.randomUUID().toString());
@@ -579,7 +579,7 @@ public void readAllItems() throws Exception {
579579
}
580580
}
581581

582-
@Test(groups = { "fast" }, timeOut = TIMEOUT)
582+
@Test(groups = { "fast" }, timeOut = SETUP_TIMEOUT, retryAnalyzer = FlakyTestRetryAnalyzer.class)
583583
public void readAllItemsWithDetailMetrics() throws Exception {
584584
try (TestState state = new TestState(getClientBuilder(), CosmosMetricCategory.DEFAULT,
585585
CosmosMetricCategory.OPERATION_DETAILS,
@@ -741,7 +741,7 @@ public void readAllItemsWithDetailMetricsWithExplicitPageSize() throws Exception
741741
}
742742
}
743743

744-
@Test(groups = { "fast" }, timeOut = TIMEOUT)
744+
@Test(groups = { "fast" }, timeOut = SETUP_TIMEOUT, retryAnalyzer = FlakyTestRetryAnalyzer.class)
745745
public void queryItems() throws Exception {
746746
try (TestState state = new TestState(getClientBuilder(), CosmosMetricCategory.ALL)) {
747747
InternalObjectNode properties = getDocumentDefinition(UUID.randomUUID().toString());
@@ -858,7 +858,10 @@ public void itemPatchSuccess() throws Exception {
858858
}
859859
}
860860

861-
@Test(groups = { "fast" }, timeOut = TIMEOUT)
861+
// Increased timeout from TIMEOUT to SETUP_TIMEOUT to account for collection creation time
862+
// (TestState provisions a fresh container; on multi-region accounts that create + readiness
863+
// warm-up can consume most of the 40s budget before the bulk operation under test runs).
864+
@Test(groups = { "fast" }, timeOut = SETUP_TIMEOUT, retryAnalyzer = FlakyTestRetryAnalyzer.class)
862865
public void createItem_withBulk() throws Exception {
863866
try (TestState state = new TestState(getClientBuilder(), CosmosMetricCategory.DEFAULT)) {
864867
int totalRequest = 5;
@@ -937,7 +940,7 @@ public void createItem_withBulk() throws Exception {
937940
}
938941
}
939942

940-
@Test(groups = {"fast"}, timeOut = TIMEOUT)
943+
@Test(groups = {"fast"}, timeOut = SETUP_TIMEOUT, retryAnalyzer = FlakyTestRetryAnalyzer.class)
941944
public void batchMultipleItemExecution() throws Exception {
942945
try (TestState state = new TestState(getClientBuilder(), CosmosMetricCategory.DEFAULT)){
943946
TestDoc firstDoc = this.populateTestDoc(this.partitionKey1);
@@ -996,7 +999,7 @@ public void batchMultipleItemExecution() throws Exception {
996999
}
9971000
}
9981001

999-
@Test(groups = { "fast" }, timeOut = TIMEOUT * 2)
1002+
@Test(groups = { "fast" }, timeOut = TIMEOUT * 2, retryAnalyzer = FlakyTestRetryAnalyzer.class)
10001003
public void effectiveMetricCategoriesForDefault() throws Exception {
10011004
try (TestState state = new TestState(getClientBuilder(), CosmosMetricCategory.fromString("DeFAult"))) {
10021005
assertThat(state.getEffectiveMetricCategories().size()).isEqualTo(5);
@@ -1018,7 +1021,7 @@ public void effectiveMetricCategoriesForDefault() throws Exception {
10181021
}
10191022
}
10201023

1021-
@Test(groups = { "fast" }, timeOut = TIMEOUT)
1024+
@Test(groups = { "fast" }, timeOut = SETUP_TIMEOUT, retryAnalyzer = FlakyTestRetryAnalyzer.class)
10221025
public void effectiveMetricCategoriesForDefaultPlusDetails() throws Exception {
10231026
try (TestState state = new TestState(getClientBuilder(),
10241027
CosmosMetricCategory.DEFAULT,
@@ -1045,7 +1048,7 @@ public void effectiveMetricCategoriesForDefaultPlusDetails() throws Exception {
10451048
}
10461049
}
10471050

1048-
@Test(groups = { "fast" }, timeOut = TIMEOUT)
1051+
@Test(groups = { "fast" }, timeOut = SETUP_TIMEOUT, retryAnalyzer = FlakyTestRetryAnalyzer.class)
10491052
public void effectiveMetricCategoriesInvalidCategory() throws Exception {
10501053
String badCategoryName = "InvalidCategory";
10511054
try (TestState state = new TestState(getClientBuilder(),
@@ -1058,7 +1061,7 @@ public void effectiveMetricCategoriesInvalidCategory() throws Exception {
10581061
}
10591062
}
10601063

1061-
@Test(groups = { "fast" }, timeOut = TIMEOUT)
1064+
@Test(groups = { "fast" }, timeOut = SETUP_TIMEOUT, retryAnalyzer = FlakyTestRetryAnalyzer.class)
10621065
public void effectiveMetricCategoriesForAll() throws Exception {
10631066
try (TestState state = new TestState(getClientBuilder(), CosmosMetricCategory.ALL)) {
10641067

@@ -1114,7 +1117,7 @@ public void endpointMetricsAreDurable() throws Exception {
11141117
}
11151118
}
11161119

1117-
@Test(groups = { "fast" }, timeOut = TIMEOUT * 2)
1120+
@Test(groups = { "fast" }, timeOut = TIMEOUT * 2, retryAnalyzer = FlakyTestRetryAnalyzer.class)
11181121
public void effectiveMetricCategoriesForAllLatebound() throws Exception {
11191122
try (TestState state = new TestState(getClientBuilder(), CosmosMetricCategory.DEFAULT)) {
11201123
EnumSet<MetricCategory> effectiveMetricCategories =

sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/faultinjection/FaultInjectionServerErrorRuleOnDirectTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,14 @@ public void faultInjectionServerErrorRuleTests_ServerConnectionTimeout() throws
707707
// Due to the replica validation, there could be an extra open connection call flow, while the rule will also be applied on.
708708
assertThat(serverConnectionDelayRule.getHitCount()).isBetween(1l, 2l);
709709
assertThat(itemResponse.getDiagnostics()).isNotNull();
710+
this.validateFaultInjectionRuleApplied(
711+
itemResponse.getDiagnostics(),
712+
OperationType.Create,
713+
HttpConstants.StatusCodes.GONE,
714+
HttpConstants.SubStatusCodes.TRANSPORT_GENERATED_410,
715+
ruleId,
716+
true
717+
);
710718

711719
} finally {
712720
serverConnectionDelayRule.disable();

sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/rx/ChangeFeedTest.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -514,23 +514,33 @@ public Document updateDocument(AsyncDocumentClient client, Document originalDocu
514514
}
515515

516516
public List<Document> bulkInsert(AsyncDocumentClient client, List<Document> docs) {
517-
ArrayList<Mono<ResourceResponse<Document>>> result = new ArrayList<Mono<ResourceResponse<Document>>>();
517+
ArrayList<Mono<Document>> result = new ArrayList<Mono<Document>>();
518+
String collectionLink = "dbs/" + createdDatabase.getId() + "/colls/" + createdCollection.getId();
518519
for (int i = 0; i < docs.size(); i++) {
520+
Document doc = docs.get(i);
519521
result.add(client
520522
.createDocument(
521-
"dbs/" + createdDatabase.getId() + "/colls/" + createdCollection.getId(),
522-
docs.get(i),
523+
collectionLink,
524+
doc,
523525
null,
524526
false)
525527
.retryWhen(Retry.fixedDelay(SETUP_CREATE_RETRY_ATTEMPTS, SETUP_CREATE_RETRY_DELAY)
526528
.filter(ChangeFeedTest::isTransientSetupCreateFailure)
527-
.onRetryExhaustedThrow((retryBackoffSpec, retrySignal) -> retrySignal.failure())));
529+
.onRetryExhaustedThrow((retryBackoffSpec, retrySignal) -> retrySignal.failure()))
530+
.map(ResourceResponse::getResource)
531+
// A retried create is non-idempotent: when a create times out (e.g. 408) the initial attempt
532+
// may still have succeeded on the backend, so a subsequent retry fails with 409 Conflict.
533+
// Treat that as success by returning the document we tried to create (ids are unique per
534+
// document, so a 409 here can only mean the prior attempt already landed).
535+
.onErrorResume(
536+
ChangeFeedTest::isConflictSetupCreateFailure,
537+
error -> Mono.just(doc)));
528538
}
529539

530540
return Flux.merge(
531541
Flux.fromIterable(result),
532542
100)
533-
.map(ResourceResponse::getResource).collectList().block();
543+
.collectList().block();
534544
}
535545

536546
@AfterMethod(groups = { "query", "emulator" }, timeOut = SETUP_TIMEOUT)
@@ -615,6 +625,12 @@ private static boolean isTransientSetupCreateFailure(Throwable error) {
615625
return statusCode == 408 || statusCode == 429 || statusCode == 500 || statusCode == 503;
616626
}
617627

628+
private static boolean isConflictSetupCreateFailure(Throwable error) {
629+
Throwable unwrapped = reactor.core.Exceptions.unwrap(error);
630+
return unwrapped instanceof com.azure.cosmos.CosmosException
631+
&& ((com.azure.cosmos.CosmosException) unwrapped).getStatusCode() == 409;
632+
}
633+
618634
private static void waitAtleastASecond(Instant befTime) throws InterruptedException {
619635
while (befTime.plusSeconds(1).isAfter(Instant.now())) {
620636
Thread.sleep(100);

0 commit comments

Comments
 (0)