Skip to content

Commit

Permalink
Fix OTP-27 Dialyzer errors in rabbitmq_ct_helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
lhoguin committed Sep 16, 2024
1 parent 9d9228d commit 9c41b2e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions deps/rabbitmq_ct_helpers/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
PROJECT = rabbitmq_ct_helpers
PROJECT_DESCRIPTION = Common Test helpers for RabbitMQ

DEPS = rabbit_common proper inet_tcp_proxy meck
TEST_DEPS = rabbit
DEPS = rabbit rabbit_common proper inet_tcp_proxy meck
LOCAL_DEPS = common_test eunit inets

XREF_IGNORE = [ \
{'Elixir.OptionParser',split,1}, \
Expand Down
6 changes: 4 additions & 2 deletions deps/rabbitmq_ct_helpers/src/rabbit_control_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ wait_for_async_command(Node) ->

command_with_output(Command, Node, Args, Opts) ->
Formatted = format_command(Command, Node, Args, Opts),
CommandResult = 'Elixir.RabbitMQCtl':exec_command(
Mod = 'Elixir.RabbitMQCtl', %% To silence a Dialyzer warning.
CommandResult = Mod:exec_command(
Formatted, fun(Output,_,_) -> Output end),
ct:pal("Executed command ~tp against node ~tp~nResult: ~tp~n", [Formatted, Node, CommandResult]),
CommandResult.
Expand All @@ -50,7 +51,8 @@ format_command(Command, Node, Args, Opts) ->
[Command,
format_args(Args),
format_options([{"--node", Node} | Opts])]),
'Elixir.OptionParser':split(iolist_to_binary(Formatted)).
Mod = 'Elixir.OptionParser', %% To silence a Dialyzer warning.
Mod:split(iolist_to_binary(Formatted)).

format_args(Args) ->
iolist_to_binary([ io_lib:format("~tp ", [Arg]) || Arg <- Args ]).
Expand Down
16 changes: 7 additions & 9 deletions deps/rabbitmq_ct_helpers/src/rabbit_ct_broker_helpers.erl
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ wait_for_rabbitmq_nodes(Config, Starting, NodeConfigs, Clustered) ->
NodeConfigs1 = [NC || {_, NC} <- NodeConfigs],
Config1 = rabbit_ct_helpers:set_config(Config,
{rmq_nodes, NodeConfigs1}),
stop_rabbitmq_nodes(Config1),
_ = stop_rabbitmq_nodes(Config1),
Error;
{Pid, I, NodeConfig} when NodeConfigs =:= [] ->
wait_for_rabbitmq_nodes(Config, Starting -- [Pid],
Expand Down Expand Up @@ -917,7 +917,7 @@ wait_for_node_handling(Procs, Fun, T0, Results) ->
move_nonworking_nodedir_away(NodeConfig) ->
ConfigFile = ?config(erlang_node_config_filename, NodeConfig),
ConfigDir = filename:dirname(ConfigFile),
case os:getenv("RABBITMQ_CT_HELPERS_DELETE_UNUSED_NODES") =/= false
ok = case os:getenv("RABBITMQ_CT_HELPERS_DELETE_UNUSED_NODES") =/= false
andalso ?OTP_RELEASE >= 23 of
true ->
file:del_dir_r(ConfigDir);
Expand Down Expand Up @@ -1135,7 +1135,7 @@ stop_rabbitmq_node(Config, NodeConfig) ->
{"RABBITMQ_NODENAME_FOR_PATHS=~ts", [InitialNodename]}
],
Cmd = ["stop-node" | MakeVars],
case rabbit_ct_helpers:get_config(Config, rabbitmq_run_cmd) of
{ok, _} = case rabbit_ct_helpers:get_config(Config, rabbitmq_run_cmd) of
undefined ->
rabbit_ct_helpers:make(Config, SrcDir, Cmd);
RunCmd ->
Expand Down Expand Up @@ -1914,10 +1914,8 @@ restart_node(Config, Node) ->

stop_node(Config, Node) ->
NodeConfig = get_node_config(Config, Node),
case stop_rabbitmq_node(Config, NodeConfig) of
{skip, _} = Error -> Error;
_ -> ok
end.
_ = stop_rabbitmq_node(Config, NodeConfig),
ok.

stop_node_after(Config, Node, Sleep) ->
timer:sleep(Sleep),
Expand All @@ -1940,7 +1938,7 @@ kill_node(Config, Node) ->
_ ->
rabbit_misc:format("kill -9 ~ts", [Pid])
end,
os:cmd(Cmd),
_ = os:cmd(Cmd),
await_os_pid_death(Pid).

kill_node_after(Config, Node, Sleep) ->
Expand Down Expand Up @@ -2231,7 +2229,7 @@ if_cover(F) ->
os:getenv("COVERAGE")
} of
{false, false} -> ok;
_ -> F()
_ -> _ = F(), ok
end.

setup_meck(Config) ->
Expand Down
8 changes: 4 additions & 4 deletions deps/rabbitmq_ct_helpers/src/rabbit_ct_config_schema.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ init_schemas(App, Config) ->
run_snippets(Config) ->
{ok, [Snippets]} = file:consult(?config(conf_snippets, Config)),
ct:pal("Loaded config schema snippets: ~tp", [Snippets]),
lists:map(
lists:foreach(
fun({N, S, C, P}) ->
ok = test_snippet(Config, {snippet_id(N), S, []}, C, P, true);
({N, S, A, C, P}) ->
Expand Down Expand Up @@ -70,12 +70,12 @@ test_snippet(Config, Snippet = {SnipID, _, _}, Expected, _Plugins, Sort) ->

write_snippet(Config, {Name, Conf, Advanced}) ->
ResultsDir = ?config(results_dir, Config),
file:make_dir(filename:join(ResultsDir, Name)),
ok = file:make_dir(filename:join(ResultsDir, Name)),
ConfFile = filename:join([ResultsDir, Name, "config.conf"]),
AdvancedFile = filename:join([ResultsDir, Name, "advanced.config"]),

file:write_file(ConfFile, Conf),
rabbit_file:write_term_file(AdvancedFile, [Advanced]),
ok = file:write_file(ConfFile, Conf),
ok = rabbit_file:write_term_file(AdvancedFile, [Advanced]),
{ConfFile, AdvancedFile}.

generate_config(ConfFile, AdvancedFile) ->
Expand Down
9 changes: 4 additions & 5 deletions deps/rabbitmq_ct_helpers/src/rabbit_ct_helpers.erl
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ redirect_logger_to_ct_logs(Config) ->
ct:pal(
?LOW_IMPORTANCE,
"Configuring logger to send logs to common_test logs"),
logger:set_handler_config(cth_log_redirect, level, debug),
ok = logger:set_handler_config(cth_log_redirect, level, debug),

%% Let's use the same format as RabbitMQ itself.
logger:set_handler_config(
ok = logger:set_handler_config(
cth_log_redirect, formatter,
rabbit_prelaunch_early_logging:default_file_formatter(#{})),

Expand All @@ -170,7 +170,7 @@ redirect_logger_to_ct_logs(Config) ->
cth_log_redirect_any_domains, cth_log_redirect_any_domains,
LogCfg),

logger:remove_handler(default),
ok = logger:remove_handler(default),

ct:pal(
?LOW_IMPORTANCE,
Expand Down Expand Up @@ -686,7 +686,6 @@ load_elixir(Config) ->
ElixirLibDir ->
ct:pal(?LOW_IMPORTANCE, "Elixir lib dir: ~ts~n", [ElixirLibDir]),
true = code:add_pathz(ElixirLibDir),
application:load(elixir),
{ok, _} = application:ensure_all_started(elixir),
Config
end.
Expand Down Expand Up @@ -947,7 +946,7 @@ port_receive_loop(Port, Stdout, Options, Until, DumpTimer) ->
end,
receive
{Port, {exit_status, X}} ->
timer:cancel(DumpTimer),
_ = timer:cancel(DumpTimer),
DropStdout = lists:member(drop_stdout, Options) orelse
Stdout =:= "",
if
Expand Down
17 changes: 9 additions & 8 deletions deps/rabbitmq_ct_helpers/src/rabbit_ct_vm_helpers.erl
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ spawn_terraform_vms(Config) ->
rabbit_ct_helpers:register_teardown_steps(
Config1, teardown_steps());
_ ->
destroy_terraform_vms(Config),
_ = destroy_terraform_vms(Config),
{skip, "Terraform failed to spawn VM"}
end.

Expand All @@ -520,7 +520,7 @@ destroy_terraform_vms(Config) ->
] ++ TfVarFlags ++ [
TfConfigDir
],
rabbit_ct_helpers:exec(Cmd, [{env, Env}]),
{ok, _} = rabbit_ct_helpers:exec(Cmd, [{env, Env}]),
Config.

terraform_var_flags(Config) ->
Expand Down Expand Up @@ -696,7 +696,7 @@ ensure_instance_count(Config, TRef) ->
poll_vms(Config)
end;
true ->
timer:cancel(TRef),
_ = timer:cancel(TRef),
rabbit_ct_helpers:set_config(Config,
{terraform_poll_done, true})
end;
Expand Down Expand Up @@ -760,7 +760,7 @@ initialize_ct_peers(Config, NodenamesMap, IPAddrsMap) ->
set_inet_hosts(Config) ->
CTPeers = get_ct_peer_entries(Config),
inet_db:set_lookup([file, native]),
[begin
_ = [begin
Hostname = ?config(hostname, CTPeerConfig),
IPAddr = ?config(ipaddr, CTPeerConfig),
inet_db:add_host(IPAddr, [Hostname]),
Expand Down Expand Up @@ -831,7 +831,7 @@ wait_for_ct_peers(Config, [CTPeer | Rest] = CTPeers, TRef) ->
end
end;
wait_for_ct_peers(Config, [], TRef) ->
timer:cancel(TRef),
_ = timer:cancel(TRef),
Config.

set_ct_peers_code_path(Config) ->
Expand Down Expand Up @@ -864,7 +864,7 @@ download_dirs(Config) ->
?MODULE,
prepare_dirs_to_download_archives,
[Config]),
inets:start(),
ok = inets:start(),
download_dirs(Config, ConfigsPerCTPeer).

download_dirs(_, [{skip, _} = Error | _]) ->
Expand Down Expand Up @@ -964,7 +964,7 @@ add_archive_to_list(Config, Archive) ->
start_http_server(Config) ->
PrivDir = ?config(priv_dir, Config),
{ok, Hostname} = inet:gethostname(),
inets:start(),
ok = inets:start(),
Options = [{port, 0},
{server_name, Hostname},
{server_root, PrivDir},
Expand Down Expand Up @@ -1021,7 +1021,8 @@ do_setup_ct_logs_proxies(Nodes) ->
[begin
user_io_proxy(Node),
ct_logs_proxy(Node)
end || Node <- Nodes].
end || Node <- Nodes],
ok.

user_io_proxy(Node) ->
ok = setup_proxy(Node, user).
Expand Down
2 changes: 1 addition & 1 deletion deps/rabbitmq_ct_helpers/src/rabbit_mgmt_test_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ uri_base_from(Config, Node) ->
uri_base_from(Config, Node, Base) ->
Port = mgmt_port(Config, Node),
Prefix = get_uri_prefix(Config),
Uri = rabbit_mgmt_format:print("http://localhost:~w~ts/~ts", [Port, Prefix, Base]),
Uri = list_to_binary(lists:flatten(io_lib:format("http://localhost:~w~ts/~ts", [Port, Prefix, Base]))),
binary_to_list(Uri).

get_uri_prefix(Config) ->
Expand Down

0 comments on commit 9c41b2e

Please sign in to comment.