Skip to content

Commit 058f89d

Browse files
committed
Streamline test execution
- Automatically map Redis version to Redis Stack version and use it for testing module commands - Remove Graph commands from execution by default - Include more Redis versions to the test matrix
1 parent d02d54e commit 058f89d

File tree

10 files changed

+118
-81
lines changed

10 files changed

+118
-81
lines changed

.github/actions/run-tests/action.yml

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,69 @@ runs:
2929
cache: 'pip'
3030

3131
- name: Setup Test environment
32+
env:
33+
REDIS_VERSION: ${{ inputs.redis-version }}
34+
REDIS_IMAGE: "redis:${{ inputs.redis-version }}"
35+
CLIENT_LIBS_TEST_IMAGE: "redislabs/client-libs-test:${{ inputs.redis-version }}"
3236
run: |
3337
pip install -U setuptools wheel
3438
pip install -r requirements.txt
3539
pip install -r dev_requirements.txt
3640
if [ "${{inputs.parser-backend}}" == "hiredis" ]; then
3741
pip install hiredis${{inputs.hiredis-version}}
3842
fi
39-
invoke devenv
43+
44+
redis_major_version=$(echo "$REDIS_VERSION" | grep -oP '^\d+')
45+
46+
if (( major_version < 8 )); then
47+
echo "Using redis-stack for module tests"
48+
49+
# Mapping of redis version to stack version
50+
declare -A redis_stack_version_mapping=(
51+
["7.4.1"]="7.4.0-v1"
52+
["7.2.6"]="7.2.0-v13"
53+
["6.2.16"]="6.2.6-v17"
54+
)
55+
56+
if [[ -v version_mapping[$REDIS_VERSION] ]]; then
57+
export REDIS_STACK_IMAGE="redis/redis-stack-server:${version_mapping[$version]}"
58+
echo "REDISMOD_URL=redis://127.0.0.1:6479/0" >> $GITHUB_ENV
59+
else
60+
echo "Version not found in the mapping."
61+
exit 1
62+
fi
63+
invoke devenv --endpoints all-stack
64+
else
65+
echo "Using redis CE for module tests"
66+
echo "REDISMOD_URL=redis://127.0.0.1:6379" >> $GITHUB_ENV
67+
invoke devenv --endpoints all
68+
fi
69+
4070
sleep 10 # time to settle
4171
shell: bash
4272

4373
- name: Run RESP2 tests
4474
run: |
4575
if [ "${{inputs.event-loop}}" == "uvloop" ]; then
46-
invoke standalone-tests --uvloop --protocol=2
76+
invoke standalone-tests --redismod-url=${REDISMOD_URL} --uvloop --protocol=2
4777
invoke cluster-tests --uvloop --protocol=2
4878
else
49-
invoke standalone-tests --protocol=2
79+
invoke standalone-tests --redismod-url=${REDISMOD_URL} --protocol=2
5080
invoke cluster-tests --protocol=2
5181
fi
5282
shell: bash
5383

5484
- name: Run RESP3 tests
5585
run: |
5686
if [ "${{inputs.event-loop}}" == "uvloop" ]; then
57-
invoke standalone-tests --uvloop --protocol=3
87+
invoke standalone-tests --redismod-url=${REDISMOD_URL} --uvloop --protocol=3
5888
5989
# hiredis does not support RESP3 on cluster
6090
if [ "${{inputs.parser-backend}}" != 'hiredis' ]; then
6191
invoke cluster-tests --uvloop --protocol=3
6292
fi
6393
else
64-
invoke standalone-tests --protocol=3
94+
invoke standalone-tests --redismod-url=${REDISMOD_URL} --protocol=3
6595
6696
# hiredis does not support RESP3 on cluster
6797
if [ "${{inputs.parser-backend}}" != 'hiredis' ]; then

.github/workflows/integration.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
max-parallel: 15
6464
fail-fast: false
6565
matrix:
66-
redis-version: ['8.0.0-M01']
66+
redis-version: ['8.0.0-M01', '7.4.1', '7.2.6', '6.2.16']
6767
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', 'pypy-3.9', 'pypy-3.10']
6868
parser-backend: ['plain']
6969
event-loop: ['asyncio']
@@ -76,7 +76,6 @@ jobs:
7676
uses: ./.github/actions/run-tests
7777
with:
7878
python-version: ${{ matrix.python-version }}
79-
test-type: ${{ matrix.test-type }}
8079
parser-backend: ${{ matrix.parser-backend }}
8180
redis-version: ${{ matrix.redis-version }}
8281

@@ -122,7 +121,6 @@ jobs:
122121
fail-fast: false
123122
matrix:
124123
redis-version: [ '8.0.0-M01' ]
125-
test-type: [ 'standalone', 'cluster' ]
126124
python-version: [ '3.8', '3.12' ]
127125
parser-backend: [ 'plain' ]
128126
event-loop: [ 'uvloop' ]

docker-compose.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
services:
44

55
redis:
6-
image: redislabs/client-libs-test:8.0-M01
6+
image: ${CLIENT_LIBS_TEST_IMAGE:-redislabs/client-libs-test:8.0-M01}
77
container_name: redis-standalone
88
environment:
99
- TLS_ENABLED=yes
@@ -20,6 +20,7 @@ services:
2020
- standalone
2121
- sentinel
2222
- replica
23+
- all-stack
2324
- all
2425

2526
replica:
@@ -32,10 +33,11 @@ services:
3233
- 6380:6379
3334
profiles:
3435
- replica
36+
- all-stack
3537
- all
3638

3739
cluster:
38-
image: redislabs/client-libs-test:8.0-M01
40+
image: ${CLIENT_LIBS_TEST_IMAGE:-redislabs/client-libs-test:8.0-M01}
3941
container_name: redis-cluster
4042
environment:
4143
- REDIS_CLUSTER=yes
@@ -51,6 +53,7 @@ services:
5153
- "./dockers/cluster:/redis/work"
5254
profiles:
5355
- cluster
56+
- all-stack
5457
- all
5558

5659
sentinel:
@@ -65,6 +68,7 @@ services:
6568
- "./dockers/sentinel.conf:/redis.conf"
6669
profiles:
6770
- sentinel
71+
- all-stack
6872
- all
6973

7074
sentinel2:
@@ -79,6 +83,7 @@ services:
7983
- "./dockers/sentinel.conf:/redis.conf"
8084
profiles:
8185
- sentinel
86+
- all-stack
8287
- all
8388

8489
sentinel3:
@@ -93,6 +98,7 @@ services:
9398
- "./dockers/sentinel.conf:/redis.conf"
9499
profiles:
95100
- sentinel
101+
- all-stack
96102
- all
97103

98104
redis-stack:
@@ -104,13 +110,12 @@ services:
104110
- "REDIS_ARGS=--enable-debug-command yes --enable-module-command yes"
105111
profiles:
106112
- standalone
107-
- all
113+
- all-stack
108114

109115
redis-stack-graph:
110116
image: redis/redis-stack-server:6.2.6-v15
111117
container_name: redis-stack-graph
112118
ports:
113119
- 6480:6379
114120
profiles:
115-
- standalone
116-
- all
121+
- graph

tasks.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,18 @@ def tests(c, uvloop=False, protocol=2, profile=False):
5050

5151

5252
@task
53-
def standalone_tests(c, uvloop=False, protocol=2, profile=False):
53+
def standalone_tests(c, uvloop=False, protocol=2, profile=False, redis_mod_url=None):
5454
"""Run tests against a standalone redis instance"""
5555
profile_arg = "--profile" if profile else ""
56+
redis_mod_url = f"--redis-mod-url={redis_mod_url}" if redis_mod_url else ""
57+
5658
if uvloop:
5759
run(
58-
f"pytest {profile_arg} --protocol={protocol} --cov=./ --cov-report=xml:coverage_resp{protocol}_uvloop.xml -m 'not onlycluster' --uvloop --junit-xml=standalone-resp{protocol}-uvloop-results.xml"
60+
f"pytest {profile_arg} --protocol={protocol} {redis_mod_url} --cov=./ --cov-report=xml:coverage_resp{protocol}_uvloop.xml -m 'not onlycluster and not graph' --uvloop --junit-xml=standalone-resp{protocol}-uvloop-results.xml"
5961
)
6062
else:
6163
run(
62-
f"pytest {profile_arg} --protocol={protocol} --cov=./ --cov-report=xml:coverage_resp{protocol}.xml -m 'not onlycluster' --junit-xml=standalone-resp{protocol}-results.xml"
64+
f"pytest {profile_arg} --protocol={protocol} {redis_mod_url} --cov=./ --cov-report=xml:coverage_resp{protocol}.xml -m 'not onlycluster and not graph' --junit-xml=standalone-resp{protocol}-results.xml"
6365
)
6466

6567

@@ -71,11 +73,11 @@ def cluster_tests(c, uvloop=False, protocol=2, profile=False):
7173
cluster_tls_url = "rediss://localhost:17379/0"
7274
if uvloop:
7375
run(
74-
f"pytest {profile_arg} --protocol={protocol} --cov=./ --cov-report=xml:coverage_cluster_resp{protocol}_uvloop.xml -m 'not onlynoncluster and not redismod' --redis-url={cluster_url} --redis-ssl-url={cluster_tls_url} --junit-xml=cluster-resp{protocol}-uvloop-results.xml --uvloop"
76+
f"pytest {profile_arg} --protocol={protocol} --cov=./ --cov-report=xml:coverage_cluster_resp{protocol}_uvloop.xml -m 'not onlynoncluster and not redismod and not graph' --redis-url={cluster_url} --redis-ssl-url={cluster_tls_url} --junit-xml=cluster-resp{protocol}-uvloop-results.xml --uvloop"
7577
)
7678
else:
7779
run(
78-
f"pytest {profile_arg} --protocol={protocol} --cov=./ --cov-report=xml:coverage_cluster_resp{protocol}.xml -m 'not onlynoncluster and not redismod' --redis-url={cluster_url} --redis-ssl-url={cluster_tls_url} --junit-xml=cluster-resp{protocol}-results.xml"
80+
f"pytest {profile_arg} --protocol={protocol} --cov=./ --cov-report=xml:coverage_cluster_resp{protocol}.xml -m 'not onlynoncluster and not redismod and not graph' --redis-url={cluster_url} --redis-ssl-url={cluster_tls_url} --junit-xml=cluster-resp{protocol}-results.xml"
7981
)
8082

8183

tests/conftest.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ def pytest_addoption(parser):
103103
help="Redis connection string, defaults to `%(default)s`",
104104
)
105105

106+
parser.addoption(
107+
"--redis-mod-url",
108+
default=default_redismod_url,
109+
action="store",
110+
help="Redis with modules connection string, defaults to `%(default)s`",
111+
)
112+
106113
parser.addoption(
107114
"--protocol",
108115
default=default_protocol,
@@ -182,9 +189,8 @@ def pytest_sessionstart(session):
182189
session.config.REDIS_INFO = REDIS_INFO
183190

184191
# module info
185-
stack_url = redis_url
186-
if stack_url == default_redis_url:
187-
stack_url = default_redismod_url
192+
stack_url = session.config.getoption("--redis-mod-url")
193+
188194
try:
189195
stack_info = _get_info(stack_url)
190196
REDIS_INFO["modules"] = stack_info["modules"]
@@ -392,11 +398,7 @@ def r(request):
392398

393399
@pytest.fixture()
394400
def stack_url(request):
395-
stack_url = request.config.getoption("--redis-url", default=default_redismod_url)
396-
if stack_url == default_redis_url:
397-
return default_redismod_url
398-
else:
399-
return stack_url
401+
return request.config.getoption("--redis-mod-url", default=default_redismod_url)
400402

401403

402404
@pytest.fixture()

0 commit comments

Comments
 (0)