5
5
import pytest
6
6
7
7
from asgiref .sync import async_to_sync
8
- from channels_valkey .core import ChannelFull , RedisChannelLayer
8
+ from channels_valkey .core import ChannelFull , ValkeyChannelLayer
9
9
10
- TEST_HOSTS = ["redis ://localhost:6379" ]
10
+ TEST_HOSTS = ["valkey ://localhost:6379" ]
11
11
12
12
MULTIPLE_TEST_HOSTS = [
13
- "redis ://localhost:6379/0" ,
14
- "redis ://localhost:6379/1" ,
15
- "redis ://localhost:6379/2" ,
16
- "redis ://localhost:6379/3" ,
17
- "redis ://localhost:6379/4" ,
18
- "redis ://localhost:6379/5" ,
19
- "redis ://localhost:6379/6" ,
20
- "redis ://localhost:6379/7" ,
21
- "redis ://localhost:6379/8" ,
22
- "redis ://localhost:6379/9" ,
13
+ "valkey ://localhost:6379/0" ,
14
+ "valkey ://localhost:6379/1" ,
15
+ "valkey ://localhost:6379/2" ,
16
+ "valkey ://localhost:6379/3" ,
17
+ "valkey ://localhost:6379/4" ,
18
+ "valkey ://localhost:6379/5" ,
19
+ "valkey ://localhost:6379/6" ,
20
+ "valkey ://localhost:6379/7" ,
21
+ "valkey ://localhost:6379/8" ,
22
+ "valkey ://localhost:6379/9" ,
23
23
]
24
24
25
25
@@ -58,7 +58,7 @@ async def channel_layer():
58
58
"""
59
59
Channel layer fixture that flushes automatically.
60
60
"""
61
- channel_layer = RedisChannelLayer (
61
+ channel_layer = ValkeyChannelLayer (
62
62
hosts = TEST_HOSTS , capacity = 3 , channel_capacity = {"tiny" : 1 }
63
63
)
64
64
yield channel_layer
@@ -70,7 +70,7 @@ async def channel_layer_multiple_hosts():
70
70
"""
71
71
Channel layer fixture that flushes automatically.
72
72
"""
73
- channel_layer = RedisChannelLayer (hosts = MULTIPLE_TEST_HOSTS , capacity = 3 )
73
+ channel_layer = ValkeyChannelLayer (hosts = MULTIPLE_TEST_HOSTS , capacity = 3 )
74
74
yield channel_layer
75
75
await channel_layer .flush ()
76
76
@@ -94,9 +94,9 @@ def test_double_receive(channel_layer):
94
94
Makes sure we can receive from two different event loops using
95
95
process-local channel names.
96
96
"""
97
- channel_layer = RedisChannelLayer (hosts = TEST_HOSTS , capacity = 3 )
97
+ channel_layer = ValkeyChannelLayer (hosts = TEST_HOSTS , capacity = 3 )
98
98
99
- # Aioredis connections can't be used from different event loops, so
99
+ # Aiovalkey connections can't be used from different event loops, so
100
100
# send and close need to be done in the same async_to_sync call.
101
101
async def send_and_close (* args , ** kwargs ):
102
102
await channel_layer .send (* args , ** kwargs )
@@ -142,7 +142,7 @@ async def test_send_specific_capacity(channel_layer):
142
142
"""
143
143
Makes sure we get ChannelFull when we hit the send capacity on a specific channel
144
144
"""
145
- custom_channel_layer = RedisChannelLayer (
145
+ custom_channel_layer = ValkeyChannelLayer (
146
146
hosts = TEST_HOSTS , capacity = 3 , channel_capacity = {"one" : 1 }
147
147
)
148
148
await custom_channel_layer .send ("one" , {"type" : "test.message" })
@@ -170,7 +170,7 @@ async def test_multi_send_receive(channel_layer):
170
170
"""
171
171
Tests overlapping sends and receives, and ordering.
172
172
"""
173
- channel_layer = RedisChannelLayer (hosts = TEST_HOSTS )
173
+ channel_layer = ValkeyChannelLayer (hosts = TEST_HOSTS )
174
174
await channel_layer .send ("test-channel-3" , {"type" : "message.1" })
175
175
await channel_layer .send ("test-channel-3" , {"type" : "message.2" })
176
176
await channel_layer .send ("test-channel-3" , {"type" : "message.3" })
@@ -205,7 +205,7 @@ async def test_groups_basic(channel_layer):
205
205
"""
206
206
Tests basic group operation.
207
207
"""
208
- channel_layer = RedisChannelLayer (hosts = TEST_HOSTS )
208
+ channel_layer = ValkeyChannelLayer (hosts = TEST_HOSTS )
209
209
channel_name1 = await channel_layer .new_channel (prefix = "test-gr-chan-1" )
210
210
channel_name2 = await channel_layer .new_channel (prefix = "test-gr-chan-2" )
211
211
channel_name3 = await channel_layer .new_channel (prefix = "test-gr-chan-3" )
@@ -230,7 +230,7 @@ async def test_groups_channel_full(channel_layer):
230
230
"""
231
231
Tests that group_send ignores ChannelFull
232
232
"""
233
- channel_layer = RedisChannelLayer (hosts = TEST_HOSTS )
233
+ channel_layer = ValkeyChannelLayer (hosts = TEST_HOSTS )
234
234
await channel_layer .group_add ("test-group" , "test-gr-chan-1" )
235
235
await channel_layer .group_send ("test-group" , {"type" : "message.1" })
236
236
await channel_layer .group_send ("test-group" , {"type" : "message.1" })
@@ -245,7 +245,7 @@ async def test_groups_multiple_hosts(channel_layer_multiple_hosts):
245
245
"""
246
246
Tests advanced group operation with multiple hosts.
247
247
"""
248
- channel_layer = RedisChannelLayer (hosts = MULTIPLE_TEST_HOSTS , capacity = 100 )
248
+ channel_layer = ValkeyChannelLayer (hosts = MULTIPLE_TEST_HOSTS , capacity = 100 )
249
249
channel_name1 = await channel_layer .new_channel (prefix = "channel1" )
250
250
channel_name2 = await channel_layer .new_channel (prefix = "channel2" )
251
251
channel_name3 = await channel_layer .new_channel (prefix = "channel3" )
@@ -273,7 +273,7 @@ async def test_groups_same_prefix(channel_layer):
273
273
"""
274
274
Tests group_send with multiple channels with same channel prefix
275
275
"""
276
- channel_layer = RedisChannelLayer (hosts = TEST_HOSTS )
276
+ channel_layer = ValkeyChannelLayer (hosts = TEST_HOSTS )
277
277
channel_name1 = await channel_layer .new_channel (prefix = "test-gr-chan" )
278
278
channel_name2 = await channel_layer .new_channel (prefix = "test-gr-chan" )
279
279
channel_name3 = await channel_layer .new_channel (prefix = "test-gr-chan" )
@@ -307,7 +307,7 @@ async def test_groups_multiple_hosts_performance(
307
307
Tests advanced group operation: can send efficiently to multiple channels
308
308
with multiple hosts within a certain timeout
309
309
"""
310
- channel_layer = RedisChannelLayer (hosts = MULTIPLE_TEST_HOSTS , capacity = 100 )
310
+ channel_layer = ValkeyChannelLayer (hosts = MULTIPLE_TEST_HOSTS , capacity = 100 )
311
311
312
312
channels = []
313
313
for i in range (0 , num_channels ):
@@ -406,7 +406,7 @@ def test_repeated_group_send_with_async_to_sync(channel_layer):
406
406
Makes sure repeated group_send calls wrapped in async_to_sync
407
407
process-local channel names.
408
408
"""
409
- channel_layer = RedisChannelLayer (hosts = TEST_HOSTS , capacity = 3 )
409
+ channel_layer = ValkeyChannelLayer (hosts = TEST_HOSTS , capacity = 3 )
410
410
411
411
try :
412
412
async_to_sync (channel_layer .group_send )(
@@ -421,7 +421,7 @@ def test_repeated_group_send_with_async_to_sync(channel_layer):
421
421
422
422
@pytest .mark .xfail (
423
423
reason = """
424
- Fails with error in redis -py: int() argument must be a string, a bytes-like
424
+ Fails with error in valkey -py: int() argument must be a string, a bytes-like
425
425
object or a real number, not 'NoneType'. Refs: #348
426
426
"""
427
427
)
@@ -430,7 +430,7 @@ async def test_receive_cancel(channel_layer):
430
430
"""
431
431
Makes sure we can cancel a receive without blocking
432
432
"""
433
- channel_layer = RedisChannelLayer (capacity = 30 )
433
+ channel_layer = ValkeyChannelLayer (capacity = 30 )
434
434
channel = await channel_layer .new_channel ()
435
435
delay = 0
436
436
while delay < 0.01 :
@@ -453,7 +453,7 @@ async def test_random_reset__channel_name(channel_layer):
453
453
Makes sure resetting random seed does not make us reuse channel names.
454
454
"""
455
455
456
- channel_layer = RedisChannelLayer ()
456
+ channel_layer = ValkeyChannelLayer ()
457
457
random .seed (1 )
458
458
channel_name_1 = await channel_layer .new_channel ()
459
459
random .seed (1 )
@@ -469,17 +469,17 @@ async def test_random_reset__client_prefix(channel_layer):
469
469
"""
470
470
471
471
random .seed (1 )
472
- channel_layer_1 = RedisChannelLayer ()
472
+ channel_layer_1 = ValkeyChannelLayer ()
473
473
random .seed (1 )
474
- channel_layer_2 = RedisChannelLayer ()
474
+ channel_layer_2 = ValkeyChannelLayer ()
475
475
assert channel_layer_1 .client_prefix != channel_layer_2 .client_prefix
476
476
477
477
478
478
@pytest .mark .asyncio
479
479
async def test_message_expiry__earliest_message_expires (channel_layer ):
480
480
expiry = 3
481
481
delay = 2
482
- channel_layer = RedisChannelLayer (expiry = expiry )
482
+ channel_layer = ValkeyChannelLayer (expiry = expiry )
483
483
channel_name = await channel_layer .new_channel ()
484
484
485
485
task = asyncio .ensure_future (
@@ -506,7 +506,7 @@ async def test_message_expiry__earliest_message_expires(channel_layer):
506
506
async def test_message_expiry__all_messages_under_expiration_time (channel_layer ):
507
507
expiry = 3
508
508
delay = 1
509
- channel_layer = RedisChannelLayer (expiry = expiry )
509
+ channel_layer = ValkeyChannelLayer (expiry = expiry )
510
510
channel_name = await channel_layer .new_channel ()
511
511
512
512
task = asyncio .ensure_future (
@@ -532,7 +532,7 @@ async def test_message_expiry__all_messages_under_expiration_time(channel_layer)
532
532
async def test_message_expiry__group_send (channel_layer ):
533
533
expiry = 3
534
534
delay = 2
535
- channel_layer = RedisChannelLayer (expiry = expiry )
535
+ channel_layer = ValkeyChannelLayer (expiry = expiry )
536
536
channel_name = await channel_layer .new_channel ()
537
537
538
538
await channel_layer .group_add ("test-group" , channel_name )
@@ -563,7 +563,7 @@ async def test_message_expiry__group_send__one_channel_expires_message(channel_l
563
563
expiry = 3
564
564
delay = 1
565
565
566
- channel_layer = RedisChannelLayer (expiry = expiry )
566
+ channel_layer = ValkeyChannelLayer (expiry = expiry )
567
567
channel_1 = await channel_layer .new_channel ()
568
568
channel_2 = await channel_layer .new_channel (prefix = "channel_2" )
569
569
@@ -613,19 +613,19 @@ async def test_message_expiry__group_send__one_channel_expires_message(channel_l
613
613
614
614
615
615
def test_default_group_key_format ():
616
- channel_layer = RedisChannelLayer ()
616
+ channel_layer = ValkeyChannelLayer ()
617
617
group_name = channel_layer ._group_key ("test_group" )
618
618
assert group_name == b"asgi:group:test_group"
619
619
620
620
621
621
def test_custom_group_key_format ():
622
- channel_layer = RedisChannelLayer (prefix = "test_prefix" )
622
+ channel_layer = ValkeyChannelLayer (prefix = "test_prefix" )
623
623
group_name = channel_layer ._group_key ("test_group" )
624
624
assert group_name == b"test_prefix:group:test_group"
625
625
626
626
627
627
def test_receive_buffer_respects_capacity ():
628
- channel_layer = RedisChannelLayer ()
628
+ channel_layer = ValkeyChannelLayer ()
629
629
buff = channel_layer .receive_buffer ["test-group" ]
630
630
for i in range (10000 ):
631
631
buff .put_nowait (i )
@@ -643,7 +643,7 @@ def test_serialize():
643
643
Test default serialization method
644
644
"""
645
645
message = {"a" : True , "b" : None , "c" : {"d" : []}}
646
- channel_layer = RedisChannelLayer ()
646
+ channel_layer = ValkeyChannelLayer ()
647
647
serialized = channel_layer .serialize (message )
648
648
assert isinstance (serialized , bytes )
649
649
assert serialized [12 :] == b"\x83 \xa1 a\xc3 \xa1 b\xc0 \xa1 c\x81 \xa1 d\x90 "
@@ -654,7 +654,7 @@ def test_deserialize():
654
654
Test default deserialization method
655
655
"""
656
656
message = b"Q\x0c \xbb ?Q\xbc \xe3 |D\xfd 9\x00 \x83 \xa1 a\xc3 \xa1 b\xc0 \xa1 c\x81 \xa1 d\x90 "
657
- channel_layer = RedisChannelLayer ()
657
+ channel_layer = ValkeyChannelLayer ()
658
658
deserialized = channel_layer .deserialize (message )
659
659
660
660
assert isinstance (deserialized , dict )
0 commit comments