Skip to content

Commit 7a2733d

Browse files
committed
Parallelize tests (except on CI)
This change enables JUnit 5's parallel mode. On my machine, this change causes `./mvnw` to run in a third of the time (from 90 seconds to 30 seconds). Integration test time specifically has been reduced 80% (from 75 seconds to 15 seconds). In order to prevent the introduction of reliability issues with CI builds, parallel execution is disabled in our `maven.yml`.
1 parent 943cd68 commit 7a2733d

File tree

7 files changed

+96
-2
lines changed

7 files changed

+96
-2
lines changed

.github/workflows/maven.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ jobs:
4949
distribution: 'temurin'
5050
java-version: ${{ matrix.java }}
5151
- name: Build with Maven
52-
run: ./mvnw -V --file pom.xml --no-transfer-progress -DtrimStackTrace=false -P-use-toolchains,docker
52+
run: ./mvnw -V --file pom.xml --no-transfer-progress -DtrimStackTrace=false -Djunit.jupiter.execution.parallel.enabled=false -P-use-toolchains,docker

httpcore5-testing/pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@
9090
<artifactId>junit-jupiter</artifactId>
9191
<scope>test</scope>
9292
</dependency>
93+
<dependency>
94+
<groupId>org.junit.platform</groupId>
95+
<artifactId>junit-platform-launcher</artifactId>
96+
<scope>test</scope>
97+
</dependency>
9398
<dependency>
9499
<groupId>org.hamcrest</groupId>
95100
<artifactId>hamcrest</artifactId>
@@ -205,4 +210,4 @@
205210
</plugins>
206211
</reporting>
207212

208-
</project>
213+
</project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* ====================================================================
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing,
14+
* software distributed under the License is distributed on an
15+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
* KIND, either express or implied. See the License for the
17+
* specific language governing permissions and limitations
18+
* under the License.
19+
* ====================================================================
20+
*
21+
* This software consists of voluntary contributions made by many
22+
* individuals on behalf of the Apache Software Foundation. For more
23+
* information on the Apache Software Foundation, please see
24+
* <http://www.apache.org/>.
25+
*
26+
*/
27+
package org.apache.hc.core5.testing;
28+
29+
import org.junit.platform.launcher.LauncherSession;
30+
import org.junit.platform.launcher.LauncherSessionListener;
31+
import org.slf4j.LoggerFactory;
32+
33+
/**
34+
* Initialize Slf4j centrally before any tests run. This prevents Slf4j from
35+
* spamming warnings during parallelized test runs.
36+
*/
37+
public class LoggingInitializationListener implements LauncherSessionListener {
38+
@Override
39+
public void launcherSessionOpened(final LauncherSession session) {
40+
LoggerFactory.getILoggerFactory();
41+
}
42+
}

httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/AlpnTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@
3737
import org.junit.jupiter.api.condition.EnabledForJreRange;
3838
import org.junit.jupiter.api.condition.JRE;
3939
import org.junit.jupiter.api.condition.OS;
40+
import org.junit.jupiter.api.parallel.Isolated;
4041

4142
class AlpnTests {
4243

4344
@Nested
45+
@Isolated
4446
@DisplayName("ALPN Oracle")
4547
class OracleJSSEAlpnTest extends AlpnTest {
4648

@@ -51,6 +53,7 @@ public OracleJSSEAlpnTest() throws Exception {
5153
}
5254

5355
@Nested
56+
@Isolated
5457
@DisplayName("ALPN Conscrypt (Java 9 or newer)")
5558
@DisabledOnOs(OS.MAC)
5659
@EnabledForJreRange(min = JRE.JAVA_9)
@@ -63,6 +66,7 @@ public ConscryptJSSEAlpnTest() throws Exception {
6366
}
6467

6568
@Nested
69+
@Isolated
6670
@DisplayName("ALPN Conscrypt (Conscrypt specific TLS strategies)")
6771
@DisabledOnOs(OS.MAC)
6872
class ConscryptJSSEAndStrategiesAlpnTest extends AlpnTest {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
org.apache.hc.core5.testing.LoggingInitializationListener

httpcore5/src/test/java/org/apache/hc/core5/ssl/TestSSLContextBuilder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@
6666
import org.junit.jupiter.api.AfterEach;
6767
import org.junit.jupiter.api.Assertions;
6868
import org.junit.jupiter.api.Test;
69+
import org.junit.jupiter.api.parallel.Isolated;
6970

7071
/**
7172
* Unit tests for {@link SSLContextBuilder}.
7273
*/
74+
@Isolated
7375
class TestSSLContextBuilder {
7476

7577
static final String PROVIDER_SUN_JSSE = "SunJSSE";
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
junit.jupiter.execution.parallel.enabled = true
20+
junit.jupiter.execution.parallel.mode.default = concurrent
21+
junit.jupiter.execution.parallel.mode.classes.default = concurrent
22+
junit.jupiter.execution.parallel.config.strategy = dynamic

0 commit comments

Comments
 (0)