summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Watson <tim@rabbitmq.com>2012-10-29 15:40:20 +0000
committerTim Watson <tim@rabbitmq.com>2012-10-29 15:40:20 +0000
commit3cd7676de61a14675dc47ed842ea3ff004d4f375 (patch)
tree78399f53baa13a3f907d0edaf3f04a7cbffda64d
parent3dbe2cede1f87e420cce098595a779f366cd043f (diff)
downloadrabbitmq-server-3cd7676de61a14675dc47ed842ea3ff004d4f375.tar.gz
make basic tests fit into rabbit_tests a bit more cleanly
-rw-r--r--src/rabbit_tests.erl150
1 files changed, 76 insertions, 74 deletions
diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl
index 25402ca7..13aff6e8 100644
--- a/src/rabbit_tests.erl
+++ b/src/rabbit_tests.erl
@@ -43,7 +43,6 @@
all_tests() ->
ok = setup_cluster(),
ok = supervisor2_tests:test_all(),
- 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),
@@ -51,6 +50,7 @@ all_tests() ->
passed = test_multi_call(),
passed = test_file_handle_cache(),
passed = test_backing_queue(),
+ passed = test_rabbit_basic_header_handling(),
passed = test_priority_queue(),
passed = test_pg_local(),
passed = test_unfold(),
@@ -81,79 +81,6 @@ 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"),
@@ -243,6 +170,81 @@ test_multi_call() ->
exit(Pid3, bang),
passed.
+test_rabbit_basic_header_handling() ->
+ passed = write_table_with_invalid_existing_type_test(),
+ passed = invalid_existing_headers_test(),
+ passed = disparate_invalid_header_entries_accumulate_separately_test(),
+ passed = corrupt_or_invalid_headers_are_overwritten_test(),
+ passed = invalid_same_header_entry_accumulation_test(),
+ passed.
+
+write_table_with_invalid_existing_type_test() ->
+ check_invalid(<<"x-death">>,
+ {longstr, <<"this should be a table!!!">>},
+ ?XDEATH_TABLE),
+ passed.
+
+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">>),
+ passed.
+
+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),
+ passed.
+
+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),
+ passed.
+
+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),
+ passed.
+
+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.
+
test_priority_queue() ->
false = priority_queue:is_queue(not_a_queue),