Skip to content

Commit c8bdf33

Browse files
committed
Switch testsuite to common_test, part #4
This is a follow-up to the previous merge of the stable branch. It covers tests which were modified or added only to the master branch. References #725. [#116526487]
1 parent dc941fe commit c8bdf33

File tree

12 files changed

+1316
-151
lines changed

12 files changed

+1316
-151
lines changed

test/channel_interceptor_SUITE.erl

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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 at
4+
%% 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 the
8+
%% License for the specific language governing rights and limitations
9+
%% 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) 2016 Pivotal Software, Inc. All rights reserved.
15+
%%
16+
17+
-module(channel_interceptor_SUITE).
18+
19+
-include_lib("common_test/include/ct.hrl").
20+
-include_lib("amqp_client/include/amqp_client.hrl").
21+
22+
-compile(export_all).
23+
24+
all() ->
25+
[
26+
{group, non_parallel_tests}
27+
].
28+
29+
groups() ->
30+
[
31+
{non_parallel_tests, [], [
32+
register_interceptor
33+
]}
34+
].
35+
36+
%% -------------------------------------------------------------------
37+
%% Testsuite setup/teardown.
38+
%% -------------------------------------------------------------------
39+
40+
init_per_suite(Config) ->
41+
rabbit_ct_helpers:log_environment(),
42+
rabbit_ct_helpers:run_setup_steps(Config).
43+
44+
end_per_suite(Config) ->
45+
rabbit_ct_helpers:run_teardown_steps(Config).
46+
47+
init_per_group(_, Config) ->
48+
Config.
49+
50+
end_per_group(_, Config) ->
51+
Config.
52+
53+
init_per_testcase(Testcase, Config) ->
54+
rabbit_ct_helpers:testcase_started(Config, Testcase),
55+
Config1 = rabbit_ct_helpers:set_config(Config, [
56+
{rmq_nodename_suffix, Testcase}
57+
]),
58+
rabbit_ct_helpers:run_steps(Config1,
59+
rabbit_ct_broker_helpers:setup_steps() ++
60+
rabbit_ct_client_helpers:setup_steps()).
61+
62+
end_per_testcase(Testcase, Config) ->
63+
Config1 = rabbit_ct_helpers:run_steps(Config,
64+
rabbit_ct_client_helpers:teardown_steps() ++
65+
rabbit_ct_broker_helpers:teardown_steps()),
66+
rabbit_ct_helpers:testcase_finished(Config1, Testcase).
67+
68+
%% -------------------------------------------------------------------
69+
%% Testcases.
70+
%% -------------------------------------------------------------------
71+
72+
register_interceptor(Config) ->
73+
passed = rabbit_ct_broker_helpers:rpc(Config, 0,
74+
?MODULE, register_interceptor1, [Config]).
75+
76+
register_interceptor1(Config) ->
77+
PredefinedChannels = rabbit_channel:list(),
78+
79+
Ch1 = rabbit_ct_client_helpers:open_channel(Config, 0),
80+
81+
QName = <<"register_interceptor-q">>,
82+
amqp_channel:call(Ch1, #'queue.declare'{queue = QName}),
83+
84+
[ChannelProc] = rabbit_channel:list() -- PredefinedChannels,
85+
86+
[{interceptors, []}] = rabbit_channel:info(ChannelProc, [interceptors]),
87+
88+
check_send_receive(Ch1, QName, <<"bar">>, <<"bar">>),
89+
90+
ok = rabbit_registry:register(channel_interceptor,
91+
<<"dummy interceptor">>,
92+
dummy_interceptor),
93+
[{interceptors, [{dummy_interceptor, undefined}]}] =
94+
rabbit_channel:info(ChannelProc, [interceptors]),
95+
96+
check_send_receive(Ch1, QName, <<"bar">>, <<"">>),
97+
98+
ok = rabbit_registry:unregister(channel_interceptor,
99+
<<"dummy interceptor">>),
100+
[{interceptors, []}] = rabbit_channel:info(ChannelProc, [interceptors]),
101+
102+
check_send_receive(Ch1, QName, <<"bar">>, <<"bar">>),
103+
passed.
104+
105+
106+
check_send_receive(Ch1, QName, Send, Receive) ->
107+
amqp_channel:call(Ch1,
108+
#'basic.publish'{routing_key = QName},
109+
#amqp_msg{payload = Send}),
110+
111+
{#'basic.get_ok'{}, #amqp_msg{payload = Receive}} =
112+
amqp_channel:call(Ch1, #'basic.get'{queue = QName,
113+
no_ack = true}).

test/channel_operation_timeout_test_queue.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ update_rates(State = #vqstate{ in_counter = InCount,
563563
ack_in = AckInRate,
564564
ack_out = AckOutRate,
565565
timestamp = TS }}) ->
566-
Now = time_compat:monotonic_time(),
566+
Now = erlang:monotonic_time(),
567567

568568
Rates = #rates { in = update_rate(Now, TS, InCount, InRate),
569569
out = update_rate(Now, TS, OutCount, OutRate),
@@ -578,7 +578,7 @@ update_rates(State = #vqstate{ in_counter = InCount,
578578
rates = Rates }.
579579

580580
update_rate(Now, TS, Count, Rate) ->
581-
Time = time_compat:convert_time_unit(Now - TS, native, micro_seconds) /
581+
Time = erlang:convert_time_unit(Now - TS, native, micro_seconds) /
582582
?MICROS_PER_SECOND,
583583
if
584584
Time == 0 -> Rate;
@@ -1076,7 +1076,7 @@ init(IsDurable, IndexState, DeltaCount, DeltaBytes, Terms,
10761076
count = DeltaCount1,
10771077
end_seq_id = NextSeqId })
10781078
end,
1079-
Now = time_compat:monotonic_time(),
1079+
Now = erlang:monotonic_time(),
10801080
IoBatchSize = rabbit_misc:get_env(rabbit, msg_store_io_batch_size,
10811081
?IO_BATCH_SIZE),
10821082

test/config_schema_SUITE.erl

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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 at
4+
%% 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 the
8+
%% License for the specific language governing rights and limitations
9+
%% 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) 2016 Pivotal Software, Inc. All rights reserved.
15+
%%
16+
17+
-module(config_schema_SUITE).
18+
19+
-include_lib("common_test/include/ct.hrl").
20+
-include_lib("amqp_client/include/amqp_client.hrl").
21+
22+
-compile(export_all).
23+
24+
all() ->
25+
[
26+
{group, non_parallel_tests}
27+
].
28+
29+
groups() ->
30+
[
31+
{non_parallel_tests, [], [
32+
run_snippets
33+
]}
34+
].
35+
36+
%% -------------------------------------------------------------------
37+
%% Testsuite setup/teardown.
38+
%% -------------------------------------------------------------------
39+
40+
init_per_suite(Config) ->
41+
rabbit_ct_helpers:log_environment(),
42+
rabbit_ct_helpers:run_setup_steps(Config).
43+
44+
end_per_suite(Config) ->
45+
rabbit_ct_helpers:run_teardown_steps(Config).
46+
47+
init_per_group(_, Config) ->
48+
Config.
49+
50+
end_per_group(_, Config) ->
51+
Config.
52+
53+
init_per_testcase(Testcase, Config) ->
54+
rabbit_ct_helpers:testcase_started(Config, Testcase),
55+
Config1 = rabbit_ct_helpers:set_config(Config, [
56+
{rmq_nodename_suffix, Testcase}
57+
]),
58+
Config2 = case Testcase of
59+
run_snippets ->
60+
SchemaDir = filename:join(?config(priv_dir, Config1), "schema"),
61+
ResultsDir = filename:join(?config(priv_dir, Config1), "results"),
62+
Snippets = filename:join(?config(data_dir, Config1),
63+
"snippets.config"),
64+
ok = file:make_dir(SchemaDir),
65+
ok = file:make_dir(ResultsDir),
66+
rabbit_ct_helpers:set_config(Config1, [
67+
{schema_dir, SchemaDir},
68+
{results_dir, ResultsDir},
69+
{conf_snippets, Snippets}
70+
])
71+
end,
72+
rabbit_ct_helpers:run_steps(Config2,
73+
rabbit_ct_broker_helpers:setup_steps() ++
74+
rabbit_ct_client_helpers:setup_steps()).
75+
76+
end_per_testcase(Testcase, Config) ->
77+
Config1 = rabbit_ct_helpers:run_steps(Config,
78+
rabbit_ct_client_helpers:teardown_steps() ++
79+
rabbit_ct_broker_helpers:teardown_steps()),
80+
rabbit_ct_helpers:testcase_finished(Config1, Testcase).
81+
82+
%% -------------------------------------------------------------------
83+
%% Testcases.
84+
%% -------------------------------------------------------------------
85+
86+
run_snippets(Config) ->
87+
passed = rabbit_ct_broker_helpers:rpc(Config, 0,
88+
?MODULE, run_snippets1, [Config]).
89+
90+
run_snippets1(Config) ->
91+
prepare_plugin_schemas(Config),
92+
{ok, [Snippets]} = file:consult(?config(conf_snippets, Config)),
93+
lists:map(
94+
fun({N, S, C, P}) -> ok = test_snippet(Config, {integer_to_list(N), S, []}, C, P);
95+
({N, S, A, C, P}) -> ok = test_snippet(Config, {integer_to_list(N), S, A}, C, P)
96+
end,
97+
Snippets),
98+
passed.
99+
100+
test_snippet(Config, Snippet, Expected, _Plugins) ->
101+
{ConfFile, AdvancedFile} = write_snippet(Config, Snippet),
102+
{ok, GeneratedFile} = generate_config(Config, ConfFile, AdvancedFile),
103+
{ok, [Generated]} = file:consult(GeneratedFile),
104+
Gen = deepsort(Generated),
105+
Exp = deepsort(Expected),
106+
case Exp of
107+
Gen -> ok;
108+
_ ->
109+
error({config_mismatch, Snippet, Exp, Gen})
110+
end.
111+
112+
write_snippet(Config, {Name, Conf, Advanced}) ->
113+
ResultsDir = ?config(results_dir, Config),
114+
file:make_dir(filename:join(ResultsDir, Name)),
115+
ConfFile = filename:join([ResultsDir, Name, "config.conf"]),
116+
AdvancedFile = filename:join([ResultsDir, Name, "advanced.config"]),
117+
118+
file:write_file(ConfFile, Conf),
119+
rabbit_file:write_term_file(AdvancedFile, [Advanced]),
120+
{ConfFile, AdvancedFile}.
121+
122+
generate_config(Config, ConfFile, AdvancedFile) ->
123+
SchemaDir = ?config(schema_dir, Config),
124+
ResultsDir = ?config(results_dir, Config),
125+
Rabbitmqctl = ?config(rabbitmqctl_cmd, Config),
126+
ScriptDir = filename:dirname(Rabbitmqctl),
127+
ct:pal("ConfFile=~p ScriptDir=~p SchemaDir=~p AdvancedFile=~p", [ConfFile, ScriptDir, SchemaDir, AdvancedFile]),
128+
rabbit_config:generate_config_file([ConfFile], ResultsDir, ScriptDir,
129+
SchemaDir, AdvancedFile).
130+
131+
prepare_plugin_schemas(Config) ->
132+
SchemaDir = ?config(schema_dir, Config),
133+
DepsDir = ?config(erlang_mk_depsdir, Config),
134+
Files = filelib:wildcard(
135+
filename:join(DepsDir, "*/priv/schema/*.schema")),
136+
[ file:copy(File, filename:join([SchemaDir, filename:basename(File)]))
137+
|| File <- Files ].
138+
139+
deepsort(List) ->
140+
case is_proplist(List) of
141+
true ->
142+
lists:keysort(1, lists:map(fun({K, V}) -> {K, deepsort(V)};
143+
(V) -> V end,
144+
List));
145+
false ->
146+
case is_list(List) of
147+
true -> lists:sort(List);
148+
false -> List
149+
end
150+
end.
151+
152+
is_proplist([{_Key, _Val}|_] = List) -> lists:all(fun({_K, _V}) -> true; (_) -> false end, List);
153+
is_proplist(_) -> false.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
I'm not a certificate
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
I'm not a certificate
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
I'm not a certificate

test/config_schema_SUITE_data/rabbit-mgmt/access.log

Whitespace-only changes.

0 commit comments

Comments
 (0)