Skip to content

Commit 66bad8e

Browse files
dvora-hchayim
andauthored
Add sync modules (except search) tests to cluster CI (#2850)
* Add modules to cluster ci * remove async tests * fix protocol checking * fix tests * revert cluster docker change * skip json 2.6.0 tests * remove breakpoint * skip test_get_latest * skip json.mset * type hint * revert type hints * ilnters --------- Co-authored-by: Chayim <chayim@users.noreply.github.com>
1 parent 7d70c91 commit 66bad8e

File tree

10 files changed

+32
-155
lines changed

10 files changed

+32
-155
lines changed

redis/commands/bf/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from redis._parsers.helpers import bool_ok
22

3-
from ..helpers import parse_to_list
3+
from ..helpers import get_protocol_version, parse_to_list
44
from .commands import * # noqa
55
from .info import BFInfo, CFInfo, CMSInfo, TDigestInfo, TopKInfo
66

@@ -108,7 +108,7 @@ def __init__(self, client, **kwargs):
108108
self.commandmixin = CMSCommands
109109
self.execute_command = client.execute_command
110110

111-
if self.client.connection_pool.connection_kwargs.get("protocol") in ["3", 3]:
111+
if get_protocol_version(self.client) in ["3", 3]:
112112
_MODULE_CALLBACKS.update(_RESP3_MODULE_CALLBACKS)
113113
else:
114114
_MODULE_CALLBACKS.update(_RESP2_MODULE_CALLBACKS)
@@ -139,7 +139,7 @@ def __init__(self, client, **kwargs):
139139
self.commandmixin = TOPKCommands
140140
self.execute_command = client.execute_command
141141

142-
if self.client.connection_pool.connection_kwargs.get("protocol") in ["3", 3]:
142+
if get_protocol_version(self.client) in ["3", 3]:
143143
_MODULE_CALLBACKS.update(_RESP3_MODULE_CALLBACKS)
144144
else:
145145
_MODULE_CALLBACKS.update(_RESP2_MODULE_CALLBACKS)
@@ -174,7 +174,7 @@ def __init__(self, client, **kwargs):
174174
self.commandmixin = CFCommands
175175
self.execute_command = client.execute_command
176176

177-
if self.client.connection_pool.connection_kwargs.get("protocol") in ["3", 3]:
177+
if get_protocol_version(self.client) in ["3", 3]:
178178
_MODULE_CALLBACKS.update(_RESP3_MODULE_CALLBACKS)
179179
else:
180180
_MODULE_CALLBACKS.update(_RESP2_MODULE_CALLBACKS)
@@ -210,7 +210,7 @@ def __init__(self, client, **kwargs):
210210
self.commandmixin = TDigestCommands
211211
self.execute_command = client.execute_command
212212

213-
if self.client.connection_pool.connection_kwargs.get("protocol") in ["3", 3]:
213+
if get_protocol_version(self.client) in ["3", 3]:
214214
_MODULE_CALLBACKS.update(_RESP3_MODULE_CALLBACKS)
215215
else:
216216
_MODULE_CALLBACKS.update(_RESP2_MODULE_CALLBACKS)
@@ -244,7 +244,7 @@ def __init__(self, client, **kwargs):
244244
self.commandmixin = BFCommands
245245
self.execute_command = client.execute_command
246246

247-
if self.client.connection_pool.connection_kwargs.get("protocol") in ["3", 3]:
247+
if get_protocol_version(self.client) in ["3", 3]:
248248
_MODULE_CALLBACKS.update(_RESP3_MODULE_CALLBACKS)
249249
else:
250250
_MODULE_CALLBACKS.update(_RESP2_MODULE_CALLBACKS)

redis/commands/helpers.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import string
44
from typing import List, Tuple
55

6+
import redis
67
from redis.typing import KeysT, KeyT
78

89

@@ -156,3 +157,10 @@ def stringify_param_value(value):
156157
return f'{{{",".join(f"{k}:{stringify_param_value(v)}" for k, v in value.items())}}}' # noqa
157158
else:
158159
return str(value)
160+
161+
162+
def get_protocol_version(client):
163+
if isinstance(client, redis.Redis) or isinstance(client, redis.asyncio.Redis):
164+
return client.connection_pool.connection_kwargs.get("protocol")
165+
elif isinstance(client, redis.cluster.AbstractRedisCluster):
166+
return client.nodes_manager.connection_kwargs.get("protocol")

redis/commands/json/__init__.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import redis
44

5-
from ..helpers import nativestr
5+
from ..helpers import get_protocol_version, nativestr
66
from .commands import JSONCommands
77
from .decoders import bulk_of_jsons, decode_list
88

@@ -34,6 +34,7 @@ def __init__(
3434
self._MODULE_CALLBACKS = {
3535
"JSON.ARRPOP": self._decode,
3636
"JSON.DEBUG": self._decode,
37+
"JSON.GET": self._decode,
3738
"JSON.MERGE": lambda r: r and nativestr(r) == "OK",
3839
"JSON.MGET": bulk_of_jsons(self._decode),
3940
"JSON.MSET": lambda r: r and nativestr(r) == "OK",
@@ -61,19 +62,13 @@ def __init__(
6162
"JSON.TOGGLE": self._decode,
6263
}
6364

64-
_RESP3_MODULE_CALLBACKS = {
65-
"JSON.GET": lambda response: [
66-
[self._decode(r) for r in res] for res in response
67-
]
68-
if response
69-
else response
70-
}
65+
_RESP3_MODULE_CALLBACKS = {}
7166

7267
self.client = client
7368
self.execute_command = client.execute_command
7469
self.MODULE_VERSION = version
7570

76-
if self.client.connection_pool.connection_kwargs.get("protocol") in ["3", 3]:
71+
if get_protocol_version(self.client) in ["3", 3]:
7772
self._MODULE_CALLBACKS.update(_RESP3_MODULE_CALLBACKS)
7873
else:
7974
self._MODULE_CALLBACKS.update(_RESP2_MODULE_CALLBACKS)

redis/commands/timeseries/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import redis
22
from redis._parsers.helpers import bool_ok
33

4-
from ..helpers import parse_to_list
4+
from ..helpers import get_protocol_version, parse_to_list
55
from .commands import (
66
ALTER_CMD,
77
CREATE_CMD,
@@ -56,7 +56,7 @@ def __init__(self, client=None, **kwargs):
5656
self.client = client
5757
self.execute_command = client.execute_command
5858

59-
if self.client.connection_pool.connection_kwargs.get("protocol") in ["3", 3]:
59+
if get_protocol_version(self.client) in ["3", 3]:
6060
self._MODULE_CALLBACKS.update(_RESP3_MODULE_CALLBACKS)
6161
else:
6262
self._MODULE_CALLBACKS.update(_RESP2_MODULE_CALLBACKS)

tests/test_asyncio/test_bloom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ async def test_tdigest_reset(decoded_r: redis.Redis):
365365

366366

367367
@pytest.mark.redismod
368-
@pytest.mark.experimental
368+
@pytest.mark.onlynoncluster
369369
async def test_tdigest_merge(decoded_r: redis.Redis):
370370
assert await decoded_r.tdigest().create("to-tDigest", 10)
371371
assert await decoded_r.tdigest().create("from-tDigest", 10)

tests/test_asyncio/test_json.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ async def test_mgetshouldsucceed(decoded_r: redis.Redis):
112112

113113

114114
@pytest.mark.redismod
115+
@pytest.mark.onlynoncluster
115116
@skip_ifmodversion_lt("2.6.0", "ReJSON")
116117
async def test_mset(decoded_r: redis.Redis):
117118
await decoded_r.json().mset(

tests/test_bloom.py

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ def client(decoded_r):
2424
return decoded_r
2525

2626

27-
@pytest.mark.redismod
2827
def test_create(client):
2928
"""Test CREATE/RESERVE calls"""
3029
assert client.bf().create("bloom", 0.01, 1000)
@@ -39,7 +38,6 @@ def test_create(client):
3938
assert client.topk().reserve("topk", 5, 100, 5, 0.9)
4039

4140

42-
@pytest.mark.redismod
4341
def test_bf_reserve(client):
4442
"""Testing BF.RESERVE"""
4543
assert client.bf().reserve("bloom", 0.01, 1000)
@@ -54,13 +52,11 @@ def test_bf_reserve(client):
5452
assert client.topk().reserve("topk", 5, 100, 5, 0.9)
5553

5654

57-
@pytest.mark.redismod
5855
@pytest.mark.experimental
5956
def test_tdigest_create(client):
6057
assert client.tdigest().create("tDigest", 100)
6158

6259

63-
@pytest.mark.redismod
6460
def test_bf_add(client):
6561
assert client.bf().create("bloom", 0.01, 1000)
6662
assert 1 == client.bf().add("bloom", "foo")
@@ -73,7 +69,6 @@ def test_bf_add(client):
7369
assert [1, 0] == intlist(client.bf().mexists("bloom", "foo", "noexist"))
7470

7571

76-
@pytest.mark.redismod
7772
def test_bf_insert(client):
7873
assert client.bf().create("bloom", 0.01, 1000)
7974
assert [1] == intlist(client.bf().insert("bloom", ["foo"]))
@@ -104,7 +99,6 @@ def test_bf_insert(client):
10499
)
105100

106101

107-
@pytest.mark.redismod
108102
def test_bf_scandump_and_loadchunk(client):
109103
# Store a filter
110104
client.bf().create("myBloom", "0.0001", "1000")
@@ -156,7 +150,6 @@ def do_verify():
156150
client.bf().create("myBloom", "0.0001", "10000000")
157151

158152

159-
@pytest.mark.redismod
160153
def test_bf_info(client):
161154
expansion = 4
162155
# Store a filter
@@ -188,7 +181,6 @@ def test_bf_info(client):
188181
assert True
189182

190183

191-
@pytest.mark.redismod
192184
def test_bf_card(client):
193185
# return 0 if the key does not exist
194186
assert client.bf().card("not_exist") == 0
@@ -203,7 +195,6 @@ def test_bf_card(client):
203195
client.bf().card("setKey")
204196

205197

206-
@pytest.mark.redismod
207198
def test_cf_add_and_insert(client):
208199
assert client.cf().create("cuckoo", 1000)
209200
assert client.cf().add("cuckoo", "filter")
@@ -229,7 +220,6 @@ def test_cf_add_and_insert(client):
229220
)
230221

231222

232-
@pytest.mark.redismod
233223
def test_cf_exists_and_del(client):
234224
assert client.cf().create("cuckoo", 1000)
235225
assert client.cf().add("cuckoo", "filter")
@@ -242,7 +232,6 @@ def test_cf_exists_and_del(client):
242232
assert 0 == client.cf().count("cuckoo", "filter")
243233

244234

245-
@pytest.mark.redismod
246235
def test_cms(client):
247236
assert client.cms().initbydim("dim", 1000, 5)
248237
assert client.cms().initbyprob("prob", 0.01, 0.01)
@@ -258,7 +247,6 @@ def test_cms(client):
258247
assert 25 == info["count"]
259248

260249

261-
@pytest.mark.redismod
262250
@pytest.mark.onlynoncluster
263251
def test_cms_merge(client):
264252
assert client.cms().initbydim("A", 1000, 5)
@@ -276,7 +264,6 @@ def test_cms_merge(client):
276264
assert [16, 15, 21] == client.cms().query("C", "foo", "bar", "baz")
277265

278266

279-
@pytest.mark.redismod
280267
def test_topk(client):
281268
# test list with empty buckets
282269
assert client.topk().reserve("topk", 3, 50, 4, 0.9)
@@ -356,7 +343,6 @@ def test_topk(client):
356343
assert 0.9 == round(float(info["decay"]), 1)
357344

358345

359-
@pytest.mark.redismod
360346
def test_topk_incrby(client):
361347
client.flushdb()
362348
assert client.topk().reserve("topk", 3, 10, 3, 1)
@@ -370,7 +356,6 @@ def test_topk_incrby(client):
370356
)
371357

372358

373-
@pytest.mark.redismod
374359
@pytest.mark.experimental
375360
def test_tdigest_reset(client):
376361
assert client.tdigest().create("tDigest", 10)
@@ -387,8 +372,7 @@ def test_tdigest_reset(client):
387372
)
388373

389374

390-
@pytest.mark.redismod
391-
@pytest.mark.experimental
375+
@pytest.mark.onlynoncluster
392376
def test_tdigest_merge(client):
393377
assert client.tdigest().create("to-tDigest", 10)
394378
assert client.tdigest().create("from-tDigest", 10)
@@ -415,7 +399,6 @@ def test_tdigest_merge(client):
415399
assert 4.0 == client.tdigest().max("to-tDigest")
416400

417401

418-
@pytest.mark.redismod
419402
@pytest.mark.experimental
420403
def test_tdigest_min_and_max(client):
421404
assert client.tdigest().create("tDigest", 100)
@@ -426,7 +409,6 @@ def test_tdigest_min_and_max(client):
426409
assert 1 == client.tdigest().min("tDigest")
427410

428411

429-
@pytest.mark.redismod
430412
@pytest.mark.experimental
431413
@skip_ifmodversion_lt("2.4.0", "bf")
432414
def test_tdigest_quantile(client):
@@ -448,7 +430,6 @@ def test_tdigest_quantile(client):
448430
assert [3.0, 5.0] == client.tdigest().quantile("t-digest", 0.5, 0.8)
449431

450432

451-
@pytest.mark.redismod
452433
@pytest.mark.experimental
453434
def test_tdigest_cdf(client):
454435
assert client.tdigest().create("tDigest", 100)
@@ -460,7 +441,6 @@ def test_tdigest_cdf(client):
460441
assert [0.1, 0.9] == [round(x, 1) for x in res]
461442

462443

463-
@pytest.mark.redismod
464444
@pytest.mark.experimental
465445
@skip_ifmodversion_lt("2.4.0", "bf")
466446
def test_tdigest_trimmed_mean(client):
@@ -471,7 +451,6 @@ def test_tdigest_trimmed_mean(client):
471451
assert 4.5 == client.tdigest().trimmed_mean("tDigest", 0.4, 0.5)
472452

473453

474-
@pytest.mark.redismod
475454
@pytest.mark.experimental
476455
def test_tdigest_rank(client):
477456
assert client.tdigest().create("t-digest", 500)
@@ -482,7 +461,6 @@ def test_tdigest_rank(client):
482461
assert [-1, 20, 9] == client.tdigest().rank("t-digest", -20, 20, 9)
483462

484463

485-
@pytest.mark.redismod
486464
@pytest.mark.experimental
487465
def test_tdigest_revrank(client):
488466
assert client.tdigest().create("t-digest", 500)
@@ -492,7 +470,6 @@ def test_tdigest_revrank(client):
492470
assert [-1, 19, 9] == client.tdigest().revrank("t-digest", 21, 0, 10)
493471

494472

495-
@pytest.mark.redismod
496473
@pytest.mark.experimental
497474
def test_tdigest_byrank(client):
498475
assert client.tdigest().create("t-digest", 500)
@@ -504,7 +481,6 @@ def test_tdigest_byrank(client):
504481
client.tdigest().byrank("t-digest", -1)[0]
505482

506483

507-
@pytest.mark.redismod
508484
@pytest.mark.experimental
509485
def test_tdigest_byrevrank(client):
510486
assert client.tdigest().create("t-digest", 500)
@@ -516,8 +492,7 @@ def test_tdigest_byrevrank(client):
516492
client.tdigest().byrevrank("t-digest", -1)[0]
517493

518494

519-
# @pytest.mark.redismod
520-
# def test_pipeline(client):
495+
# # def test_pipeline(client):
521496
# pipeline = client.bf().pipeline()
522497
# assert not client.bf().execute_command("get pipeline")
523498
#

0 commit comments

Comments
 (0)