diff --git a/channels/layers.py b/channels/layers.py index 20b91c43..1f418544 100644 --- a/channels/layers.py +++ b/channels/layers.py @@ -147,10 +147,13 @@ class BaseChannelLayer(ABC): MAX_NAME_LENGTH = 100 extensions: Iterable[str] = () + expiry: int + capacity: int + channel_capacity: Dict[str, int] def __init__( self, - expiry=60, + expiry: int = 60, capacity: Optional[int] = 100, channel_capacity: Optional[int] = None, ): @@ -263,7 +266,12 @@ async def new_channel(self, prefix: str = "specific.") -> str: """ -class InMemoryChannelLayer(WithFlushExtension, WithGroupsExtension, BaseChannelLayer): +# WARNING: Protocols must be last +class InMemoryChannelLayer( + BaseChannelLayer, + WithFlushExtension, + WithGroupsExtension, +): """ In-memory channel layer implementation """ diff --git a/tests/test_layers.py b/tests/test_layers.py index 543a9f19..3ebbc287 100644 --- a/tests/test_layers.py +++ b/tests/test_layers.py @@ -13,6 +13,18 @@ ) +# when starting with Test it would be tried to collect by pytest +class StubChannelLayer(BaseChannelLayer): + async def send(self, channel: str, message: dict): + raise NotImplementedError() + + async def receive(self, channel: str) -> dict: + raise NotImplementedError() + + async def new_channel(self, prefix: str = "specific.") -> str: + raise NotImplementedError() + + class TestChannelLayerManager(unittest.TestCase): @override_settings( CHANNEL_LAYERS={"default": {"BACKEND": "channels.layers.InMemoryChannelLayer"}} @@ -72,7 +84,7 @@ async def test_send_receive(): @pytest.mark.parametrize( "method", - [BaseChannelLayer().valid_channel_name, BaseChannelLayer().valid_group_name], + [StubChannelLayer().valid_channel_name, StubChannelLayer().valid_group_name], ) @pytest.mark.parametrize( "channel_name,expected_valid",