Skip to content

Commit

Permalink
Add make target to start containerised test env.
Browse files Browse the repository at this point in the history
  • Loading branch information
ggivo committed Nov 23, 2024
1 parent accfea2 commit e1c0453
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 28 deletions.
50 changes: 24 additions & 26 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,41 +31,39 @@ Set up test environments with ```make start```, tear down those environments wit
This guide explains how to bootstrap and manage a test environment for Jedis using Docker Compose.

## Workflow Steps
1. **Bring up the test environment** (examples provided below).
2. **Run tests** (via IDE, Maven, etc.).
3. **Destroy the test environment** using `docker compose down`.
1. **Start the test environment** by running the following command (examples below).
- For instance, to start the environment with Redis 8.0-M01, 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

### Important Note
The default test environment uses the temporary work folder `./redis-env-work`.
Some tests might leave Redis nodes in an inconsistent state, so this folder should be cleaned or removed before bootstrapping the environment again.
# Start the Test Environment Using Docker

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

## Bootstrap test env using Docker
- **Redis 8.0-M01**
## Option 1: Using `make` Targets
To bring up the test environment for a specific Redis version (8.0-M01, 7.4.1, 7.2.6, or 6.2.16), use the following command:
```bash
make start-test-env version=8.0-M01 # Replace with desired version
```
rm -rf ./redis-env-work

## Option 2: Using docker compose commands directly
Docker compose file can be found in `src/test/resources/env` folder.
- **Redis 8.0-M01, 7.4.1, 7.2.6**
```bash
rm -rf /tmp/redis-env-work
export REDIS_VERSION=8.0-M01
docker compose --env-file src/test/resources/env/.env -f src/test/resources/env/docker-compose.yml up
```
- **Redis 7.4.1**
```
rm -rf ./redis-env-work
export REDIS_VERSION=7.4.1
docker compose --env-file src/test/resources/env/.env -f src/test/resources/env/docker-compose.yml up
```
- **Redis 7.2.6**
```
rm -rf ./redis-env-work
export REDIS_VERSION=7.2.6
docker compose --env-file src/test/resources/env/.env -f src/test/resources/env/docker-compose.yml up
docker compose up
```
- **Redis 6.2.16**
- **NOTE :** 6.2.16 uses a dedicated .env.v6.12.16 file, since some of the redis configuration settings are not supported in 6.2.16
```
rm -rf ./redis-env-work
docker compose --env-file src/test/resources/env/.env.v6.12.16 -f src/test/resources/env/docker-compose.yml up
- **NOTE:** Redis 6.2.16 uses a dedicated `.env.v6.2.16`.
```bash
rm -rf /tmp/redis-env-work
docker compose --env-file .env.v6.2.16 up
```


# Some rules of Jedis source code

## Code Convention
Expand Down
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
PATH := ./redis-git/src:${PATH}

# Supported test env versions
SUPPORTED_TEST_ENV_VERSIONS := 8.0-M01 7.4.1 7.2.6 6.2.16
DEFAULT_TEST_ENV_VERSION := 8.0-M01

define REDIS1_CONF
daemonize yes
protected-mode no
Expand Down Expand Up @@ -559,5 +563,32 @@ system-setup:
compile-module:
gcc -shared -o /tmp/testmodule.so -fPIC src/test/resources/testmodule.c

# Start test environment with specific version using predefined docker compose setup

start-test-env:
@if [ -z "$(version)" ]; then \
version=$(arg); \
if [ -z "$$version" ]; then \
version="$(DEFAULT_TEST_ENV_VERSION)"; \
fi; \
fi; \
if ! echo "$(SUPPORTED_TEST_ENV_VERSIONS)" | grep -qw "$$version"; then \
echo "Error: Invalid version '$$version'. Supported versions are: $(SUPPORTED_TEST_ENV_VERSIONS)."; \
exit 1; \
fi; \
env_file="src/test/resources/env/.env"; \
if [ "$$version" = "6.2.16" ]; then \
env_file="src/test/resources/env/.env.v6.2.16"; \
fi; \
rm -rf /tmp/redis-env-work; \
export REDIS_VERSION=$$version && \
docker compose --env-file $$env_file -f src/test/resources/env/docker-compose.yml up -d; \
echo "Started test environment with Redis version $$version."

# Stop the test environment
stop-test-env:
docker compose -f src/test/resources/env/docker-compose.yml down; \
rm -rf /tmp/redis-env-work; \
echo "Stopped test environment and performed cleanup."

.PHONY: test
2 changes: 1 addition & 1 deletion src/test/resources/env/.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ REDIS_VERSION=8.0-M01
CLIENT_LIBS_TEST_IMAGE=redislabs/client-libs-test
REDIS_ENV_CONF_DIR=./
REDIS_MODULES_DIR=/tmp
REDIS_ENV_WORK_DIR=./redis-env-work
REDIS_ENV_WORK_DIR=/tmp/redis-env-work

ENABLE_MODULE_COMMAND_DIRECTIVE=--enable-module-command yes
2 changes: 1 addition & 1 deletion src/test/resources/env/.env.v6.2.16
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ REDIS_VERSION=6.2.16
CLIENT_LIBS_TEST_IMAGE=redislabs/client-libs-test
REDIS_ENV_CONF_DIR=./
REDIS_MODULES_DIR=/tmp
REDIS_ENV_WORK_DIR=./redis-env-work
REDIS_ENV_WORK_DIR=/tmp/redis-env-work

#REMOVE UNSUPPORTED DIRECTIVE
ENABLE_MODULE_COMMAND_DIRECTIVE=

0 comments on commit e1c0453

Please sign in to comment.