fix: failed ct test
This commit is contained in:
parent
7f870257b2
commit
fa753cf333
|
@ -27,7 +27,7 @@ all() ->
|
||||||
t_copy_conf_override_on_restarts(_Config) ->
|
t_copy_conf_override_on_restarts(_Config) ->
|
||||||
ct:timetrap({seconds, 120}),
|
ct:timetrap({seconds, 120}),
|
||||||
snabbkaffe:fix_ct_logging(),
|
snabbkaffe:fix_ct_logging(),
|
||||||
Cluster = cluster([core, core, core]),
|
Cluster = cluster([cluster_spec({core, 1}), cluster_spec({core, 2}), cluster_spec({core, 3})]),
|
||||||
|
|
||||||
%% 1. Start all nodes
|
%% 1. Start all nodes
|
||||||
Nodes = start_cluster(Cluster),
|
Nodes = start_cluster(Cluster),
|
||||||
|
@ -41,7 +41,7 @@ t_copy_conf_override_on_restarts(_Config) ->
|
||||||
%% crash and eventually all nodes should be ready.
|
%% crash and eventually all nodes should be ready.
|
||||||
start_cluster_async(Cluster),
|
start_cluster_async(Cluster),
|
||||||
|
|
||||||
timer:sleep(15_000),
|
timer:sleep(15000),
|
||||||
|
|
||||||
assert_config_load_done(Nodes),
|
assert_config_load_done(Nodes),
|
||||||
|
|
||||||
|
@ -50,11 +50,11 @@ t_copy_conf_override_on_restarts(_Config) ->
|
||||||
stop_cluster(Nodes)
|
stop_cluster(Nodes)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
t_copy_data_dir(_Config) ->
|
t_copy_new_data_dir(_Config) ->
|
||||||
net_kernel:start(['master1@127.0.0.1', longnames]),
|
net_kernel:start(['master1@127.0.0.1', longnames]),
|
||||||
ct:timetrap({seconds, 120}),
|
ct:timetrap({seconds, 120}),
|
||||||
snabbkaffe:fix_ct_logging(),
|
snabbkaffe:fix_ct_logging(),
|
||||||
Cluster = cluster([{core, copy1}, {core, copy2}, {core, copy3}]),
|
Cluster = cluster([cluster_spec({core, 4}), cluster_spec({core, 5}), cluster_spec({core, 6})]),
|
||||||
|
|
||||||
%% 1. Start all nodes
|
%% 1. Start all nodes
|
||||||
[First | Rest] = Nodes = start_cluster(Cluster),
|
[First | Rest] = Nodes = start_cluster(Cluster),
|
||||||
|
@ -66,7 +66,30 @@ t_copy_data_dir(_Config) ->
|
||||||
ok = rpc:call(First, application, start, [emqx_conf]),
|
ok = rpc:call(First, application, start, [emqx_conf]),
|
||||||
{[ok, ok], []} = rpc:multicall(Rest, application, start, [emqx_conf]),
|
{[ok, ok], []} = rpc:multicall(Rest, application, start, [emqx_conf]),
|
||||||
|
|
||||||
assert_data_copy_done(Nodes),
|
assert_data_copy_done(Nodes, "/configs/cluster.hocon"),
|
||||||
|
stop_cluster(Nodes),
|
||||||
|
ok
|
||||||
|
after
|
||||||
|
stop_cluster(Nodes)
|
||||||
|
end.
|
||||||
|
|
||||||
|
t_copy_deprecated_data_dir(_Config) ->
|
||||||
|
net_kernel:start(['master2@127.0.0.1', longnames]),
|
||||||
|
ct:timetrap({seconds, 120}),
|
||||||
|
snabbkaffe:fix_ct_logging(),
|
||||||
|
Cluster = cluster([cluster_spec({core, 7}), cluster_spec({core, 8}), cluster_spec({core, 9})]),
|
||||||
|
|
||||||
|
%% 1. Start all nodes
|
||||||
|
[First | Rest] = Nodes = start_cluster(Cluster),
|
||||||
|
try
|
||||||
|
assert_config_load_done(Nodes),
|
||||||
|
rpc:call(First, ?MODULE, create_deprecated_data_dir, []),
|
||||||
|
{[ok, ok, ok], []} = rpc:multicall(Nodes, application, stop, [emqx_conf]),
|
||||||
|
{[ok, ok, ok], []} = rpc:multicall(Nodes, ?MODULE, set_data_dir_env, []),
|
||||||
|
ok = rpc:call(First, application, start, [emqx_conf]),
|
||||||
|
{[ok, ok], []} = rpc:multicall(Rest, application, start, [emqx_conf]),
|
||||||
|
|
||||||
|
assert_data_copy_done(Nodes, "/configs/cluster-override.conf"),
|
||||||
stop_cluster(Nodes),
|
stop_cluster(Nodes),
|
||||||
ok
|
ok
|
||||||
after
|
after
|
||||||
|
@ -87,6 +110,16 @@ create_data_dir() ->
|
||||||
Telemetry = <<"telemetry.enable = false">>,
|
Telemetry = <<"telemetry.enable = false">>,
|
||||||
ok = file:write_file(Node ++ "/configs/cluster.hocon", Telemetry).
|
ok = file:write_file(Node ++ "/configs/cluster.hocon", Telemetry).
|
||||||
|
|
||||||
|
create_deprecated_data_dir() ->
|
||||||
|
Node = atom_to_list(node()),
|
||||||
|
ok = filelib:ensure_dir(Node ++ "/certs/"),
|
||||||
|
ok = filelib:ensure_dir(Node ++ "/authz/"),
|
||||||
|
ok = filelib:ensure_dir(Node ++ "/configs/"),
|
||||||
|
ok = file:write_file(Node ++ "/certs/fake-cert", list_to_binary(Node)),
|
||||||
|
ok = file:write_file(Node ++ "/authz/fake-authz", list_to_binary(Node)),
|
||||||
|
Telemetry = <<"telemetry.enable = false">>,
|
||||||
|
ok = file:write_file(Node ++ "/configs/cluster-override.conf", Telemetry).
|
||||||
|
|
||||||
set_data_dir_env() ->
|
set_data_dir_env() ->
|
||||||
Node = atom_to_list(node()),
|
Node = atom_to_list(node()),
|
||||||
%% will create certs and authz dir
|
%% will create certs and authz dir
|
||||||
|
@ -101,13 +134,14 @@ set_data_dir_env() ->
|
||||||
application:set_env(emqx, config_files, [NewConfigFile]),
|
application:set_env(emqx, config_files, [NewConfigFile]),
|
||||||
application:set_env(emqx, data_dir, Node),
|
application:set_env(emqx, data_dir, Node),
|
||||||
application:set_env(emqx, cluster_conf_file, Node ++ "/configs/cluster.hocon"),
|
application:set_env(emqx, cluster_conf_file, Node ++ "/configs/cluster.hocon"),
|
||||||
|
application:set_env(emqx, cluster_override_conf_file, Node ++ "/configs/cluster-override.conf"),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
assert_data_copy_done([First0 | Rest]) ->
|
assert_data_copy_done([First0 | Rest], File) ->
|
||||||
First = atom_to_list(First0),
|
First = atom_to_list(First0),
|
||||||
{ok, FakeCertFile} = file:read_file(First ++ "/certs/fake-cert"),
|
{ok, FakeCertFile} = file:read_file(First ++ "/certs/fake-cert"),
|
||||||
{ok, FakeAuthzFile} = file:read_file(First ++ "/authz/fake-authz"),
|
{ok, FakeAuthzFile} = file:read_file(First ++ "/authz/fake-authz"),
|
||||||
{ok, FakeOverrideFile} = file:read_file(First ++ "/configs/cluster.hocon"),
|
{ok, FakeOverrideFile} = file:read_file(First ++ File),
|
||||||
{ok, ExpectFake} = hocon:binary(FakeOverrideFile),
|
{ok, ExpectFake} = hocon:binary(FakeOverrideFile),
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun(Node0) ->
|
fun(Node0) ->
|
||||||
|
@ -119,7 +153,7 @@ assert_data_copy_done([First0 | Rest]) ->
|
||||||
),
|
),
|
||||||
?assertEqual(
|
?assertEqual(
|
||||||
{ok, ExpectFake},
|
{ok, ExpectFake},
|
||||||
hocon:files([Node ++ "/configs/cluster.hocon"]),
|
hocon:files([Node ++ File]),
|
||||||
#{node => Node}
|
#{node => Node}
|
||||||
),
|
),
|
||||||
?assertEqual(
|
?assertEqual(
|
||||||
|
@ -174,3 +208,6 @@ cluster(Specs) ->
|
||||||
ok
|
ok
|
||||||
end}
|
end}
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
cluster_spec({Type, Num}) ->
|
||||||
|
{Type, list_to_atom(atom_to_list(?MODULE) ++ integer_to_list(Num))}.
|
||||||
|
|
Loading…
Reference in New Issue