Skip to content

Commit 82987da

Browse files
committed
Use standard Redis docker image in CI
Adapt the tests to use the standard Redis docker image where possible, instead of using the Redis Stack image in all places. This way we can run the CI, at least in theory, against different versions of Redis and Redis Stack dockers.
1 parent b7a85eb commit 82987da

13 files changed

+138
-58
lines changed

docker-compose.yml

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,23 @@ version: "3.8"
55
services:
66

77
redis:
8-
image: redis/redis-stack-server:edge
8+
image: redis:latest
99
container_name: redis-standalone
10+
command: redis-server --enable-debug-command yes
1011
ports:
1112
- 6379:6379
12-
environment:
13-
- "REDIS_ARGS=--enable-debug-command yes --enable-module-command yes"
1413
profiles:
1514
- standalone
1615
- sentinel
1716
- replica
1817
- all
1918

2019
replica:
21-
image: redis/redis-stack-server:edge
20+
image: redis:latest
2221
container_name: redis-replica
2322
depends_on:
2423
- redis
25-
environment:
26-
- "REDIS_ARGS=--replicaof redis 6379"
24+
command: redis-server --replicaof redis 6379
2725
ports:
2826
- 6380:6379
2927
profiles:
@@ -63,13 +61,11 @@ services:
6361
- "./dockers/stunnel/keys:/etc/stunnel/keys:ro"
6462

6563
sentinel:
66-
image: redis/redis-stack-server:edge
64+
image: redis:latest
6765
container_name: redis-sentinel
6866
depends_on:
6967
- redis
70-
environment:
71-
- "REDIS_ARGS=--port 26379"
72-
entrypoint: "/opt/redis-stack/bin/redis-sentinel /redis.conf --port 26379"
68+
entrypoint: "/usr/local/bin/redis-sentinel /redis.conf --port 26379"
7369
ports:
7470
- 26379:26379
7571
volumes:
@@ -79,13 +75,11 @@ services:
7975
- all
8076

8177
sentinel2:
82-
image: redis/redis-stack-server:edge
78+
image: redis:latest
8379
container_name: redis-sentinel2
8480
depends_on:
8581
- redis
86-
environment:
87-
- "REDIS_ARGS=--port 26380"
88-
entrypoint: "/opt/redis-stack/bin/redis-sentinel /redis.conf --port 26380"
82+
entrypoint: "/usr/local/bin/redis-sentinel /redis.conf --port 26380"
8983
ports:
9084
- 26380:26380
9185
volumes:
@@ -95,15 +89,26 @@ services:
9589
- all
9690

9791
sentinel3:
98-
image: redis/redis-stack-server:edge
92+
image: redis:latest
9993
container_name: redis-sentinel3
10094
depends_on:
10195
- redis
102-
entrypoint: "/opt/redis-stack/bin/redis-sentinel /redis.conf --port 26381"
96+
entrypoint: "/usr/local/bin/redis-sentinel /redis.conf --port 26381"
10397
ports:
10498
- 26381:26381
10599
volumes:
106100
- "./dockers/sentinel.conf:/redis.conf"
107101
profiles:
108102
- sentinel
109103
- all
104+
105+
redis-stack:
106+
image: redis/redis-stack-server:edge
107+
container_name: redis-stack
108+
ports:
109+
- 6479:6379
110+
environment:
111+
- "REDIS_ARGS=--enable-debug-command yes --enable-module-command yes"
112+
profiles:
113+
- standalone
114+
- all

tests/conftest.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
REDIS_INFO = {}
1919
default_redis_url = "redis://localhost:6379/0"
2020
default_protocol = "2"
21-
default_redismod_url = "redis://localhost:6379"
21+
default_redismod_url = "redis://localhost:6479"
2222

2323
# default ssl client ignores verification for the purpose of testing
2424
default_redis_ssl_url = "rediss://localhost:6666"
@@ -341,6 +341,21 @@ def r(request):
341341
yield client
342342

343343

344+
@pytest.fixture()
345+
def stack_url(request):
346+
stack_url = request.config.getoption("--redis-url", default=default_redismod_url)
347+
if stack_url == default_redis_url:
348+
return default_redismod_url
349+
else:
350+
return stack_url
351+
352+
353+
@pytest.fixture()
354+
def stack_r(request, stack_url):
355+
with _get_client(redis.Redis, request, from_url=stack_url) as client:
356+
yield client
357+
358+
344359
@pytest.fixture()
345360
def decoded_r(request):
346361
with _get_client(redis.Redis, request, decode_responses=True) as client:

tests/test_asyncio/test_bloom.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from math import inf
22

33
import pytest
4+
import pytest_asyncio
45
import redis.asyncio as redis
56
from redis.exceptions import ModuleError, RedisError
67
from redis.utils import HIREDIS_AVAILABLE
@@ -11,6 +12,11 @@
1112
)
1213

1314

15+
@pytest_asyncio.fixture()
16+
async def decoded_r(create_redis, stack_url):
17+
return await create_redis(decode_responses=True, url=stack_url)
18+
19+
1420
def intlist(obj):
1521
return [int(v) for v in obj]
1622

tests/test_asyncio/test_graph.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import pytest
2+
import pytest_asyncio
23
import redis.asyncio as redis
34
from redis.commands.graph import Edge, Node, Path
45
from redis.commands.graph.execution_plan import Operation
56
from redis.exceptions import ResponseError
67
from tests.conftest import skip_if_redis_enterprise
78

89

10+
@pytest_asyncio.fixture()
11+
async def decoded_r(create_redis, stack_url):
12+
return await create_redis(decode_responses=True, url=stack_url)
13+
14+
915
async def test_bulk(decoded_r):
1016
with pytest.raises(NotImplementedError):
1117
await decoded_r.graph().bulk()

tests/test_asyncio/test_json.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import pytest
2+
import pytest_asyncio
23
import redis.asyncio as redis
34
from redis import exceptions
45
from redis.commands.json.path import Path
56
from tests.conftest import assert_resp_response, skip_ifmodversion_lt
67

78

9+
@pytest_asyncio.fixture()
10+
async def decoded_r(create_redis, stack_url):
11+
return await create_redis(decode_responses=True, url=stack_url)
12+
13+
814
async def test_json_setbinarykey(decoded_r: redis.Redis):
915
d = {"hello": "world", b"some": "value"}
1016
with pytest.raises(TypeError):

tests/test_asyncio/test_search.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from io import TextIOWrapper
66

77
import pytest
8+
import pytest_asyncio
89
import redis.asyncio as redis
910
import redis.commands.search
1011
import redis.commands.search.aggregation as aggregations
@@ -31,6 +32,11 @@
3132
)
3233

3334

35+
@pytest_asyncio.fixture()
36+
async def decoded_r(create_redis, stack_url):
37+
return await create_redis(decode_responses=True, url=stack_url)
38+
39+
3440
async def waitForIndex(env, idx, timeout=None):
3541
delay = 0.1
3642
while True:

tests/test_asyncio/test_timeseries.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from time import sleep
33

44
import pytest
5+
import pytest_asyncio
56
import redis.asyncio as redis
67
from tests.conftest import (
78
assert_resp_response,
@@ -10,6 +11,11 @@
1011
)
1112

1213

14+
@pytest_asyncio.fixture()
15+
async def decoded_r(create_redis, stack_url):
16+
return await create_redis(decode_responses=True, url=stack_url)
17+
18+
1319
async def test_create(decoded_r: redis.Redis):
1420
assert await decoded_r.ts().create(1)
1521
assert await decoded_r.ts().create(2, retention_msecs=5)
@@ -214,18 +220,20 @@ async def test_del_range(decoded_r: redis.Redis):
214220
)
215221

216222

217-
async def test_range(r: redis.Redis):
223+
async def test_range(decoded_r: redis.Redis):
218224
for i in range(100):
219-
await r.ts().add(1, i, i % 7)
220-
assert 100 == len(await r.ts().range(1, 0, 200))
225+
await decoded_r.ts().add(1, i, i % 7)
226+
assert 100 == len(await decoded_r.ts().range(1, 0, 200))
221227
for i in range(100):
222-
await r.ts().add(1, i + 200, i % 7)
223-
assert 200 == len(await r.ts().range(1, 0, 500))
228+
await decoded_r.ts().add(1, i + 200, i % 7)
229+
assert 200 == len(await decoded_r.ts().range(1, 0, 500))
224230
# last sample isn't returned
225231
assert 20 == len(
226-
await r.ts().range(1, 0, 500, aggregation_type="avg", bucket_size_msec=10)
232+
await decoded_r.ts().range(
233+
1, 0, 500, aggregation_type="avg", bucket_size_msec=10
234+
)
227235
)
228-
assert 10 == len(await r.ts().range(1, 0, 500, count=10))
236+
assert 10 == len(await decoded_r.ts().range(1, 0, 500, count=10))
229237

230238

231239
@skip_ifmodversion_lt("99.99.99", "timeseries")

tests/test_bloom.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,20 @@
55
from redis.exceptions import ModuleError, RedisError
66
from redis.utils import HIREDIS_AVAILABLE
77

8-
from .conftest import assert_resp_response, is_resp2_connection, skip_ifmodversion_lt
8+
from .conftest import (
9+
_get_client,
10+
assert_resp_response,
11+
is_resp2_connection,
12+
skip_ifmodversion_lt,
13+
)
14+
15+
16+
@pytest.fixture()
17+
def decoded_r(request, stack_url):
18+
with _get_client(
19+
redis.Redis, request, decode_responses=True, from_url=stack_url
20+
) as client:
21+
yield client
922

1023

1124
def intlist(obj):

tests/test_commands.py

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,44 +1818,44 @@ def try_delete_libs(self, r, *lib_names):
18181818

18191819
@pytest.mark.onlynoncluster
18201820
@skip_if_server_version_lt("7.1.140")
1821-
def test_tfunction_load_delete(self, r):
1822-
self.try_delete_libs(r, "lib1")
1821+
def test_tfunction_load_delete(self, stack_r):
1822+
self.try_delete_libs(stack_r, "lib1")
18231823
lib_code = self.generate_lib_code("lib1")
1824-
assert r.tfunction_load(lib_code)
1825-
assert r.tfunction_delete("lib1")
1824+
assert stack_r.tfunction_load(lib_code)
1825+
assert stack_r.tfunction_delete("lib1")
18261826

18271827
@pytest.mark.onlynoncluster
18281828
@skip_if_server_version_lt("7.1.140")
1829-
def test_tfunction_list(self, r):
1830-
self.try_delete_libs(r, "lib1", "lib2", "lib3")
1831-
assert r.tfunction_load(self.generate_lib_code("lib1"))
1832-
assert r.tfunction_load(self.generate_lib_code("lib2"))
1833-
assert r.tfunction_load(self.generate_lib_code("lib3"))
1829+
def test_tfunction_list(self, stack_r):
1830+
self.try_delete_libs(stack_r, "lib1", "lib2", "lib3")
1831+
assert stack_r.tfunction_load(self.generate_lib_code("lib1"))
1832+
assert stack_r.tfunction_load(self.generate_lib_code("lib2"))
1833+
assert stack_r.tfunction_load(self.generate_lib_code("lib3"))
18341834

18351835
# test error thrown when verbose > 4
18361836
with pytest.raises(redis.exceptions.DataError):
1837-
assert r.tfunction_list(verbose=8)
1837+
assert stack_r.tfunction_list(verbose=8)
18381838

1839-
functions = r.tfunction_list(verbose=1)
1839+
functions = stack_r.tfunction_list(verbose=1)
18401840
assert len(functions) == 3
18411841

18421842
expected_names = [b"lib1", b"lib2", b"lib3"]
18431843
actual_names = [functions[0][13], functions[1][13], functions[2][13]]
18441844

18451845
assert sorted(expected_names) == sorted(actual_names)
1846-
assert r.tfunction_delete("lib1")
1847-
assert r.tfunction_delete("lib2")
1848-
assert r.tfunction_delete("lib3")
1846+
assert stack_r.tfunction_delete("lib1")
1847+
assert stack_r.tfunction_delete("lib2")
1848+
assert stack_r.tfunction_delete("lib3")
18491849

18501850
@pytest.mark.onlynoncluster
18511851
@skip_if_server_version_lt("7.1.140")
1852-
def test_tfcall(self, r):
1853-
self.try_delete_libs(r, "lib1")
1854-
assert r.tfunction_load(self.generate_lib_code("lib1"))
1855-
assert r.tfcall("lib1", "foo") == b"bar"
1856-
assert r.tfcall_async("lib1", "foo") == b"bar"
1852+
def test_tfcall(self, stack_r):
1853+
self.try_delete_libs(stack_r, "lib1")
1854+
assert stack_r.tfunction_load(self.generate_lib_code("lib1"))
1855+
assert stack_r.tfcall("lib1", "foo") == b"bar"
1856+
assert stack_r.tfcall_async("lib1", "foo") == b"bar"
18571857

1858-
assert r.tfunction_delete("lib1")
1858+
assert stack_r.tfunction_delete("lib1")
18591859

18601860
def test_ttl(self, r):
18611861
r["a"] = "1"
@@ -5022,25 +5022,27 @@ def test_command_getkeysandflags(self, r: redis.Redis):
50225022
@pytest.mark.onlynoncluster
50235023
@skip_if_server_version_lt("4.0.0")
50245024
@skip_if_redis_enterprise()
5025-
def test_module(self, r):
5025+
def test_module(self, stack_r):
50265026
with pytest.raises(redis.exceptions.ModuleError) as excinfo:
5027-
r.module_load("/some/fake/path")
5027+
stack_r.module_load("/some/fake/path")
50285028
assert "Error loading the extension." in str(excinfo.value)
50295029

50305030
with pytest.raises(redis.exceptions.ModuleError) as excinfo:
5031-
r.module_load("/some/fake/path", "arg1", "arg2", "arg3", "arg4")
5031+
stack_r.module_load("/some/fake/path", "arg1", "arg2", "arg3", "arg4")
50325032
assert "Error loading the extension." in str(excinfo.value)
50335033

50345034
@pytest.mark.onlynoncluster
50355035
@skip_if_server_version_lt("7.0.0")
50365036
@skip_if_redis_enterprise()
5037-
def test_module_loadex(self, r: redis.Redis):
5037+
def test_module_loadex(self, stack_r: redis.Redis):
50385038
with pytest.raises(redis.exceptions.ModuleError) as excinfo:
5039-
r.module_loadex("/some/fake/path")
5039+
stack_r.module_loadex("/some/fake/path")
50405040
assert "Error loading the extension." in str(excinfo.value)
50415041

50425042
with pytest.raises(redis.exceptions.ModuleError) as excinfo:
5043-
r.module_loadex("/some/fake/path", ["name", "value"], ["arg1", "arg2"])
5043+
stack_r.module_loadex(
5044+
"/some/fake/path", ["name", "value"], ["arg1", "arg2"]
5045+
)
50445046
assert "Error loading the extension." in str(excinfo.value)
50455047

50465048
@skip_if_server_version_lt("2.6.0")

tests/test_graph.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525

2626
@pytest.fixture
27-
def client(request):
28-
r = _get_client(Redis, request, decode_responses=True)
27+
def client(request, stack_url):
28+
r = _get_client(Redis, request, decode_responses=True, from_url=stack_url)
2929
r.flushdb()
3030
return r
3131

tests/test_json.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99

1010
@pytest.fixture
11-
def client(request):
12-
r = _get_client(Redis, request, decode_responses=True)
11+
def client(request, stack_url):
12+
r = _get_client(Redis, request, decode_responses=True, from_url=stack_url)
1313
r.flushdb()
1414
return r
1515

tests/test_search.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ def createIndex(client, num_docs=100, definition=None):
107107

108108

109109
@pytest.fixture
110-
def client(request):
111-
r = _get_client(redis.Redis, request, decode_responses=True)
110+
def client(request, stack_url):
111+
r = _get_client(redis.Redis, request, decode_responses=True, from_url=stack_url)
112112
r.flushdb()
113113
return r
114114

0 commit comments

Comments
 (0)