Skip to content

Commit f8f3135

Browse files
committed
test(batch): add 100ms wait to reduce flakiness in BatchContextTest
1 parent 2aa7b20 commit f8f3135

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

src/it/java/io/weaviate/integration/OIDCSupportITest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void test_resourceOwnerPassword() throws Exception {
8181
Assume.assumeTrue("WCS_DUMMY_CI_PW is not set", WCS_DUMMY_CI_PW != null && !WCS_DUMMY_CI_PW.isBlank());
8282
Assume.assumeTrue("no internet connection", hasInternetConnection());
8383

84-
// Check norwal resource owner password flow works.
84+
// Check normal resource owner password flow works.
8585
var password = Authentication.resourceOwnerPassword(WCS_DUMMY_CI_USERNAME, WCS_DUMMY_CI_PW, List.of());
8686
var auth = SpyTokenProvider.spyOn(password);
8787
pingWeaviate(wcsContainer, auth);

src/test/java/io/weaviate/client6/v1/api/collections/batch/BatchContextTest.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.IOException;
44
import java.util.ArrayList;
5+
import java.util.Collection;
56
import java.util.Collections;
67
import java.util.List;
78
import java.util.Map;
@@ -171,25 +172,21 @@ public void test_drainOnClose() throws Exception {
171172
// Contrary the test above, we expect the objects to be sent
172173
// only after context.close(), as the half-empty batch will
173174
// be drained. Similarly, we want to ack everything as it arrives.
174-
Future<?> backgroundAcks = BACKGROUND.submit(() -> {
175+
BACKGROUND.submit(() -> {
175176
try {
176177
List<String> received = recvDataAndAck();
177178
Assertions.assertThat(tasks)
178179
.extracting(TaskHandle::id).containsExactlyInAnyOrderElementsOf(received);
179180
Assertions.assertThat(tasks)
180181
.extracting(TaskHandle::isAcked).allMatch(CompletableFuture::isDone);
181-
182-
// Wait until the Results event's been processed to guarantee
183-
// that the tasks' futures are completed before asserting.
184-
Future<?> results = out.emitEvent(new Event.Results(received, Collections.emptyMap()));
185-
results.get();
182+
out.emitEvent(new Event.Results(received, Collections.emptyMap()));
186183
} catch (Exception e) {
187184
throw new RuntimeException(e);
188185
}
189186
});
190187

191188
context.close();
192-
backgroundAcks.get(); // Wait for the "mock server" to process the data message.
189+
awaitResults(tasks);
193190

194191
Assertions.assertThat(tasks).extracting(TaskHandle::result)
195192
.allMatch(CompletableFuture::isDone)
@@ -268,6 +265,13 @@ public void test_backoffBacklog() throws Exception {
268265

269266
context.close();
270267

268+
// Wait until the Results event's been processed to guarantee
269+
// that the tasks' futures are completed before asserting.
270+
CompletableFuture.allOf(
271+
tasks.stream().map(TaskHandle::result)
272+
.toArray(CompletableFuture[]::new))
273+
.get(100, TimeUnit.MILLISECONDS);
274+
271275
Assertions.assertThat(tasks).extracting(TaskHandle::result)
272276
.allMatch(CompletableFuture::isDone)
273277
.extracting(CompletableFuture::get).extracting(TaskHandle.Result::error)
@@ -464,6 +468,15 @@ private List<String> recvDataAndAck() throws InterruptedException {
464468
return ids;
465469
}
466470

471+
private void awaitResults(Collection<TaskHandle> tasks) throws Exception {
472+
// Wait until the Results event's been processed to guarantee
473+
// that the tasks' futures are completed before asserting.
474+
CompletableFuture.allOf(
475+
tasks.stream().map(TaskHandle::result)
476+
.toArray(CompletableFuture[]::new))
477+
.get(100, TimeUnit.MILLISECONDS);
478+
}
479+
467480
static String getBeacon(WeaviateProtoBatch.BatchReference reference) {
468481
return "weaviate://localhost/" + reference.getToCollection() + "/" + reference.getToUuid();
469482
}

0 commit comments

Comments
 (0)