Skip to content

Commit bfb6e8e

Browse files
committed
Switch testsuite to common_test, part #2
The migrated tests are those from `rabbit_tests.erl`. References #725. [#116526487]
1 parent 0b3c6be commit bfb6e8e

File tree

6 files changed

+4464
-295
lines changed

6 files changed

+4464
-295
lines changed

test/dummy_event_receiver.erl

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
%% The contents of this file are subject to the Mozilla Public License
2+
%% Version 1.1 (the "License"); you may not use this file except in
3+
%% compliance with the License. You may obtain a copy of the License
4+
%% at http://www.mozilla.org/MPL/
5+
%%
6+
%% Software distributed under the License is distributed on an "AS IS"
7+
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
8+
%% the License for the specific language governing rights and
9+
%% limitations under the License.
10+
%%
11+
%% The Original Code is RabbitMQ.
12+
%%
13+
%% The Initial Developer of the Original Code is GoPivotal, Inc.
14+
%% Copyright (c) 2007-2015 Pivotal Software, Inc. All rights reserved.
15+
%%
16+
17+
-module(dummy_event_receiver).
18+
19+
-export([start/3, stop/0]).
20+
21+
-export([init/1, handle_call/2, handle_event/2, handle_info/2,
22+
terminate/2, code_change/3]).
23+
24+
-include("rabbit.hrl").
25+
26+
start(Pid, Nodes, Types) ->
27+
Oks = [ok || _ <- Nodes],
28+
{Oks, _} = rpc:multicall(Nodes, gen_event, add_handler,
29+
[rabbit_event, ?MODULE, [Pid, Types]]).
30+
31+
stop() ->
32+
gen_event:delete_handler(rabbit_event, ?MODULE, []).
33+
34+
%%----------------------------------------------------------------------------
35+
36+
init([Pid, Types]) ->
37+
{ok, {Pid, Types}}.
38+
39+
handle_call(_Request, State) ->
40+
{ok, not_understood, State}.
41+
42+
handle_event(Event = #event{type = Type}, State = {Pid, Types}) ->
43+
case lists:member(Type, Types) of
44+
true -> Pid ! Event;
45+
false -> ok
46+
end,
47+
{ok, State}.
48+
49+
handle_info(_Info, State) ->
50+
{ok, State}.
51+
52+
terminate(_Arg, _State) ->
53+
ok.
54+
55+
code_change(_OldVsn, State, _Extra) ->
56+
{ok, State}.
57+
58+
%%----------------------------------------------------------------------------

test/dummy_runtime_parameters.erl

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
%% The contents of this file are subject to the Mozilla Public License
2+
%% Version 1.1 (the "License"); you may not use this file except in
3+
%% compliance with the License. You may obtain a copy of the License
4+
%% at http://www.mozilla.org/MPL/
5+
%%
6+
%% Software distributed under the License is distributed on an "AS IS"
7+
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
8+
%% the License for the specific language governing rights and
9+
%% limitations under the License.
10+
%%
11+
%% The Original Code is RabbitMQ.
12+
%%
13+
%% The Initial Developer of the Original Code is GoPivotal, Inc.
14+
%% Copyright (c) 2007-2015 Pivotal Software, Inc. All rights reserved.
15+
%%
16+
17+
-module(dummy_runtime_parameters).
18+
-behaviour(rabbit_runtime_parameter).
19+
-behaviour(rabbit_policy_validator).
20+
21+
-include("rabbit.hrl").
22+
23+
-export([validate/5, notify/4, notify_clear/3]).
24+
-export([register/0, unregister/0]).
25+
-export([validate_policy/1]).
26+
-export([register_policy_validator/0, unregister_policy_validator/0]).
27+
28+
%----------------------------------------------------------------------------
29+
30+
register() ->
31+
rabbit_registry:register(runtime_parameter, <<"test">>, ?MODULE).
32+
33+
unregister() ->
34+
rabbit_registry:unregister(runtime_parameter, <<"test">>).
35+
36+
validate(_, <<"test">>, <<"good">>, _Term, _User) -> ok;
37+
validate(_, <<"test">>, <<"maybe">>, <<"good">>, _User) -> ok;
38+
validate(_, <<"test">>, <<"admin">>, _Term, none) -> ok;
39+
validate(_, <<"test">>, <<"admin">>, _Term, User) ->
40+
case lists:member(administrator, User#user.tags) of
41+
true -> ok;
42+
false -> {error, "meh", []}
43+
end;
44+
validate(_, <<"test">>, _, _, _) -> {error, "meh", []}.
45+
46+
notify(_, _, _, _) -> ok.
47+
notify_clear(_, _, _) -> ok.
48+
49+
%----------------------------------------------------------------------------
50+
51+
register_policy_validator() ->
52+
rabbit_registry:register(policy_validator, <<"testeven">>, ?MODULE),
53+
rabbit_registry:register(policy_validator, <<"testpos">>, ?MODULE).
54+
55+
unregister_policy_validator() ->
56+
rabbit_registry:unregister(policy_validator, <<"testeven">>),
57+
rabbit_registry:unregister(policy_validator, <<"testpos">>).
58+
59+
validate_policy([{<<"testeven">>, Terms}]) when is_list(Terms) ->
60+
case length(Terms) rem 2 =:= 0 of
61+
true -> ok;
62+
false -> {error, "meh", []}
63+
end;
64+
65+
validate_policy([{<<"testpos">>, Terms}]) when is_list(Terms) ->
66+
case lists:all(fun (N) -> is_integer(N) andalso N > 0 end, Terms) of
67+
true -> ok;
68+
false -> {error, "meh", []}
69+
end;
70+
71+
validate_policy(_) ->
72+
{error, "meh", []}.

test/rabbit_ct_broker_helpers.erl

Lines changed: 0 additions & 78 deletions
This file was deleted.

test/sup_delayed_restart_SUITE.erl

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
%% The contents of this file are subject to the Mozilla Public License
2+
%% Version 1.1 (the "License"); you may not use this file except in
3+
%% compliance with the License. You may obtain a copy of the License
4+
%% at http://www.mozilla.org/MPL/
5+
%%
6+
%% Software distributed under the License is distributed on an "AS IS"
7+
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
8+
%% the License for the specific language governing rights and
9+
%% limitations under the License.
10+
%%
11+
%% The Original Code is RabbitMQ.
12+
%%
13+
%% The Initial Developer of the Original Code is GoPivotal, Inc.
14+
%% Copyright (c) 2007-2015 Pivotal Software, Inc. All rights reserved.
15+
%%
16+
17+
-module(sup_delayed_restart_SUITE).
18+
19+
-behaviour(supervisor2).
20+
21+
-include_lib("common_test/include/ct.hrl").
22+
23+
-compile(export_all).
24+
25+
all() ->
26+
[
27+
delayed_restart
28+
].
29+
30+
%%----------------------------------------------------------------------------
31+
%% Public API
32+
%%----------------------------------------------------------------------------
33+
34+
delayed_restart(_Config) ->
35+
passed = with_sup(simple_one_for_one,
36+
fun (SupPid) ->
37+
{ok, _ChildPid} =
38+
supervisor2:start_child(SupPid, []),
39+
test_supervisor_delayed_restart(SupPid)
40+
end),
41+
passed = with_sup(one_for_one, fun test_supervisor_delayed_restart/1).
42+
43+
test_supervisor_delayed_restart(SupPid) ->
44+
ok = ping_child(SupPid),
45+
ok = exit_child(SupPid),
46+
timer:sleep(100),
47+
ok = ping_child(SupPid),
48+
ok = exit_child(SupPid),
49+
timer:sleep(100),
50+
timeout = ping_child(SupPid),
51+
timer:sleep(1010),
52+
ok = ping_child(SupPid),
53+
passed.
54+
55+
with_sup(RestartStrategy, Fun) ->
56+
{ok, SupPid} = supervisor2:start_link(?MODULE, [RestartStrategy]),
57+
Res = Fun(SupPid),
58+
unlink(SupPid),
59+
exit(SupPid, shutdown),
60+
Res.
61+
62+
init([RestartStrategy]) ->
63+
{ok, {{RestartStrategy, 1, 1},
64+
[{test, {?MODULE, start_child, []}, {permanent, 1},
65+
16#ffffffff, worker, [?MODULE]}]}}.
66+
67+
start_child() ->
68+
{ok, proc_lib:spawn_link(fun run_child/0)}.
69+
70+
ping_child(SupPid) ->
71+
Ref = make_ref(),
72+
with_child_pid(SupPid, fun(ChildPid) -> ChildPid ! {ping, Ref, self()} end),
73+
receive {pong, Ref} -> ok
74+
after 1000 -> timeout
75+
end.
76+
77+
exit_child(SupPid) ->
78+
with_child_pid(SupPid, fun(ChildPid) -> exit(ChildPid, abnormal) end),
79+
ok.
80+
81+
with_child_pid(SupPid, Fun) ->
82+
case supervisor2:which_children(SupPid) of
83+
[{_Id, undefined, worker, [?MODULE]}] -> ok;
84+
[{_Id, ChildPid, worker, [?MODULE]}] -> Fun(ChildPid);
85+
[] -> ok
86+
end.
87+
88+
run_child() ->
89+
receive {ping, Ref, Pid} -> Pid ! {pong, Ref},
90+
run_child()
91+
end.

0 commit comments

Comments
 (0)