Skip to content

Commit 7193326

Browse files
committed
ci: run tests in parallel
Reduces test execution time from 1:20min to ~45s
1 parent 124599b commit 7193326

7 files changed

Lines changed: 65 additions & 62 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111
target/
1212
# maven-lombok-plugin
1313
.factorypath
14+
# Surefire statistics for optimized execution time
15+
.surefire-*

pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,12 @@
232232
<version>3.5.4</version>
233233
<configuration>
234234
<trimStackTrace>false</trimStackTrace>
235+
<parallel>classes</parallel>
236+
<forkCount>4</forkCount>
237+
<reuseForks>true</reuseForks>
238+
<threadCount>1</threadCount>
239+
<perCoreThreadCount>true</perCoreThreadCount>
240+
<runOrder>balanced</runOrder>
235241
<argLine>
236242
<!--
237243
Gson (used for JSON serialization) utilizes reflection and needs to be able to access private fields of
@@ -241,12 +247,6 @@
241247
-->
242248
--add-opens=java.base/java.lang=ALL-UNNAMED
243249
</argLine>
244-
<properties>
245-
<property>
246-
<name>listener</name>
247-
<value>io.weaviate.containers.TestListener</value>
248-
</property>
249-
</properties>
250250
</configuration>
251251
</plugin>
252252
<plugin>

src/it/java/io/weaviate/containers/Container.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,6 @@ public class Container {
1818
public static final Img2VecNeural IMG2VEC_NEURAL = Img2VecNeural.createDefault();
1919
public static final MinIo MINIO = MinIo.createDefault();
2020

21-
/**
22-
* Stop all shared Testcontainers created in {@link #startAll}.
23-
* <p>
24-
* Testcontainer's Ryuk will reap any dangling containers after the tests
25-
* finish. However, since {@link Weaviate} instances also hold a
26-
* {@link WeaviateClient}, we want to stop them proactively to
27-
* close client connections.
28-
*/
29-
static void stopAll() {
30-
WEAVIATE.stop();
31-
}
32-
3321
public static ContainerGroup compose(Weaviate weaviate, GenericContainer<?>... containers) {
3422
return new ContainerGroup(weaviate, containers);
3523
}

src/it/java/io/weaviate/containers/TestListener.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/it/java/io/weaviate/containers/Weaviate.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ public WeaviateClient getClient() {
4949
return clientInstance;
5050
}
5151

52+
/**
53+
* Get client that is not shared with other tests / callers.
54+
* The returned client is not wrapped in an instance of {@link SharedClient},
55+
* so it can be auto-closed by the try-with-resources statement when it exists.
56+
*/
57+
public WeaviateClient getBareClient() {
58+
if (!isRunning()) {
59+
start();
60+
}
61+
try {
62+
return new WeaviateClient(Config.of(defaultConfigFn()));
63+
} catch (Exception e) {
64+
throw new RuntimeException("create WeaviateClient for Weaviate container", e);
65+
}
66+
}
67+
5268
/**
5369
* Create a new instance of WeaviateClient connected to this container.
5470
* Prefer using {@link #getClient} unless your test needs the initialization
@@ -138,6 +154,7 @@ public Builder withFilesystemBackup(String fsPath) {
138154
environment.put("BACKUP_FILESYSTEM_PATH", fsPath);
139155
return this;
140156
}
157+
141158
public Builder withAdminUsers(String... admins) {
142159
adminUsers.addAll(Arrays.asList(admins));
143160
return this;

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

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.weaviate.client6.v1.api.collections.vectorindex.Hnsw;
2222
import io.weaviate.client6.v1.api.collections.vectorizers.SelfProvidedVectorizer;
2323
import io.weaviate.containers.Container;
24+
import io.weaviate.containers.Weaviate;
2425

2526
public class CollectionsITest extends ConcurrentTest {
2627
private static WeaviateClient client = Container.WEAVIATE.getClient();
@@ -95,31 +96,34 @@ public void testCrossReferences() throws IOException {
9596
}
9697

9798
@Test
98-
public void testListDeleteAll() throws IOException {
99-
var nsA = ns("A");
100-
var nsB = ns("B");
101-
var nsC = ns("C");
102-
103-
client.collections.create(nsA);
104-
client.collections.create(nsB);
105-
client.collections.create(nsC);
106-
107-
Assertions.assertThat(client.collections.exists(nsA)).isTrue();
108-
Assertions.assertThat(client.collections.exists(nsB)).isTrue();
109-
Assertions.assertThat(client.collections.exists(nsC)).isTrue();
110-
Assertions.assertThat(client.collections.exists(ns("X"))).isFalse();
111-
112-
var all = client.collections.list();
113-
Assertions.assertThat(all)
114-
.hasSizeGreaterThanOrEqualTo(3)
115-
.extracting(CollectionConfig::collectionName)
116-
.contains(nsA, nsB, nsC);
117-
118-
client.collections.deleteAll();
119-
120-
all = client.collections.list();
121-
Assertions.assertThat(all.isEmpty());
122-
99+
public void testListDeleteAll() throws Exception {
100+
// Use a separate container for this test so as not to interfere
101+
// with other tests.
102+
try (final var _client = Weaviate.createDefault().getBareClient()) {
103+
var nsA = ns("A");
104+
var nsB = ns("B");
105+
var nsC = ns("C");
106+
107+
_client.collections.create(nsA);
108+
_client.collections.create(nsB);
109+
_client.collections.create(nsC);
110+
111+
Assertions.assertThat(_client.collections.exists(nsA)).isTrue();
112+
Assertions.assertThat(_client.collections.exists(nsB)).isTrue();
113+
Assertions.assertThat(_client.collections.exists(nsC)).isTrue();
114+
Assertions.assertThat(_client.collections.exists(ns("X"))).isFalse();
115+
116+
var all = _client.collections.list();
117+
Assertions.assertThat(all)
118+
.hasSizeGreaterThanOrEqualTo(3)
119+
.extracting(CollectionConfig::collectionName)
120+
.contains(nsA, nsB, nsC);
121+
122+
_client.collections.deleteAll();
123+
124+
all = _client.collections.list();
125+
Assertions.assertThat(all.isEmpty());
126+
}
123127
}
124128

125129
@Test

src/main/java/io/weaviate/client6/v1/api/collections/data/ReferenceAddManyResponse.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@ public ReferenceAddManyResponse deserialize(JsonElement json, Type typeOfT, Json
2424
int i = 0;
2525
for (var el : json.getAsJsonArray()) {
2626
var result = el.getAsJsonObject().get("result").getAsJsonObject();
27-
if (result.get("status").getAsString().equals("FAILED")) {
28-
var errorMsg = result
29-
.get("errors").getAsJsonObject()
30-
.get("error").getAsJsonArray()
31-
.get(0).getAsString();
27+
if (result.get("status").getAsString().equals("FAILED")
28+
&& result.has("errors")) {
29+
String errorMsg;
30+
try {
31+
errorMsg = result
32+
.get("errors").getAsJsonObject()
33+
.get("error").getAsJsonArray()
34+
.get(0).getAsString();
35+
} catch (Exception e) {
36+
errorMsg = result.get("errors").toString();
37+
}
3238

3339
var batchErr = new BatchError(errorMsg, null, i);
3440
errors.add(batchErr);

0 commit comments

Comments
 (0)