Skip to content

Commit 64b255b

Browse files
refine vector index wait strategy
1 parent cc7aca5 commit 64b255b

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/aot/MongoRepositoryContributorTests.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import org.bson.BsonString;
3434
import org.bson.Document;
35+
import org.junit.jupiter.api.AfterEach;
3536
import org.junit.jupiter.api.BeforeAll;
3637
import org.junit.jupiter.api.BeforeEach;
3738
import org.junit.jupiter.api.Test;
@@ -151,18 +152,26 @@ private static void initializeVectorIndex() {
151152
.append("queryVector", List.of(1.0, 1.12345, 2.23456, 3.34567, 4.45678)));
152153

153154
// wait for search index to serve data
154-
Awaitility.await().atMost(Duration.ofSeconds(120)).pollInterval(Duration.ofMillis(200)).until(() -> {
155-
try (MongoCursor<Document> cursor = userCollection.aggregate(List.of($vectorSearch)).iterator()) {
156-
return cursor.hasNext();
157-
}
158-
});
155+
Awaitility.await().atLeast(Duration.ofMillis(50)).atMost(Duration.ofSeconds(120)).ignoreExceptions()
156+
.pollInterval(Duration.ofMillis(250)).until(() -> {
157+
try (MongoCursor<Document> cursor = userCollection.aggregate(List.of($vectorSearch)).iterator()) {
158+
if (cursor.hasNext()) {
159+
Document next = cursor.next();
160+
return true;
161+
}
162+
return false;
163+
}
164+
});
159165
}
160166

161167
@BeforeEach
162168
void beforeEach() throws InterruptedException {
169+
initUsers();
170+
}
163171

172+
@AfterEach
173+
void afterEach() {
164174
MongoTestUtils.flushCollection(DB_NAME, "user", client);
165-
initUsers();
166175
}
167176

168177
@Test

0 commit comments

Comments
 (0)