Skip to content

Commit 532a3fd

Browse files
why? just why is this search server thingy so brittle?
1 parent 34ad67e commit 532a3fd

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/VectorIndexIntegrationTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@ void init() {
7777
@AfterEach
7878
void cleanup() {
7979

80+
template.tryToDropSearchIndexes(Movie.class, Duration.ofSeconds(30));
8081
template.flush(Movie.class);
81-
template.searchIndexOps(Movie.class).dropAllIndexes();
82-
template.awaitNoSearchIndexAvailable(Movie.class, Duration.ofSeconds(30));
8382
}
8483

8584
@ParameterizedTest // GH-4706

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/test/util/MongoTestTemplate.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,43 @@ public void awaitNoSearchIndexAvailable(String collectionName, Duration timeout)
233233
public void awaitNoSearchIndexAvailable(Class<?> type, Duration timeout) {
234234
awaitNoSearchIndexAvailable(getCollectionName(type), timeout);
235235
}
236+
237+
public void tryToDropSearchIndexes(Class<?> type, Duration duration) {
238+
tryToDropSearchIndexes(getCollectionName(type), duration);
239+
}
240+
241+
public void tryToDropSearchIndexes(String collectionName, Duration timeout) {
242+
243+
Awaitility.await().atMost(timeout).pollInterval(Duration.ofMillis(200)).until(() -> {
244+
245+
try {
246+
this.execute(collectionName, coll -> {
247+
248+
ArrayList<Document> indexDocuments = coll.aggregate(List.of(Document.parse("{'$listSearchIndexes': { } }")))
249+
.into(new ArrayList<>());
250+
251+
indexDocuments.forEach(indexDocument -> {
252+
if (indexDocument.containsKey("name")) {
253+
boolean toBeDeleted = true;
254+
if (indexDocument.containsKey("status")) {
255+
String status = indexDocument.getString("status");
256+
if (status.equals("DELETING") || status.equals("DOES_NOT_EXIST")) {
257+
toBeDeleted = false;
258+
}
259+
}
260+
if (toBeDeleted) {
261+
coll.dropSearchIndex(indexDocument.getString("name"));
262+
}
263+
}
264+
});
265+
return "done with that";
266+
});
267+
} catch (Exception e) {
268+
return false;
269+
}
270+
return true;
271+
});
272+
273+
awaitNoSearchIndexAvailable(collectionName, timeout);
274+
}
236275
}

0 commit comments

Comments
 (0)