@@ -58,6 +58,7 @@ groups() ->
58
58
set_disk_free_limit_command ,
59
59
set_vm_memory_high_watermark_command ,
60
60
topic_matching ,
61
+ max_message_size ,
61
62
{queue_max_length , [], [
62
63
{max_length_simple , [], MaxLengthTests },
63
64
{max_length_mirrored , [], MaxLengthTests }]}
@@ -1299,6 +1300,84 @@ sync_mirrors(QName, Config) ->
1299
1300
_ -> ok
1300
1301
end .
1301
1302
1303
+ gen_binary_mb (N ) ->
1304
+ B1M = << <<" _" >> || _ <- lists :seq (1 , 1024 * 1024 ) >>,
1305
+ << B1M || _ <- lists :seq (1 , N ) >>.
1306
+
1307
+ assert_channel_alive (Ch ) ->
1308
+ amqp_channel :call (Ch , # 'basic.publish' {routing_key = <<" nope" >>},
1309
+ # amqp_msg {payload = <<" HI" >>}).
1310
+
1311
+ assert_channel_fail_max_size (Ch , Monitor , ExpectedException ) ->
1312
+ receive
1313
+ {'DOWN' , Monitor , process , Ch ,
1314
+ {shutdown ,
1315
+ {server_initiated_close , 406 , Exception }}} ->
1316
+ ? assertMatch (Exception , ExpectedException )
1317
+ after 100000 ->
1318
+ error ({channel_exception_expected , max_message_size })
1319
+ end .
1320
+
1321
+ max_message_size (Config ) ->
1322
+ Binary128M = gen_binary_mb (128 ),
1323
+ {_ , Ch } = rabbit_ct_client_helpers :open_connection_and_channel (Config , 0 ),
1324
+ % % Default message size is 128MB
1325
+ Size128Mb = 1024 * 1024 * 128 ,
1326
+ Size128Mb = rabbit_ct_broker_helpers :rpc (Config , 0 ,
1327
+ application , get_env , [rabbit , max_message_size , undefined ]),
1328
+
1329
+ Size128Mb = byte_size (Binary128M ),
1330
+ % % Binary is whithin the max size limit
1331
+ amqp_channel :call (Ch , # 'basic.publish' {routing_key = <<" nope" >>}, # amqp_msg {payload = Binary128M }),
1332
+ % % Channel process is alive
1333
+ assert_channel_alive (Ch ),
1334
+
1335
+ Monitor = monitor (process , Ch ),
1336
+ % % This publish should cause a channel exception
1337
+ BinaryBiggerThan128M = <<" _" , Binary128M /binary >>,
1338
+ amqp_channel :call (Ch , # 'basic.publish' {routing_key = <<" nope" >>}, # amqp_msg {payload = BinaryBiggerThan128M }),
1339
+ ct :pal (" Assert channel error 128" ),
1340
+ ExpectedException = <<" PRECONDITION_FAILED - message size " ,
1341
+ (integer_to_binary (byte_size (BinaryBiggerThan128M )))/binary ,
1342
+ " larger than configured max size " ,
1343
+ (integer_to_binary (Size128Mb ))/binary >>,
1344
+ assert_channel_fail_max_size (Ch , Monitor , ExpectedException ),
1345
+
1346
+
1347
+ {_ , Ch1 } = rabbit_ct_client_helpers :open_connection_and_channel (Config , 0 ),
1348
+
1349
+ % % Set a bigger message size
1350
+ rabbit_ct_broker_helpers :rpc (Config , 0 ,
1351
+ application , set_env , [rabbit , max_message_size , 1024 * 1024 * 256 ]),
1352
+
1353
+ amqp_channel :call (Ch1 , # 'basic.publish' {routing_key = <<" nope" >>}, # amqp_msg {payload = Binary128M }),
1354
+ assert_channel_alive (Ch1 ),
1355
+
1356
+ amqp_channel :call (Ch1 , # 'basic.publish' {routing_key = <<" nope" >>}, # amqp_msg {payload = BinaryBiggerThan128M }),
1357
+ assert_channel_alive (Ch1 ),
1358
+
1359
+ % % Set message size above 512MB.
1360
+ % % The actual limit will be 512MB
1361
+ rabbit_ct_broker_helpers :rpc (Config , 0 ,
1362
+ application , set_env , [rabbit , max_message_size , 1024 * 1024 * 515 ]),
1363
+
1364
+ Binary512M = << Binary128M /binary , Binary128M /binary ,
1365
+ Binary128M /binary , Binary128M /binary >>,
1366
+
1367
+ BinaryBiggerThan512M = <<" _" , Binary512M /binary >>,
1368
+
1369
+ amqp_channel :call (Ch1 , # 'basic.publish' {routing_key = <<" nope" >>}, # amqp_msg {payload = Binary512M }),
1370
+ assert_channel_alive (Ch1 ),
1371
+
1372
+ Monitor1 = monitor (process , Ch1 ),
1373
+ amqp_channel :call (Ch1 , # 'basic.publish' {routing_key = <<" nope" >>}, # amqp_msg {payload = BinaryBiggerThan512M }),
1374
+ ct :pal (" Assert channel error 512" ),
1375
+ ExpectedException1 = <<" PRECONDITION_FAILED - message size " ,
1376
+ (integer_to_binary (byte_size (BinaryBiggerThan512M )))/binary ,
1377
+ " larger than max size " ,
1378
+ (integer_to_binary (byte_size (Binary512M )))/binary >>,
1379
+ assert_channel_fail_max_size (Ch1 , Monitor1 , ExpectedException1 ).
1380
+
1302
1381
% % ---------------------------------------------------------------------------
1303
1382
% % rabbitmqctl helpers.
1304
1383
% % ---------------------------------------------------------------------------
0 commit comments