diff options
author | Tim Watson <tim@rabbitmq.com> | 2012-10-29 13:59:40 +0000 |
---|---|---|
committer | Tim Watson <tim@rabbitmq.com> | 2012-10-29 13:59:40 +0000 |
commit | 412d94bcdd6733f17849b08a467db1fdb56480d0 (patch) | |
tree | 87dc2f6311e355571d75e0aa5ff256ab4c37d51e | |
parent | 94da2cb2a045d56865a4d5f3e6a6dcc8d1c7a5c5 (diff) | |
download | rabbitmq-server-412d94bcdd6733f17849b08a467db1fdb56480d0.tar.gz |
migrate rabbit_basic tests to rabbit_tests
-rw-r--r-- | src/rabbit_basic_tests.erl | 110 | ||||
-rw-r--r-- | src/rabbit_tests.erl | 85 |
2 files changed, 84 insertions, 111 deletions
diff --git a/src/rabbit_basic_tests.erl b/src/rabbit_basic_tests.erl deleted file mode 100644 index 19c901c2..00000000 --- a/src/rabbit_basic_tests.erl +++ /dev/null @@ -1,110 +0,0 @@ -%% The contents of this file are subject to the Mozilla Public License -%% Version 1.1 (the "License"); you may not use this file except in -%% compliance with the License. You may obtain a copy of the License -%% at http://www.mozilla.org/MPL/ -%% -%% Software distributed under the License is distributed on an "AS IS" -%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -%% the License for the specific language governing rights and -%% limitations under the License. -%% -%% The Original Code is RabbitMQ. -%% -%% The Initial Developer of the Original Code is VMware, Inc. -%% Copyright (c) 2007-2012 VMware, Inc. All rights reserved. -%% --module(rabbit_basic_tests). - --include("rabbit.hrl"). --include_lib("eunit/include/eunit.hrl"). - --compile(export_all). - --define(XDEATH_TABLE, - [{<<"reason">>, longstr, <<"blah">>}, - {<<"queue">>, longstr, <<"foo.bar.baz">>}, - {<<"exchange">>, longstr, <<"my-exchange">>}, - {<<"routing-keys">>, array, []}]). - --define(ROUTE_TABLE, [{<<"redelivered">>, bool, <<"true">>}]). - -write_table_with_invalid_existing_type_test_() -> - [{"existing entries with invalid types are moved to a table " - "stored as <<\"x-invalid-headers header\">>", - fun() -> - check_invalid(<<"x-death">>, - {longstr, <<"this should be a table!!!">>}, - ?XDEATH_TABLE) - end}, - {"if invalid existing headers are moved, newly added " - "ones are still stored correctly", - begin - BadHeaders = [{<<"x-received-from">>, - longstr, <<"this should be a table!!!">>}], - Headers = rabbit_basic:prepend_table_header( - <<"x-received-from">>, ?ROUTE_TABLE, BadHeaders), - ?_assertEqual({array, [{table, ?ROUTE_TABLE}]}, - rabbit_misc:table_lookup(Headers, <<"x-received-from">>)) - end}, - {"disparate invalid header entries are accumulated separately", - begin - BadHeaders = [{<<"x-received-from">>, - longstr, <<"this should be a table!!!">>}], - Headers = rabbit_basic:prepend_table_header( - <<"x-received-from">>, ?ROUTE_TABLE, BadHeaders), - BadHeaders2 = rabbit_basic:prepend_table_header( - <<"x-death">>, ?XDEATH_TABLE, - [{<<"x-death">>, - longstr, <<"and so should this!!!">>}|Headers]), - ?_assertMatch( - {table, - [{<<"x-death">>, array, [{longstr, <<"and so should this!!!">>}]}, - {<<"x-received-from">>, - array, [{longstr, <<"this should be a table!!!">>}]}]}, - rabbit_misc:table_lookup(BadHeaders2, ?INVALID_HEADERS_KEY)) - end}, - {"corrupt or invalid x-invalid-headers entries are overwritten!", - begin - Headers0 = [{<<"x-death">>, longstr, <<"this should be a table">>}, - {?INVALID_HEADERS_KEY, longstr, <<"what the!?">>}], - Headers1 = rabbit_basic:prepend_table_header( - <<"x-death">>, ?XDEATH_TABLE, Headers0), - ?_assertMatch( - {table, - [{<<"x-death">>, array, - [{longstr, <<"this should be a table">>}]}, - {?INVALID_HEADERS_KEY, array, - [{longstr, <<"what the!?">>}]}]}, - rabbit_misc:table_lookup(Headers1, ?INVALID_HEADERS_KEY)) - end}]. - -invalid_same_header_entry_accumulation_test() -> - Key = <<"x-received-from">>, - BadHeader1 = {longstr, <<"this should be a table!!!">>}, - Headers = check_invalid(Key, BadHeader1, ?ROUTE_TABLE), - Headers2 = rabbit_basic:prepend_table_header( - Key, - ?ROUTE_TABLE, - [{Key, longstr, - <<"this should also be a table!!!">>}|Headers]), - Invalid = rabbit_misc:table_lookup(Headers2, ?INVALID_HEADERS_KEY), - ?assertMatch({table, _}, Invalid), - {table, InvalidHeaders} = Invalid, - ?assertMatch({array, - [{longstr, <<"this should also be a table!!!">>},BadHeader1]}, - rabbit_misc:table_lookup(InvalidHeaders, Key)). - -assert_invalid(HeaderKey, Entry, Table) -> - fun() -> check_invalid(HeaderKey, Entry, Table) end. - -check_invalid(HeaderKey, {TBin, VBin}=InvalidEntry, HeaderTable) -> - Headers = rabbit_basic:prepend_table_header(HeaderKey, HeaderTable, - [{HeaderKey, TBin, VBin}]), - InvalidHeaders = rabbit_misc:table_lookup(Headers, ?INVALID_HEADERS_KEY), - ?assertMatch({table, _}, InvalidHeaders), - {_, Invalid} = InvalidHeaders, - InvalidArrayForKey = rabbit_misc:table_lookup(Invalid, HeaderKey), - ?assertMatch({array, _}, InvalidArrayForKey), - {_, Array} = InvalidArrayForKey, - ?assertMatch([InvalidEntry], Array), - Headers. diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index bea94c15..25402ca7 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -31,10 +31,19 @@ -define(CLEANUP_QUEUE_NAME, <<"cleanup-queue">>). -define(TIMEOUT, 5000). + +-define(XDEATH_TABLE, + [{<<"reason">>, longstr, <<"blah">>}, + {<<"queue">>, longstr, <<"foo.bar.baz">>}, + {<<"exchange">>, longstr, <<"my-exchange">>}, + {<<"routing-keys">>, array, []}]). + +-define(ROUTE_TABLE, [{<<"redelivered">>, bool, <<"true">>}]). + all_tests() -> ok = setup_cluster(), ok = supervisor2_tests:test_all(), - ok = rabbit_basic_tests:test(), + ok = rabbit_basic_tests(), passed = gm_tests:all_tests(), passed = mirrored_supervisor_tests:all_tests(), application:set_env(rabbit, file_handles_high_watermark, 10, infinity), @@ -72,6 +81,80 @@ all_tests() -> passed = test_configurable_server_properties(), passed. +rabbit_basic_tests() -> + ok = write_table_with_invalid_existing_type_test(), + ok = invalid_existing_headers_test(), + ok = disparate_invalid_header_entries_accumulate_separately_test(), + ok = corrupt_or_invalid_headers_are_overwritten_test(), + ok = invalid_same_header_entry_accumulation_test(). + +write_table_with_invalid_existing_type_test() -> + check_invalid(<<"x-death">>, + {longstr, <<"this should be a table!!!">>}, + ?XDEATH_TABLE), + ok. + +invalid_existing_headers_test() -> + BadHeaders = [{<<"x-received-from">>, + longstr, <<"this should be a table!!!">>}], + Headers = rabbit_basic:prepend_table_header( + <<"x-received-from">>, ?ROUTE_TABLE, BadHeaders), + {array, [{table, ?ROUTE_TABLE}]} = + rabbit_misc:table_lookup(Headers, <<"x-received-from">>), + ok. + +disparate_invalid_header_entries_accumulate_separately_test() -> + BadHeaders = [{<<"x-received-from">>, + longstr, <<"this should be a table!!!">>}], + Headers = rabbit_basic:prepend_table_header( + <<"x-received-from">>, ?ROUTE_TABLE, BadHeaders), + BadHeaders2 = rabbit_basic:prepend_table_header( + <<"x-death">>, ?XDEATH_TABLE, + [{<<"x-death">>, + longstr, <<"and so should this!!!">>}|Headers]), + + {table, [{<<"x-death">>, array, [{longstr, <<"and so should this!!!">>}]}, + {<<"x-received-from">>, + array, [{longstr, <<"this should be a table!!!">>}]}]} = + rabbit_misc:table_lookup(BadHeaders2, ?INVALID_HEADERS_KEY), + ok. + +corrupt_or_invalid_headers_are_overwritten_test() -> + Headers0 = [{<<"x-death">>, longstr, <<"this should be a table">>}, + {?INVALID_HEADERS_KEY, longstr, <<"what the!?">>}], + Headers1 = rabbit_basic:prepend_table_header( + <<"x-death">>, ?XDEATH_TABLE, Headers0), + {table,[{<<"x-death">>, array, + [{longstr, <<"this should be a table">>}]}, + {?INVALID_HEADERS_KEY, array, + [{longstr, <<"what the!?">>}]}]} = + rabbit_misc:table_lookup(Headers1, ?INVALID_HEADERS_KEY), + ok. + +invalid_same_header_entry_accumulation_test() -> + Key = <<"x-received-from">>, + BadHeader1 = {longstr, <<"this should be a table!!!">>}, + Headers = check_invalid(Key, BadHeader1, ?ROUTE_TABLE), + Headers2 = rabbit_basic:prepend_table_header( + Key, + ?ROUTE_TABLE, + [{Key, longstr, + <<"this should also be a table!!!">>}|Headers]), + Invalid = rabbit_misc:table_lookup(Headers2, ?INVALID_HEADERS_KEY), + {table, InvalidHeaders} = Invalid, + {array, [{longstr, <<"this should also be a table!!!">>},BadHeader1]} = + rabbit_misc:table_lookup(InvalidHeaders, Key), + ok. + +check_invalid(HeaderKey, {TBin, VBin}=InvalidEntry, HeaderTable) -> + Headers = rabbit_basic:prepend_table_header(HeaderKey, HeaderTable, + [{HeaderKey, TBin, VBin}]), + InvalidHeaders = rabbit_misc:table_lookup(Headers, ?INVALID_HEADERS_KEY), + {table, Invalid} = InvalidHeaders, + InvalidArrayForKey = rabbit_misc:table_lookup(Invalid, HeaderKey), + {array, [InvalidEntry]} = InvalidArrayForKey, + Headers. + do_if_secondary_node(Up, Down) -> SecondaryNode = rabbit_nodes:make("hare"), |