Skip to content

Commit

Permalink
Use standard Redis docker image in CI
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gerzse committed May 24, 2024
1 parent b7a85eb commit 937a135
Show file tree
Hide file tree
Showing 13 changed files with 151 additions and 59 deletions.
37 changes: 21 additions & 16 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@ version: "3.8"
services:

redis:
image: redis/redis-stack-server:edge
image: redis:latest
container_name: redis-standalone
command: redis-server --enable-debug-command yes
ports:
- 6379:6379
environment:
- "REDIS_ARGS=--enable-debug-command yes --enable-module-command yes"
profiles:
- standalone
- sentinel
- replica
- all

replica:
image: redis/redis-stack-server:edge
image: redis:latest
container_name: redis-replica
depends_on:
- redis
environment:
- "REDIS_ARGS=--replicaof redis 6379"
command: redis-server --replicaof redis 6379
ports:
- 6380:6379
profiles:
Expand Down Expand Up @@ -63,13 +61,11 @@ services:
- "./dockers/stunnel/keys:/etc/stunnel/keys:ro"

sentinel:
image: redis/redis-stack-server:edge
image: redis:latest
container_name: redis-sentinel
depends_on:
- redis
environment:
- "REDIS_ARGS=--port 26379"
entrypoint: "/opt/redis-stack/bin/redis-sentinel /redis.conf --port 26379"
entrypoint: "/usr/local/bin/redis-sentinel /redis.conf --port 26379"
ports:
- 26379:26379
volumes:
Expand All @@ -79,13 +75,11 @@ services:
- all

sentinel2:
image: redis/redis-stack-server:edge
image: redis:latest
container_name: redis-sentinel2
depends_on:
- redis
environment:
- "REDIS_ARGS=--port 26380"
entrypoint: "/opt/redis-stack/bin/redis-sentinel /redis.conf --port 26380"
entrypoint: "/usr/local/bin/redis-sentinel /redis.conf --port 26380"
ports:
- 26380:26380
volumes:
Expand All @@ -95,15 +89,26 @@ services:
- all

sentinel3:
image: redis/redis-stack-server:edge
image: redis:latest
container_name: redis-sentinel3
depends_on:
- redis
entrypoint: "/opt/redis-stack/bin/redis-sentinel /redis.conf --port 26381"
entrypoint: "/usr/local/bin/redis-sentinel /redis.conf --port 26381"
ports:
- 26381:26381
volumes:
- "./dockers/sentinel.conf:/redis.conf"
profiles:
- sentinel
- all

redis-stack:
image: redis/redis-stack-server:edge
container_name: redis-stack
ports:
- 6479:6379
environment:
- "REDIS_ARGS=--enable-debug-command yes --enable-module-command yes"
profiles:
- standalone
- all
8 changes: 7 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
REDIS_INFO = {}
default_redis_url = "redis://localhost:6379/0"
default_protocol = "2"
default_redismod_url = "redis://localhost:6379"
default_redismod_url = "redis://localhost:6479"

# default ssl client ignores verification for the purpose of testing
default_redis_ssl_url = "rediss://localhost:6666"
Expand Down Expand Up @@ -341,6 +341,12 @@ def r(request):
yield client


@pytest.fixture()
def stack_r(request):
with _get_client(redis.Redis, request, from_url=default_redismod_url) as client:
yield client


@pytest.fixture()
def decoded_r(request):
with _get_client(redis.Redis, request, decode_responses=True) as client:
Expand Down
7 changes: 7 additions & 0 deletions tests/test_asyncio/test_bloom.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
from math import inf

import pytest
import pytest_asyncio
import redis.asyncio as redis
from redis.exceptions import ModuleError, RedisError
from redis.utils import HIREDIS_AVAILABLE
from tests.conftest import (
assert_resp_response,
default_redismod_url,
is_resp2_connection,
skip_ifmodversion_lt,
)


@pytest_asyncio.fixture()
async def decoded_r(create_redis):
return await create_redis(decode_responses=True, url=default_redismod_url)


def intlist(obj):
return [int(v) for v in obj]

Expand Down
8 changes: 7 additions & 1 deletion tests/test_asyncio/test_graph.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import pytest
import pytest_asyncio
import redis.asyncio as redis
from redis.commands.graph import Edge, Node, Path
from redis.commands.graph.execution_plan import Operation
from redis.exceptions import ResponseError
from tests.conftest import skip_if_redis_enterprise
from tests.conftest import default_redismod_url, skip_if_redis_enterprise


@pytest_asyncio.fixture()
async def decoded_r(create_redis):
return await create_redis(decode_responses=True, url=default_redismod_url)


async def test_bulk(decoded_r):
Expand Down
12 changes: 11 additions & 1 deletion tests/test_asyncio/test_json.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import pytest
import pytest_asyncio
import redis.asyncio as redis
from redis import exceptions
from redis.commands.json.path import Path
from tests.conftest import assert_resp_response, skip_ifmodversion_lt
from tests.conftest import (
assert_resp_response,
default_redismod_url,
skip_ifmodversion_lt,
)


@pytest_asyncio.fixture()
async def decoded_r(create_redis):
return await create_redis(decode_responses=True, url=default_redismod_url)


async def test_json_setbinarykey(decoded_r: redis.Redis):
Expand Down
7 changes: 7 additions & 0 deletions tests/test_asyncio/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from io import TextIOWrapper

import pytest
import pytest_asyncio
import redis.asyncio as redis
import redis.commands.search
import redis.commands.search.aggregation as aggregations
Expand All @@ -17,6 +18,7 @@
from redis.commands.search.suggestion import Suggestion
from tests.conftest import (
assert_resp_response,
default_redismod_url,
is_resp2_connection,
skip_if_redis_enterprise,
skip_ifmodversion_lt,
Expand All @@ -31,6 +33,11 @@
)


@pytest_asyncio.fixture()
async def decoded_r(create_redis):
return await create_redis(decode_responses=True, url=default_redismod_url)


async def waitForIndex(env, idx, timeout=None):
delay = 0.1
while True:
Expand Down
23 changes: 16 additions & 7 deletions tests/test_asyncio/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
from time import sleep

import pytest
import pytest_asyncio
import redis.asyncio as redis
from tests.conftest import (
assert_resp_response,
default_redismod_url,
is_resp2_connection,
skip_ifmodversion_lt,
)


@pytest_asyncio.fixture()
async def decoded_r(create_redis):
return await create_redis(decode_responses=True, url=default_redismod_url)


async def test_create(decoded_r: redis.Redis):
assert await decoded_r.ts().create(1)
assert await decoded_r.ts().create(2, retention_msecs=5)
Expand Down Expand Up @@ -214,18 +221,20 @@ async def test_del_range(decoded_r: redis.Redis):
)


async def test_range(r: redis.Redis):
async def test_range(decoded_r: redis.Redis):
for i in range(100):
await r.ts().add(1, i, i % 7)
assert 100 == len(await r.ts().range(1, 0, 200))
await decoded_r.ts().add(1, i, i % 7)
assert 100 == len(await decoded_r.ts().range(1, 0, 200))
for i in range(100):
await r.ts().add(1, i + 200, i % 7)
assert 200 == len(await r.ts().range(1, 0, 500))
await decoded_r.ts().add(1, i + 200, i % 7)
assert 200 == len(await decoded_r.ts().range(1, 0, 500))
# last sample isn't returned
assert 20 == len(
await r.ts().range(1, 0, 500, aggregation_type="avg", bucket_size_msec=10)
await decoded_r.ts().range(
1, 0, 500, aggregation_type="avg", bucket_size_msec=10
)
)
assert 10 == len(await r.ts().range(1, 0, 500, count=10))
assert 10 == len(await decoded_r.ts().range(1, 0, 500, count=10))


@skip_ifmodversion_lt("99.99.99", "timeseries")
Expand Down
16 changes: 15 additions & 1 deletion tests/test_bloom.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,21 @@
from redis.exceptions import ModuleError, RedisError
from redis.utils import HIREDIS_AVAILABLE

from .conftest import assert_resp_response, is_resp2_connection, skip_ifmodversion_lt
from .conftest import (
_get_client,
assert_resp_response,
default_redismod_url,
is_resp2_connection,
skip_ifmodversion_lt,
)


@pytest.fixture()
def decoded_r(request):
with _get_client(
redis.Redis, request, decode_responses=True, from_url=default_redismod_url
) as client:
yield client


def intlist(obj):
Expand Down
54 changes: 28 additions & 26 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1818,44 +1818,44 @@ def try_delete_libs(self, r, *lib_names):

@pytest.mark.onlynoncluster
@skip_if_server_version_lt("7.1.140")
def test_tfunction_load_delete(self, r):
self.try_delete_libs(r, "lib1")
def test_tfunction_load_delete(self, stack_r):
self.try_delete_libs(stack_r, "lib1")
lib_code = self.generate_lib_code("lib1")
assert r.tfunction_load(lib_code)
assert r.tfunction_delete("lib1")
assert stack_r.tfunction_load(lib_code)
assert stack_r.tfunction_delete("lib1")

@pytest.mark.onlynoncluster
@skip_if_server_version_lt("7.1.140")
def test_tfunction_list(self, r):
self.try_delete_libs(r, "lib1", "lib2", "lib3")
assert r.tfunction_load(self.generate_lib_code("lib1"))
assert r.tfunction_load(self.generate_lib_code("lib2"))
assert r.tfunction_load(self.generate_lib_code("lib3"))
def test_tfunction_list(self, stack_r):
self.try_delete_libs(stack_r, "lib1", "lib2", "lib3")
assert stack_r.tfunction_load(self.generate_lib_code("lib1"))
assert stack_r.tfunction_load(self.generate_lib_code("lib2"))
assert stack_r.tfunction_load(self.generate_lib_code("lib3"))

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

functions = r.tfunction_list(verbose=1)
functions = stack_r.tfunction_list(verbose=1)
assert len(functions) == 3

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

assert sorted(expected_names) == sorted(actual_names)
assert r.tfunction_delete("lib1")
assert r.tfunction_delete("lib2")
assert r.tfunction_delete("lib3")
assert stack_r.tfunction_delete("lib1")
assert stack_r.tfunction_delete("lib2")
assert stack_r.tfunction_delete("lib3")

@pytest.mark.onlynoncluster
@skip_if_server_version_lt("7.1.140")
def test_tfcall(self, r):
self.try_delete_libs(r, "lib1")
assert r.tfunction_load(self.generate_lib_code("lib1"))
assert r.tfcall("lib1", "foo") == b"bar"
assert r.tfcall_async("lib1", "foo") == b"bar"
def test_tfcall(self, stack_r):
self.try_delete_libs(stack_r, "lib1")
assert stack_r.tfunction_load(self.generate_lib_code("lib1"))
assert stack_r.tfcall("lib1", "foo") == b"bar"
assert stack_r.tfcall_async("lib1", "foo") == b"bar"

assert r.tfunction_delete("lib1")
assert stack_r.tfunction_delete("lib1")

def test_ttl(self, r):
r["a"] = "1"
Expand Down Expand Up @@ -5022,25 +5022,27 @@ def test_command_getkeysandflags(self, r: redis.Redis):
@pytest.mark.onlynoncluster
@skip_if_server_version_lt("4.0.0")
@skip_if_redis_enterprise()
def test_module(self, r):
def test_module(self, stack_r):
with pytest.raises(redis.exceptions.ModuleError) as excinfo:
r.module_load("/some/fake/path")
stack_r.module_load("/some/fake/path")
assert "Error loading the extension." in str(excinfo.value)

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

@pytest.mark.onlynoncluster
@skip_if_server_version_lt("7.0.0")
@skip_if_redis_enterprise()
def test_module_loadex(self, r: redis.Redis):
def test_module_loadex(self, stack_r: redis.Redis):
with pytest.raises(redis.exceptions.ModuleError) as excinfo:
r.module_loadex("/some/fake/path")
stack_r.module_loadex("/some/fake/path")
assert "Error loading the extension." in str(excinfo.value)

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

@skip_if_server_version_lt("2.6.0")
Expand Down
6 changes: 4 additions & 2 deletions tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
QueryResult,
)
from redis.exceptions import ResponseError
from tests.conftest import _get_client, skip_if_redis_enterprise
from tests.conftest import _get_client, default_redismod_url, skip_if_redis_enterprise


@pytest.fixture
def client(request):
r = _get_client(Redis, request, decode_responses=True)
r = _get_client(
Redis, request, decode_responses=True, from_url=default_redismod_url
)
r.flushdb()
return r

Expand Down
Loading

0 comments on commit 937a135

Please sign in to comment.