Skip to content

Commit 582356c

Browse files
authored
Work around create failure in unified tests with retry (#1094)
On 4.0 sharded clusters, the create collection command often fails with error code 11601 (Interrupted). Work around it by retrying the command. JAVA-4883
1 parent dfd6e7c commit 582356c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

driver-sync/src/test/functional/com/mongodb/client/AbstractUnifiedTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import static com.mongodb.ClusterFixture.isDataLakeTest;
7272
import static com.mongodb.ClusterFixture.isSharded;
7373
import static com.mongodb.ClusterFixture.serverVersionAtLeast;
74+
import static com.mongodb.ClusterFixture.serverVersionLessThan;
7475
import static com.mongodb.ClusterFixture.setDirectConnection;
7576
import static com.mongodb.client.CommandMonitoringTestHelper.assertEventsEquality;
7677
import static com.mongodb.client.CommandMonitoringTestHelper.getExpectedEvents;
@@ -168,7 +169,16 @@ public void setUp() {
168169
collectionHelper.killAllSessions();
169170

170171
if (!isDataLakeTest()) {
171-
collectionHelper.create(collectionName, new CreateCollectionOptions(), WriteConcern.MAJORITY);
172+
try {
173+
collectionHelper.create(collectionName, new CreateCollectionOptions(), WriteConcern.MAJORITY);
174+
} catch (MongoCommandException e) {
175+
// Older sharded clusters sometimes reply with this error. Work around it by retrying once.
176+
if (e.getErrorCode() == 11601 && isSharded() && serverVersionLessThan(4, 2)) {
177+
collectionHelper.create(collectionName, new CreateCollectionOptions(), WriteConcern.MAJORITY);
178+
} else {
179+
throw e;
180+
}
181+
}
172182
}
173183

174184
if (!data.isEmpty()) {

0 commit comments

Comments
 (0)