Skip to content

Commit

Permalink
Introduces test matrix based on Redis versions [8.0-M02, 7.4.1, 7.2.6…
Browse files Browse the repository at this point in the history
…, 6.2.16] (redis#4015)

* Introduces test matrix based on Redis versions [8.0-M1, 7.4.1, 7.2.6, 6.2.16]

Use docker composer to bring up the test env using `redislabs/client-libs-test` image.

When run against older Redis version some tests are using commands available only in newer Redis server versions. To resolve this we are introducing two new annotations/rules

 - Introduce `SinceRedisVersion` annotation/Rule - for conditionally running tests based on Redis server version contacted
 - Introduce `EnableOnCommad` annotation/Rule -  for conditionally running tests based on command availability on the server

And mark respective tests with the least Redis Version required by the test
 - SinceRedisVersion ("7.4.0") - Mark tests using commands/modifiers introduced with Redis 7.4.0
 - SinceRedisVersion ("7.2.0") - Mark tests using commands/modifiers introduced with Redis 7.2.0
 - SinceRedisVersion ("7.0.0") - Mark tests using commands/modifiers introduced with Redis 7.0.0

 The same approach used to mark CSC tests
 - Disabled client-side caching tests for versions below  7.4

- Test env migrated to use native Redis server TLS instead of  using stunnel

Not all tests were migrated
 - Disable Modules test in containerized test env ModuleTest uses custom test module to test load/unload/sendCommand.
    Requires pre-build test module on the same os like test container to avoid errors

 - Disable UDS tests in containerized test env
    No easy way to make unix sockets work on MAC with docker

---------

Co-authored-by: M Sazzadul Hoque <[email protected]>
  • Loading branch information
ggivo and sazzad16 authored Jan 14, 2025
1 parent 180d9aa commit f9977e4
Show file tree
Hide file tree
Showing 138 changed files with 2,690 additions and 539 deletions.
47 changes: 47 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,53 @@ Jedis unit tests use many Redis instances, so we use a ```Makefile``` to prepare
Start unit tests with ```make test```.
Set up test environments with ```make start```, tear down those environments with ```make stop``` and clean up the environment files with ```make cleanup```.


# Jedis Test Environment Using Docker

This guide explains how to bootstrap and manage a test environment for Jedis using Docker Compose.

## Workflow Steps
1. **Start the test environment** by running the following command (examples below).
- For instance, to start the environment with Redis 8.0-M02, use `make start-test-env`.
2. **Run tests** through your IDE, Maven, or other testing tools as needed.
3. **Stop the test environment** by running the following command:
- `make stop-test-env`
- This will stop and tear down the Docker containers running the Redis service

# Start the Test Environment Using Docker

You can bootstrap the test environment for supported versions of Redis using the provided `make` targets.

## Option 1: Using `make` Targets
To bring up the test environment for a specific Redis version (8.0-M02, 7.4.1, 7.2.6, or 6.2.16), use the following command:
```bash
make start-test-env version=8.0-M02 # Replace with desired version
```
To stop test environment:
```bash
make stop-test-env
```
To run tests using dockerized environment:
```bash
make test-on-docker
```

## Option 2: Using docker compose commands directly
Docker compose file can be found in `src/test/resources/env` folder.
- **Redis 8.0-M02**
```bash
rm -rf /tmp/redis-env-work
export REDIS_VERSION=8.0-M02
docker compose up
```
- **Redis 7.4.1, 7.2.6, 6.2.16,**
```bash
rm -rf /tmp/redis-env-work
export REDIS_VERSION=6.2.16
docker compose --env-file .env --env-file .env.v6.2.16 up
```


# Some rules of Jedis source code

## Code Convention
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
mvn javadoc:jar
- name: Run tests
run: |
export TEST_ENV_PROVIDER=local
make test
env:
JVM_OPTS: -Xmx3200m
Expand Down
124 changes: 124 additions & 0 deletions .github/workflows/test-on-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
---

name: Build and Test using containerized environment

on:
push:
paths-ignore:
- 'docs/**'
- '**/*.md'
- '**/*.rst'
branches:
- master
- '[0-9].*'
pull_request:
branches:
- master
- '[0-9].*'
schedule:
- cron: '0 1 * * *' # nightly build
workflow_dispatch:
inputs:
specific_test:
description: 'Run specific test(s) (optional)'
required: false
default: ''
jobs:

build:
name: Build and Test
runs-on: ubuntu-latest
env:
REDIS_ENV_WORK_DIR: ${{ github.workspace }}/redis-env-work
REDIS_ENV_CONF_DIR: ${{ github.workspace }}/src/test/resources/env
CLIENT_LIBS_IMAGE_PREFIX: "redislabs/client-libs-test"
strategy:
fail-fast: false
matrix:
redis_version:
- "8.0-M02"
- "7.4.1"
- "7.2.6"
# - "6.2.16"
steps:
- uses: actions/checkout@v2
- name: Set up publishing to maven central
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'temurin'
- name: System setup
run: |
sudo apt update
sudo apt install -y make
make compile-module
- name: Cache dependencies
uses: actions/cache@v2
with:
path: |
~/.m2/repository
/var/cache/apt
key: jedis-${{hashFiles('**/pom.xml')}}
# Set up Docker Compose environment
- name: Set up Docker Compose environment
run: |
mkdir -m 777 $REDIS_ENV_WORK_DIR
export REDIS_VERSION="${{ matrix.redis_version }}"
make start-test-env version=$REDIS_VERSION
- name: Maven offline
run: |
mvn -q dependency:go-offline
- name: Build docs
run: |
mvn javadoc:jar
# Run Tests
- name: Run Maven tests
run: |
export TEST_ENV_PROVIDER=docker
export TEST_WORK_FOLDER=$REDIS_ENV_WORK_DIR
echo $TEST_WORK_FOLDER
if [ -z "$TESTS" ]; then
mvn clean compile test
else
mvn -Dtest=$TESTS clean compile test
fi
env:
TESTS: ${{ github.event.inputs.specific_test || '' }}
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: |
target/surefire-reports/**/*.xml
# Collect logs on failure
- name: Collect logs on failure
if: failure() # This runs only if the previous steps failed
run: |
echo "Collecting logs from $WORK_DIR..."
ls -la $REDIS_ENV_WORK_DIR
# Upload logs as artifacts
- name: Upload logs on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: redis-env-work-logs-${{ matrix.redis_version }}
path: ${{ env.REDIS_ENV_WORK_DIR }}
# Bring down the Docker Compose test environment
- name: Tear down Docker Compose environment
if: always()
run: |
docker compose $COMPOSE_ENV_FILES -f src/test/resources/env/docker-compose.yml down
continue-on-error: true
# Upload code coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload test results to Codecov
if: ${{ github.event_name == 'schedule' || (github.event_name == 'push') || github.event_name == 'workflow_dispatch'}}
uses: codecov/test-results-action@v1
with:
fail_ci_if_error: false
files: ./target/surefire-reports/TEST*
token: ${{ secrets.CODECOV_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ build/
bin/
tags
.idea
.run
*.aof
*.rdb
redis-git
appendonlydir/
.DS_Store
Loading

0 comments on commit f9977e4

Please sign in to comment.