Skip to content

Commit 5c0cf87

Browse files
uglideCopilotatakavci
authored
Separate unit and integration tests (#4280)
* Separate unit and integration tests - Use test target only for running integration tests - Use failsafe for running integration tests - Clean up pom.xml * Merge test coverage and update workflows * Update pom.xml Co-authored-by: Copilot <[email protected]> * Fix jacoco:merge * Include failsafe reports to fix tests results in PRs * Another attempt * Just change the location of failsafe summary file * Fix tag for ActiveActiveLocalFailoverTest * Clean before running doctests * Fix redis container name * Cache dependencies in doctests.yml * Use manual build for codeql * Update .github/workflows/test-on-docker.yml Co-authored-by: atakavci <[email protected]> --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: atakavci <[email protected]>
1 parent b04e64b commit 5c0cf87

File tree

109 files changed

+367
-72
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+367
-72
lines changed
Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
1-
# For most projects, this workflow file will not need changing; you simply need
2-
# to commit it to your repository.
3-
#
4-
# You may wish to alter this file to override the set of languages analyzed,
5-
# or to provide custom queries or build logic.
6-
#
7-
# ******** NOTE ********
8-
# We have attempted to detect the languages in your repository. Please check
9-
# the `language` matrix defined below to confirm you have the correct set of
10-
# supported CodeQL languages.
11-
#
121
name: "CodeQL"
132

143
on:
4+
workflow_dispatch:
155
push:
166
branches: [ master ]
177
pull_request:
@@ -35,29 +25,21 @@ jobs:
3525

3626
# Initializes the CodeQL tools for scanning.
3727
- name: Initialize CodeQL
38-
uses: github/codeql-action/init@v2
28+
uses: github/codeql-action/init@v3
3929
with:
4030
languages: java
41-
# If you wish to specify custom queries, you can do so here or in a config file.
42-
# By default, queries listed here will override any specified in a config file.
43-
# Prefix the list here with "+" to use these queries and those in the config file.
44-
# queries: ./path/to/local/query, your-org/your-repo/queries@main
31+
dependency-caching: true
32+
build-mode: manual
4533

46-
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
47-
# If this step fails, then you should remove it and run the build manually (see below)
48-
- name: Autobuild
49-
uses: github/codeql-action/autobuild@v2
50-
51-
# ℹ️ Command-line programs to run using the OS shell.
52-
# 📚 https://git.io/JvXDl
53-
54-
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
55-
# and modify them (or add more) to build your code if your project
56-
# uses a compiled language
34+
- name: Set up JDK 8
35+
uses: actions/setup-java@v4
36+
with:
37+
distribution: temurin
38+
java-version: '8'
39+
cache: maven
5740

58-
#- run: |
59-
# make bootstrap
60-
# make release
41+
- name: Build
42+
run: mvn -B package
6143

6244
- name: Perform CodeQL Analysis
63-
uses: github/codeql-action/analyze@v2
45+
uses: github/codeql-action/analyze@v3

.github/workflows/doctests.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ jobs:
1212
doctests:
1313
runs-on: ubuntu-latest
1414
services:
15-
redis-stack:
16-
image: redis/redis-stack-server:latest
15+
redis:
16+
image: redis:latest
1717
options: >-
1818
--health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5
1919
ports:
@@ -33,6 +33,9 @@ jobs:
3333
with:
3434
java-version: '11'
3535
distribution: 'temurin'
36+
- name: Maven offline
37+
run: |
38+
mvn -q dependency:go-offline
3639
- name: Run doctests
3740
run: |
38-
mvn -Pdoctests test
41+
mvn -Pdoctests clean compile test

.github/workflows/integration.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,3 @@ jobs:
5656
env:
5757
JVM_OPTS: -Xmx3200m
5858
TERM: dumb
59-
- name: Upload coverage to Codecov
60-
uses: codecov/codecov-action@v4
61-
with:
62-
fail_ci_if_error: false
63-
token: ${{ secrets.CODECOV_TOKEN }}
64-
- name: Upload test results to Codecov
65-
if: ${{ github.event_name == 'schedule' || (github.event_name == 'push') || github.event_name == 'workflow_dispatch'}}
66-
uses: codecov/test-results-action@v1
67-
with:
68-
fail_ci_if_error: false
69-
files: ./target/surefire-reports/TEST*
70-
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/test-on-docker.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ jobs:
8080
export TEST_WORK_FOLDER=$REDIS_ENV_WORK_DIR
8181
echo $TEST_WORK_FOLDER
8282
if [ -z "$TESTS" ]; then
83-
mvn clean compile test
83+
mvn clean compile verify
8484
else
85-
mvn -Dtest=$TESTS clean compile test
85+
mvn -Dtest=$TESTS clean verify
8686
fi
8787
env:
8888
JVM_OPTS: "-XX:+HeapDumpOnOutOfMemoryError -XX:+ExitOnOutOfMemoryError -XX:HeapDumpPath=${{ runner.temp }}/heapdump-${{ matrix.redis_version }}.hprof"
@@ -105,6 +105,7 @@ jobs:
105105
with:
106106
files: |
107107
target/surefire-reports/**/*.xml
108+
target/failsafe-reports/**/*.xml
108109
# Collect logs on failure
109110
- name: Collect logs on failure
110111
if: failure() # This runs only if the previous steps failed
@@ -125,15 +126,22 @@ jobs:
125126
docker compose $COMPOSE_ENV_FILES -f src/test/resources/env/docker-compose.yml down
126127
continue-on-error: true
127128
# Upload code coverage
128-
- name: Upload coverage to Codecov
129+
- name: Upload merged coverage to Codecov
129130
uses: codecov/codecov-action@v5
130131
with:
132+
# Upload the merged JaCoCo XML report generated at verify phase
133+
files: ./target/site/jacoco/jacoco.xml
134+
flags: docker-${{ matrix.redis_version }}
135+
name: merged-coverage
131136
fail_ci_if_error: false
132137
token: ${{ secrets.CODECOV_TOKEN }}
133-
- name: Upload test results to Codecov
138+
- name: Upload test results to Codecov (unit + IT)
134139
if: ${{ github.event_name == 'schedule' || (github.event_name == 'push') || github.event_name == 'workflow_dispatch'}}
135140
uses: codecov/test-results-action@v1
136141
with:
137142
fail_ci_if_error: false
138-
files: ./target/surefire-reports/TEST*
143+
files: |
144+
./target/surefire-reports/*.xml
145+
./target/failsafe-reports/*.xml
146+
flags: test-results-docker-${{ matrix.redis_version }}
139147
token: ${{ secrets.CODECOV_TOKEN }}

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,10 @@ stop:
522522
test: | start mvn-test-local stop
523523

524524
mvn-test-local:
525-
@TEST_ENV_PROVIDER=local mvn -Dtest=${TEST} clean compile test
525+
@TEST_ENV_PROVIDER=local mvn -Dtest=${TEST} clean compile verify
526526

527527
mvn-test:
528-
mvn -Dtest=${TEST} clean compile test
528+
mvn -Dtest=${TEST} clean compile verify
529529

530530
package: | start mvn-package stop
531531

pom.xml

Lines changed: 129 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,17 +252,70 @@
252252
<artifactId>jacoco-maven-plugin</artifactId>
253253
<version>0.8.13</version>
254254
<executions>
255+
<!-- Collect coverage for unit tests -->
255256
<execution>
257+
<id>prepare-agent-ut</id>
256258
<goals>
257259
<goal>prepare-agent</goal>
258260
</goals>
261+
<configuration>
262+
<propertyName>argLine</propertyName>
263+
<destFile>${project.build.directory}/jacoco-ut.exec</destFile>
264+
</configuration>
265+
</execution>
266+
<!-- Collect coverage for integration tests tagged with @Tag("integration") -->
267+
<execution>
268+
<id>prepare-agent-it-tagged</id>
269+
<goals>
270+
<goal>prepare-agent</goal>
271+
</goals>
272+
<configuration>
273+
<propertyName>failsafeTaggedArgLine</propertyName>
274+
<destFile>${project.build.directory}/jacoco-it-tagged.exec</destFile>
275+
</configuration>
276+
</execution>
277+
<!-- Collect coverage for integration tests with filename suffix IntegrationTest(s) -->
278+
<execution>
279+
<id>prepare-agent-it-suffix</id>
280+
<goals>
281+
<goal>prepare-agent</goal>
282+
</goals>
283+
<configuration>
284+
<propertyName>failsafeSuffixArgLine</propertyName>
285+
<destFile>${project.build.directory}/jacoco-it-suffix.exec</destFile>
286+
</configuration>
287+
</execution>
288+
<!-- Merge all coverage data after all integration tests -->
289+
<execution>
290+
<id>merge-coverage</id>
291+
<phase>post-integration-test</phase>
292+
<goals>
293+
<goal>merge</goal>
294+
</goals>
295+
<configuration>
296+
<fileSets>
297+
<fileSet>
298+
<directory>${project.build.directory}</directory>
299+
<includes>
300+
<include>jacoco-ut.exec</include>
301+
<include>jacoco-it-tagged.exec</include>
302+
<include>jacoco-it-suffix.exec</include>
303+
</includes>
304+
</fileSet>
305+
</fileSets>
306+
<destFile>${project.build.directory}/jacoco-merged.exec</destFile>
307+
</configuration>
259308
</execution>
309+
<!-- Generate the final report on the merged data -->
260310
<execution>
261311
<id>report</id>
262-
<phase>test</phase>
312+
<phase>verify</phase>
263313
<goals>
264314
<goal>report</goal>
265315
</goals>
316+
<configuration>
317+
<dataFile>${project.build.directory}/jacoco-merged.exec</dataFile>
318+
</configuration>
266319
</execution>
267320
</executions>
268321
</plugin>
@@ -282,12 +335,80 @@
282335
<systemPropertyVariables>
283336
<redis-hosts>${redis-hosts}</redis-hosts>
284337
</systemPropertyVariables>
338+
<excludedGroups>integration,scenario</excludedGroups>
285339
<excludes>
286-
<exclude>**/examples/*Example.java</exclude>
340+
<exclude>**/examples/*.java</exclude>
341+
<exclude>**/scenario/*Test.java</exclude>
342+
<!-- Exclude integration tests from unit-test phase -->
343+
<exclude>**/*IntegrationTest.java</exclude>
344+
<exclude>**/*IntegrationTests.java</exclude>
287345
</excludes>
288346
<!--<trimStackTrace>false</trimStackTrace>-->
289347
</configuration>
290348
</plugin>
349+
<plugin>
350+
<artifactId>maven-failsafe-plugin</artifactId>
351+
<version>${maven.surefire.version}</version>
352+
<configuration>
353+
<argLine>@{failsafeSuffixArgLine} ${JVM_OPTS}</argLine>
354+
<systemPropertyVariables>
355+
<redis-hosts>${redis-hosts}</redis-hosts>
356+
</systemPropertyVariables>
357+
<!-- Default includes used when invoking failsafe goals directly (e.g., mvn failsafe:integration-test) -->
358+
<includes>
359+
<include>**/*IntegrationTest.java</include>
360+
<include>**/*IntegrationTests.java</include>
361+
</includes>
362+
<excludes>
363+
<exclude>**/examples/*.java</exclude>
364+
<exclude>**/scenario/*Test.java</exclude>
365+
<!-- Exclude unit tests -->
366+
<exclude>**/mocked/*.java</exclude>
367+
</excludes>
368+
</configuration>
369+
<executions>
370+
<!-- Run all tests tagged with @Tag("integration") regardless of file name -->
371+
<execution>
372+
<id>it-tagged</id>
373+
<goals>
374+
<goal>integration-test</goal>
375+
</goals>
376+
<configuration>
377+
<argLine>@{failsafeTaggedArgLine} ${JVM_OPTS}</argLine>
378+
<groups>integration</groups>
379+
<includes>
380+
<include>**/*Test.java</include>
381+
<include>**/*Tests.java</include>
382+
</includes>
383+
</configuration>
384+
</execution>
385+
<!-- Also run tests whose filenames end with IntegrationTest or IntegrationTests, even if not tagged -->
386+
<execution>
387+
<id>it-suffix</id>
388+
<goals>
389+
<goal>integration-test</goal>
390+
</goals>
391+
<configuration>
392+
<argLine>@{failsafeSuffixArgLine} ${JVM_OPTS}</argLine>
393+
394+
<includes>
395+
<include>**/*IntegrationTest.java</include>
396+
<include>**/*IntegrationTests.java</include>
397+
</includes>
398+
</configuration>
399+
</execution>
400+
<!-- Verify phase should run once after both IT executions -->
401+
<execution>
402+
<id>it-verify</id>
403+
<goals>
404+
<goal>verify</goal>
405+
</goals>
406+
<configuration>
407+
<summaryFile>${project.build.directory}/failsafe-summary.xml</summaryFile>
408+
</configuration>
409+
</execution>
410+
</executions>
411+
</plugin>
291412
<plugin>
292413
<artifactId>maven-source-plugin</artifactId>
293414
<version>3.3.1</version>
@@ -359,19 +480,19 @@
359480
<include>**/VAddParams.java</include>
360481
<include>**/VSimParams.java</include>
361482
<include>**/VSimScoreAttribs.java</include>
362-
<include>**/*FunctionCommandsTest*</include>
483+
<include>**/*FunctionCommandsTest*.java</include>
363484
<include>**/Endpoint.java</include>
364485
<include>src/main/java/redis/clients/jedis/mcf/*.java</include>
365486
<include>src/test/java/redis/clients/jedis/failover/*.java</include>
366487
<include>**/mcf/EchoStrategyIntegrationTest.java</include>
367488
<include>**/mcf/LagAwareStrategyUnitTest.java</include>
368489
<include>**/mcf/RedisRestAPI*.java</include>
369490
<include>**/mcf/ActiveActiveLocalFailoverTest*</include>
370-
<include>**/mcf/FailbackMechanism*</include>
371-
<include>**/mcf/PeriodicFailbackTest*</include>
372-
<include>**/mcf/AutomaticFailoverTest*</include>
373-
<include>**/mcf/MultiCluster*</include>
374-
<include>**/mcf/StatusTracker*</include>
491+
<include>**/mcf/FailbackMechanism*.java</include>
492+
<include>**/mcf/PeriodicFailbackTest*.java</include>
493+
<include>**/mcf/AutomaticFailoverTest*.java</include>
494+
<include>**/mcf/MultiCluster*.java</include>
495+
<include>**/mcf/StatusTracker*.java</include>
375496
<include>**/Health*.java</include>
376497
<include>src/main/java/redis/clients/jedis/MultiClusterClientConfig.java</include>
377498
<include>src/main/java/redis/clients/jedis/HostAndPort.java</include>

src/test/java/redis/clients/jedis/ACLJedisPoolTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
1818

1919
import org.junit.jupiter.api.Test;
20+
import org.junit.jupiter.api.Tag;
2021
import org.junit.jupiter.api.extension.RegisterExtension;
2122
import redis.clients.jedis.exceptions.InvalidURIException;
2223
import redis.clients.jedis.exceptions.JedisAccessControlException;
@@ -29,6 +30,7 @@
2930
* This test is only executed when the server/cluster is Redis 6. or more.
3031
*/
3132
@SinceRedisVersion("6.0.0")
33+
@Tag("integration")
3234
public class ACLJedisPoolTest {
3335
private static final EndpointConfig endpoint = HostAndPorts.getRedisEndpoint("standalone0-acl");
3436

src/test/java/redis/clients/jedis/ACLJedisSentinelPoolTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import org.junit.jupiter.api.BeforeEach;
1616
import org.junit.jupiter.api.Test;
17+
import org.junit.jupiter.api.Tag;
1718
import org.junit.jupiter.api.extension.RegisterExtension;
1819
import redis.clients.jedis.exceptions.JedisConnectionException;
1920
import redis.clients.jedis.exceptions.JedisException;
@@ -25,6 +26,7 @@
2526
* This tests are only executed when the server/cluster is Redis 6 or more.
2627
*/
2728
@SinceRedisVersion("6.0.0")
29+
@Tag("integration")
2830
public class ACLJedisSentinelPoolTest {
2931

3032
private static final String MASTER_NAME = "aclmaster";

src/test/java/redis/clients/jedis/ClusterPipeliningTest.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@
1717
import org.hamcrest.MatcherAssert;
1818
import org.hamcrest.Matchers;
1919

20-
import org.junit.jupiter.api.AfterAll;
21-
import org.junit.jupiter.api.AfterEach;
22-
import org.junit.jupiter.api.BeforeAll;
23-
import org.junit.jupiter.api.BeforeEach;
24-
import org.junit.jupiter.api.Test;
25-
import org.junit.jupiter.api.Timeout;
20+
import org.junit.jupiter.api.*;
2621
import redis.clients.jedis.args.*;
2722
import redis.clients.jedis.exceptions.JedisDataException;
2823
import redis.clients.jedis.params.*;
@@ -36,6 +31,7 @@
3631
import redis.clients.jedis.util.JedisClusterTestUtil;
3732
import redis.clients.jedis.util.SafeEncoder;
3833

34+
@Tag("integration")
3935
public class ClusterPipeliningTest {
4036

4137
private static final String LOCAL_IP = "127.0.0.1";

0 commit comments

Comments
 (0)