Add a test of HA queue mgmt and fix a bug thus found.

This commit is contained in:
Simon MacMullen 2011-07-19 17:35:40 +01:00
parent 5ed6a16232
commit b6b4917a07
3 changed files with 53 additions and 3 deletions

View File

@ -420,7 +420,7 @@ handle_slave_synchronised(QName, SSPid, State) ->
handle_slave_promoted(QName, SPid, State) ->
handle_slave_sync_change(QName, fun ([]) -> [SPid];
([{_, SSPids}]) -> [SSPids] -- [SPid]
([{_, SSPids}]) -> SSPids -- [SPid]
end, State).
handle_slave_sync_change(QName, Fun, State = #state{tables = Tables}) ->

View File

@ -24,7 +24,8 @@
-export([start_second_node/0, stop_second_node/0]).
-import(rabbit_mgmt_test_http, [http_get/1]).
-import(rabbit_mgmt_test_http, [http_get/1, http_put/3, http_delete/2]).
-import(rabbit_misc, [pget/2]).
%%----------------------------------------------------------------------------
@ -43,3 +44,52 @@ plugin_dir() ->
cluster_nodes_test() ->
?assertEqual(2, length(http_get("/nodes"))),
ok.
ha_test_() ->
{timeout, 60, fun ha/0}.
ha() ->
QArgs = [{node, <<"hare">>},
{arguments, [{'x-ha-policy', all}]}],
http_put("/queues/%2f/ha-queue", QArgs, ?NO_CONTENT),
Q = wait_for("/queues/%2f/ha-queue", synchronised_slave_nodes),
assert_node(hare, pget(node, Q)),
assert_single_node('rabbit-test', pget(slave_nodes, Q)),
assert_single_node('rabbit-test', pget(synchronised_slave_nodes, Q)),
restart_node(),
Q2 = wait_for("/queues/%2f/ha-queue", synchronised_slave_nodes),
%% TODO this does not yet pass, I think due to bug24130.
%% assert_node('rabbit-test', pget(node, Q2)),
%% assert_single_node(hare, pget(slave_nodes, Q2)),
%% assert_single_node(hare, pget(synchronised_slave_nodes, Q2)),
http_delete("/queues/%2f/ha-queue", ?NO_CONTENT),
ok.
%%----------------------------------------------------------------------------
wait_for(Path, Key) ->
wait_for(Path, Key, 100).
wait_for(Path, Key, 0) ->
exit({timeout, {Path, Key}});
wait_for(Path, Key, Count) ->
Res = http_get(Path),
case pget(Key, http_get(Path)) of
undefined -> timer:sleep(10),
wait_for(Path, Key, Count - 1);
_ -> Res
end.
assert_single_node(Exp, Act) ->
?assertEqual(1, length(Act)),
assert_node(Exp, hd(Act)).
assert_node(Exp, Act) ->
?assertEqual(Exp,
list_to_atom(hd(string:tokens(binary_to_list(Act), "@")))).
restart_node() ->
stop_second_node(),
timer:sleep(1000),
start_second_node().

View File

@ -22,7 +22,7 @@
-include("rabbit_mgmt_test.hrl").
-export([http_get/1]).
-export([http_get/1, http_put/3, http_delete/2]).
overview_test() ->
%% Rather crude, but this req doesn't say much and at least this means it