Skip to content

Commit 338cbfd

Browse files
committed
Re-enable Graph tests (#3287)
Although the Graph module was deprecated, we want to have tests running as long as we keep the client code. Therefore re-enable the Graph tests, by adding to the docker-compose stack an older redis-stack-server image. The Graph tests run only with RESP2. Tweak the CI so that it runs against the latest RC release for now. This way we get all the features in RC release of server, so we can execute all tests, including the ones for hash field expiration. Some test failures brought to light issues with the RESP3 push message invalidation handler, align a bit the code in that area. Some more housekeeping around tests, here and there.
1 parent 532bc02 commit 338cbfd

File tree

8 files changed

+88
-38
lines changed

8 files changed

+88
-38
lines changed

.github/workflows/integration.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ permissions:
2424
contents: read # to fetch code (actions/checkout)
2525

2626
env:
27-
REDIS_STACK_IMAGE: redis/redis-stack-server:7.4.0-rc1
2827
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
28+
REDIS_IMAGE: redis/redis-stack-server:7.4.0-rc1
29+
REDIS_STACK_IMAGE: redis/redis-stack-server:7.4.0-rc1
2930

3031
jobs:
3132
dependency-audit:

docker-compose.yml

+14-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ services:
77
redis:
88
image: ${REDIS_IMAGE:-redis:latest}
99
container_name: redis-standalone
10-
command: redis-server --enable-debug-command yes
10+
command: redis-server --enable-debug-command yes --protected-mode no
1111
ports:
1212
- 6379:6379
1313
profiles:
@@ -21,7 +21,7 @@ services:
2121
container_name: redis-replica
2222
depends_on:
2323
- redis
24-
command: redis-server --replicaof redis 6379
24+
command: redis-server --replicaof redis 6379 --protected-mode no
2525
ports:
2626
- 6380:6379
2727
profiles:
@@ -67,7 +67,7 @@ services:
6767
container_name: redis-sentinel
6868
depends_on:
6969
- redis
70-
entrypoint: "/usr/local/bin/redis-sentinel /redis.conf --port 26379"
70+
entrypoint: "redis-sentinel /redis.conf --port 26379"
7171
ports:
7272
- 26379:26379
7373
volumes:
@@ -81,7 +81,7 @@ services:
8181
container_name: redis-sentinel2
8282
depends_on:
8383
- redis
84-
entrypoint: "/usr/local/bin/redis-sentinel /redis.conf --port 26380"
84+
entrypoint: "redis-sentinel /redis.conf --port 26380"
8585
ports:
8686
- 26380:26380
8787
volumes:
@@ -95,7 +95,7 @@ services:
9595
container_name: redis-sentinel3
9696
depends_on:
9797
- redis
98-
entrypoint: "/usr/local/bin/redis-sentinel /redis.conf --port 26381"
98+
entrypoint: "redis-sentinel /redis.conf --port 26381"
9999
ports:
100100
- 26381:26381
101101
volumes:
@@ -114,3 +114,12 @@ services:
114114
profiles:
115115
- standalone
116116
- all
117+
118+
redis-stack-graph:
119+
image: redis/redis-stack-server:6.2.6-v15
120+
container_name: redis-stack-graph
121+
ports:
122+
- 6480:6379
123+
profiles:
124+
- standalone
125+
- all

dockers/create_cluster.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ dir /nodes/$PORT
3131
EOF
3232

3333
set -x
34-
/usr/local/bin/redis-server /nodes/$PORT/redis.conf
34+
redis-server /nodes/$PORT/redis.conf
3535
sleep 1
3636
if [ $? -ne 0 ]; then
3737
echo "Redis failed to start, exiting."
@@ -40,8 +40,8 @@ EOF
4040
echo 127.0.0.1:$PORT >> /nodes/nodemap
4141
done
4242
if [ -z "${REDIS_PASSWORD}" ]; then
43-
echo yes | /usr/local/bin/redis-cli --cluster create `seq -f 127.0.0.1:%g ${START_PORT} ${END_PORT}` --cluster-replicas 1
43+
echo yes | redis-cli --cluster create `seq -f 127.0.0.1:%g ${START_PORT} ${END_PORT}` --cluster-replicas 1
4444
else
45-
echo yes | /usr/local/bin/redis-cli -a ${REDIS_PASSWORD} --cluster create `seq -f 127.0.0.1:%g ${START_PORT} ${END_PORT}` --cluster-replicas 1
45+
echo yes | redis-cli -a ${REDIS_PASSWORD} --cluster create `seq -f 127.0.0.1:%g ${START_PORT} ${END_PORT}` --cluster-replicas 1
4646
fi
4747
tail -f /redis.log

tests/conftest.py

+7
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ def _get_info(redis_url):
121121
def pytest_sessionstart(session):
122122
# during test discovery, e.g. with VS Code, we may not
123123
# have a server running.
124+
protocol = session.config.getoption("--protocol")
125+
REDIS_INFO["resp_version"] = int(protocol) if protocol else None
124126
redis_url = session.config.getoption("--redis-url")
125127
try:
126128
info = _get_info(redis_url)
@@ -265,6 +267,11 @@ def skip_if_cryptography() -> _TestDecorator:
265267
return pytest.mark.skipif(False, reason="No cryptography dependency")
266268

267269

270+
def skip_if_resp_version(resp_version) -> _TestDecorator:
271+
check = REDIS_INFO.get("resp_version", None) == resp_version
272+
return pytest.mark.skipif(check, reason=f"RESP version required != {resp_version}")
273+
274+
268275
def _get_client(
269276
cls, request, single_connection_client=True, flushdb=True, from_url=None, **kwargs
270277
):

tests/test_asyncio/test_graph.py

+22-2
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@
44
from redis.commands.graph import Edge, Node, Path
55
from redis.commands.graph.execution_plan import Operation
66
from redis.exceptions import ResponseError
7-
from tests.conftest import skip_if_redis_enterprise
7+
from tests.conftest import skip_if_redis_enterprise, skip_if_resp_version
88

99

1010
@pytest_asyncio.fixture()
1111
async def decoded_r(create_redis, stack_url):
12-
return await create_redis(decode_responses=True, url=stack_url)
12+
return await create_redis(decode_responses=True, url="redis://localhost:6480")
1313

1414

1515
@pytest.mark.redismod
16+
@skip_if_resp_version(3)
1617
async def test_bulk(decoded_r):
1718
with pytest.raises(NotImplementedError):
1819
await decoded_r.graph().bulk()
1920
await decoded_r.graph().bulk(foo="bar!")
2021

2122

2223
@pytest.mark.redismod
24+
@skip_if_resp_version(3)
2325
async def test_graph_creation(decoded_r: redis.Redis):
2426
graph = decoded_r.graph()
2527

@@ -65,6 +67,7 @@ async def test_graph_creation(decoded_r: redis.Redis):
6567

6668

6769
@pytest.mark.redismod
70+
@skip_if_resp_version(3)
6871
async def test_array_functions(decoded_r: redis.Redis):
6972
graph = decoded_r.graph()
7073

@@ -88,6 +91,7 @@ async def test_array_functions(decoded_r: redis.Redis):
8891

8992

9093
@pytest.mark.redismod
94+
@skip_if_resp_version(3)
9195
async def test_path(decoded_r: redis.Redis):
9296
node0 = Node(node_id=0, label="L1")
9397
node1 = Node(node_id=1, label="L1")
@@ -108,6 +112,7 @@ async def test_path(decoded_r: redis.Redis):
108112

109113

110114
@pytest.mark.redismod
115+
@skip_if_resp_version(3)
111116
async def test_param(decoded_r: redis.Redis):
112117
params = [1, 2.3, "str", True, False, None, [0, 1, 2]]
113118
query = "RETURN $param"
@@ -118,6 +123,7 @@ async def test_param(decoded_r: redis.Redis):
118123

119124

120125
@pytest.mark.redismod
126+
@skip_if_resp_version(3)
121127
async def test_map(decoded_r: redis.Redis):
122128
query = "RETURN {a:1, b:'str', c:NULL, d:[1,2,3], e:True, f:{x:1, y:2}}"
123129

@@ -135,6 +141,7 @@ async def test_map(decoded_r: redis.Redis):
135141

136142

137143
@pytest.mark.redismod
144+
@skip_if_resp_version(3)
138145
async def test_point(decoded_r: redis.Redis):
139146
query = "RETURN point({latitude: 32.070794860, longitude: 34.820751118})"
140147
expected_lat = 32.070794860
@@ -152,6 +159,7 @@ async def test_point(decoded_r: redis.Redis):
152159

153160

154161
@pytest.mark.redismod
162+
@skip_if_resp_version(3)
155163
async def test_index_response(decoded_r: redis.Redis):
156164
result_set = await decoded_r.graph().query("CREATE INDEX ON :person(age)")
157165
assert 1 == result_set.indices_created
@@ -167,6 +175,7 @@ async def test_index_response(decoded_r: redis.Redis):
167175

168176

169177
@pytest.mark.redismod
178+
@skip_if_resp_version(3)
170179
async def test_stringify_query_result(decoded_r: redis.Redis):
171180
graph = decoded_r.graph()
172181

@@ -221,6 +230,7 @@ async def test_stringify_query_result(decoded_r: redis.Redis):
221230

222231

223232
@pytest.mark.redismod
233+
@skip_if_resp_version(3)
224234
async def test_optional_match(decoded_r: redis.Redis):
225235
# Build a graph of form (a)-[R]->(b)
226236
node0 = Node(node_id=0, label="L1", properties={"value": "a"})
@@ -246,6 +256,7 @@ async def test_optional_match(decoded_r: redis.Redis):
246256

247257

248258
@pytest.mark.redismod
259+
@skip_if_resp_version(3)
249260
async def test_cached_execution(decoded_r: redis.Redis):
250261
await decoded_r.graph().query("CREATE ()")
251262

@@ -266,6 +277,7 @@ async def test_cached_execution(decoded_r: redis.Redis):
266277

267278

268279
@pytest.mark.redismod
280+
@skip_if_resp_version(3)
269281
async def test_slowlog(decoded_r: redis.Redis):
270282
create_query = """CREATE
271283
(:Rider {name:'Valentino Rossi'})-[:rides]->(:Team {name:'Yamaha'}),
@@ -280,6 +292,7 @@ async def test_slowlog(decoded_r: redis.Redis):
280292

281293
@pytest.mark.xfail(strict=False)
282294
@pytest.mark.redismod
295+
@skip_if_resp_version(3)
283296
async def test_query_timeout(decoded_r: redis.Redis):
284297
# Build a sample graph with 1000 nodes.
285298
await decoded_r.graph().query("UNWIND range(0,1000) as val CREATE ({v: val})")
@@ -294,6 +307,7 @@ async def test_query_timeout(decoded_r: redis.Redis):
294307

295308

296309
@pytest.mark.redismod
310+
@skip_if_resp_version(3)
297311
async def test_read_only_query(decoded_r: redis.Redis):
298312
with pytest.raises(Exception):
299313
# Issue a write query, specifying read-only true,
@@ -303,6 +317,7 @@ async def test_read_only_query(decoded_r: redis.Redis):
303317

304318

305319
@pytest.mark.redismod
320+
@skip_if_resp_version(3)
306321
async def test_profile(decoded_r: redis.Redis):
307322
q = """UNWIND range(1, 3) AS x CREATE (p:Person {v:x})"""
308323
profile = (await decoded_r.graph().profile(q)).result_set
@@ -319,6 +334,7 @@ async def test_profile(decoded_r: redis.Redis):
319334

320335
@skip_if_redis_enterprise()
321336
@pytest.mark.redismod
337+
@skip_if_resp_version(3)
322338
async def test_config(decoded_r: redis.Redis):
323339
config_name = "RESULTSET_SIZE"
324340
config_value = 3
@@ -351,6 +367,7 @@ async def test_config(decoded_r: redis.Redis):
351367

352368
@pytest.mark.onlynoncluster
353369
@pytest.mark.redismod
370+
@skip_if_resp_version(3)
354371
async def test_list_keys(decoded_r: redis.Redis):
355372
result = await decoded_r.graph().list_keys()
356373
assert result == []
@@ -374,6 +391,7 @@ async def test_list_keys(decoded_r: redis.Redis):
374391

375392

376393
@pytest.mark.redismod
394+
@skip_if_resp_version(3)
377395
async def test_multi_label(decoded_r: redis.Redis):
378396
redis_graph = decoded_r.graph("g")
379397

@@ -400,6 +418,7 @@ async def test_multi_label(decoded_r: redis.Redis):
400418

401419

402420
@pytest.mark.redismod
421+
@skip_if_resp_version(3)
403422
async def test_execution_plan(decoded_r: redis.Redis):
404423
redis_graph = decoded_r.graph("execution_plan")
405424
create_query = """CREATE
@@ -419,6 +438,7 @@ async def test_execution_plan(decoded_r: redis.Redis):
419438

420439

421440
@pytest.mark.redismod
441+
@skip_if_resp_version(3)
422442
async def test_explain(decoded_r: redis.Redis):
423443
redis_graph = decoded_r.graph("execution_plan")
424444
# graph creation / population

tests/test_commands.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -712,11 +712,15 @@ def test_client_kill_filter_by_user(self, r, request):
712712
@skip_if_redis_enterprise()
713713
@pytest.mark.onlynoncluster
714714
def test_client_kill_filter_by_maxage(self, r, request):
715-
_get_client(redis.Redis, request, flushdb=False)
715+
r2 = _get_client(redis.Redis, request, flushdb=False)
716+
name = "target-foobar"
717+
r2.client_setname(name)
716718
time.sleep(4)
717-
assert len(r.client_list()) >= 2
719+
initial_clients = [c["name"] for c in r.client_list()]
720+
assert name in initial_clients
718721
r.client_kill_filter(maxage=2)
719-
assert len(r.client_list()) == 1
722+
final_clients = [c["name"] for c in r.client_list()]
723+
assert name not in final_clients
720724

721725
@pytest.mark.onlynoncluster
722726
@skip_if_server_version_lt("2.9.50")

0 commit comments

Comments
 (0)