diff options
author | Michael Bridgen <mikeb@lshift.net> | 2009-11-12 16:56:47 +0000 |
---|---|---|
committer | Michael Bridgen <mikeb@lshift.net> | 2009-11-12 16:56:47 +0000 |
commit | 167499115701e02dc0d432a73f7de1a02b2ea61c (patch) | |
tree | fc876b2ddcfa281cf253402fdd468e9cd5edcace | |
parent | 0f0233099f4bf64e1cab1b9a867be59526f24d18 (diff) | |
download | rabbitmq-server-167499115701e02dc0d432a73f7de1a02b2ea61c.tar.gz |
Bug 21836: Test that the content framing code doesn't produce frames that break frame-max
-rw-r--r-- | src/rabbit_tests.erl | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index c3280508..aff5f296 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -51,6 +51,7 @@ all_tests() -> passed = test_priority_queue(), passed = test_unfold(), passed = test_parsing(), + passed = test_content_framing(), passed = test_topic_matching(), passed = test_log_management(), passed = test_app_management(), @@ -249,6 +250,45 @@ test_content_properties() -> V -> exit({got_success_but_expected_failure, V}) end. +%% Test that content frames don't exceed frame-max +test_content_framing(FrameMax, Fragments) -> + [Header | Frames] = + rabbit_binary_generator:build_simple_content_frames( + 1, + #content{class_id = 0, properties_bin = <<>>, + payload_fragments_rev = Fragments}, + FrameMax), + % header is formatted correctly and the size is the total of the + % fragments + <<_FrameHeader:7/binary, _ClassAndWeight:4/binary, + BodySize:64/unsigned, _Rest/binary>> = list_to_binary(Header), + BodySize = size(list_to_binary(Fragments)), + false = lists:any( + fun (ContentFrame) -> + FrameBinary = list_to_binary(ContentFrame), + % assert + <<_TypeAndChannel:3/binary, + Size:32/unsigned, + _Payload:Size/binary, + 16#CE>> = FrameBinary, + size(FrameBinary) > FrameMax + end, + Frames), + passed. + +test_content_framing() -> + % no content + passed = test_content_framing(4096, []), + passed = test_content_framing(4096, [<<>>]), + % easily fit in one frame + passed = test_content_framing(4096, [<<"Easy">>]), + % exactly one frame (empty frame = 8 bytes) + passed = test_content_framing(11, [<<"One">>]), + % more than one frame + passed = test_content_framing(20, [<<"into more than one frame">>, + <<"This will have to go">>]), + passed. + test_topic_match(P, R) -> test_topic_match(P, R, true). |