@@ -299,9 +299,10 @@ async def test_groups_multiple_hosts_performance(
299
299
300
300
301
301
@pytest .mark .asyncio
302
- async def test_group_send_capacity (channel_layer ):
302
+ async def test_group_send_capacity (channel_layer , caplog ):
303
303
"""
304
- Makes sure we dont send messages to groups that are over capacity
304
+ Makes sure we dont group_send messages to channels that are over capacity.
305
+ Make sure number of channels with full capacity are logged as an exception to help debug errors.
305
306
"""
306
307
307
308
channel = await channel_layer .new_channel ()
@@ -312,16 +313,61 @@ async def test_group_send_capacity(channel_layer):
312
313
await channel_layer .group_send ("test-group" , {"type" : "message.3" })
313
314
await channel_layer .group_send ("test-group" , {"type" : "message.4" })
314
315
315
- # We should recieve the first 3 messages
316
+ # We should receive the first 3 messages
316
317
assert (await channel_layer .receive (channel ))["type" ] == "message.1"
317
318
assert (await channel_layer .receive (channel ))["type" ] == "message.2"
318
319
assert (await channel_layer .receive (channel ))["type" ] == "message.3"
319
320
320
- # Make sure we do NOT recieve message 4
321
+ # Make sure we do NOT receive message 4
321
322
with pytest .raises (asyncio .TimeoutError ):
322
323
async with async_timeout .timeout (1 ):
323
324
await channel_layer .receive (channel )
324
325
326
+ # Make sure number of channels over capacity are logged
327
+ for record in caplog .records :
328
+ assert record .levelname == "ERROR"
329
+ assert record .msg == "1 of 1 channels over capacity in group test-group"
330
+
331
+
332
+ @pytest .mark .asyncio
333
+ async def test_group_send_capacity_multiple_channels (channel_layer , caplog ):
334
+ """
335
+ Makes sure we dont group_send messages to channels that are over capacity
336
+ Make sure number of channels with full capacity are logged as an exception to help debug errors.
337
+ """
338
+
339
+ channel_1 = await channel_layer .new_channel ()
340
+ channel_2 = await channel_layer .new_channel (prefix = "channel_2" )
341
+ await channel_layer .group_add ("test-group" , channel_1 )
342
+ await channel_layer .group_add ("test-group" , channel_2 )
343
+
344
+ # Let's put channel_2 over capacity
345
+ await channel_layer .send (channel_2 , {"type" : "message.0" })
346
+
347
+ await channel_layer .group_send ("test-group" , {"type" : "message.1" })
348
+ await channel_layer .group_send ("test-group" , {"type" : "message.2" })
349
+ await channel_layer .group_send ("test-group" , {"type" : "message.3" })
350
+
351
+ # Channel_1 should receive all 3 group messages
352
+ assert (await channel_layer .receive (channel_1 ))["type" ] == "message.1"
353
+ assert (await channel_layer .receive (channel_1 ))["type" ] == "message.2"
354
+ assert (await channel_layer .receive (channel_1 ))["type" ] == "message.3"
355
+
356
+ # Channel_2 should receive the first message + 2 group messages
357
+ assert (await channel_layer .receive (channel_2 ))["type" ] == "message.0"
358
+ assert (await channel_layer .receive (channel_2 ))["type" ] == "message.1"
359
+ assert (await channel_layer .receive (channel_2 ))["type" ] == "message.2"
360
+
361
+ # Make sure channel_2 does not receive the 3rd group message
362
+ with pytest .raises (asyncio .TimeoutError ):
363
+ async with async_timeout .timeout (1 ):
364
+ await channel_layer .receive (channel_2 )
365
+
366
+ # Make sure number of channels over capacity are logged
367
+ for record in caplog .records :
368
+ assert record .levelname == "ERROR"
369
+ assert record .msg == "1 of 2 channels over capacity in group test-group"
370
+
325
371
326
372
@pytest .mark .asyncio
327
373
async def test_connection_pool_pop ():
0 commit comments