Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion channels/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class BaseChannelLayer:
def __init__(self, expiry=60, capacity=100, channel_capacity=None):
self.expiry = expiry
self.capacity = capacity
self.channel_capacity = channel_capacity or {}
self.channel_capacity = self.compile_capacities(channel_capacity or {})

def compile_capacities(self, channel_capacity):
"""
Expand Down
19 changes: 19 additions & 0 deletions tests/test_inmemorychannel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import re

import async_timeout
import pytest
Expand Down Expand Up @@ -70,6 +71,24 @@ async def test_send_capacity(channel_layer):
await channel_layer.send("test-channel-1", {"type": "test.message"})


@pytest.mark.asyncio
async def test_send_channel_capacity():
"""
Makes sure channel_capacity patterns override the default capacity
"""
channel_layer = InMemoryChannelLayer(
capacity=3, channel_capacity={"small-*": 1, re.compile(r"^big-"): 5}
)
assert channel_layer.get_capacity("small-channel") == 1
assert channel_layer.get_capacity("big-channel") == 5
assert channel_layer.get_capacity("other-channel") == 3
await channel_layer.send("small-channel", {"type": "test.message"})
with pytest.raises(ChannelFull):
await channel_layer.send("small-channel", {"type": "test.message"})
await channel_layer.flush()
await channel_layer.close()


@pytest.mark.asyncio
async def test_process_local_send_receive(channel_layer):
"""
Expand Down