Skip to content

Commit

Permalink
test: add copy data dir test case
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongwencool committed Dec 5, 2022
1 parent 9b37837 commit 64ab4ca
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
69 changes: 69 additions & 0 deletions apps/emqx_conf/test/emqx_conf_app_SUITE.erl
Expand Up @@ -54,10 +54,78 @@ t_copy_conf_override_on_restarts(_Config) ->
stop_cluster(Nodes)
end.

t_copy_data_dir(_Config) ->
net_kernel:start(['master1@127.0.0.1', longnames]),
ct:timetrap({seconds, 120}),
snabbkaffe:fix_ct_logging(),
Cluster = cluster([{core, copy1}, {core, copy2}, {core, copy3}]),

%% 1. Start all nodes
[First | Rest] = Nodes = start_cluster(Cluster),
try
assert_config_load_done(Nodes),
rpc:call(First, ?MODULE, create_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),
stop_cluster(Nodes),
ok
after
stop_cluster(Nodes)
end.

%%------------------------------------------------------------------------------
%% Helper functions
%%------------------------------------------------------------------------------

create_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() ->
Node = atom_to_list(node()),
%% will create certs and authz dir
ok = filelib:ensure_dir(Node ++ "/configs/"),
application:set_env(emqx, data_dir, Node),
application:set_env(emqx, cluster_override_conf_file, Node ++ "/configs/cluster-override.conf"),
ok.

assert_data_copy_done([First0 | Rest]) ->
First = atom_to_list(First0),
{ok, FakeCertFile} = file:read_file(First ++ "/certs/fake-cert"),
{ok, FakeAuthzFile} = file:read_file(First ++ "/authz/fake-authz"),
{ok, FakeOverrideFile} = file:read_file(First ++ "/configs/cluster-override.conf"),
lists:foreach(
fun(Node0) ->
Node = atom_to_list(Node0),
?assertEqual(
{ok, FakeCertFile},
file:read_file(Node ++ "/certs/fake-cert"),
#{node => Node}
),
?assertEqual(
{ok, FakeOverrideFile},
file:read_file(Node ++ "/configs/cluster-override.conf"),
#{node => Node}
),
?assertEqual(
{ok, FakeAuthzFile},
file:read_file(Node ++ "/authz/fake-authz"),
#{node => Node}
)
end,
Rest
).

assert_config_load_done(Nodes) ->
lists:foreach(
fun(Node) ->
Expand Down Expand Up @@ -96,6 +164,7 @@ cluster(Specs) ->
{env_handler, fun
(emqx) ->
application:set_env(emqx, boot_modules, []),
io:format("~p~p~n", [node(), application:get_all_env(emqx)]),
ok;
(_) ->
ok
Expand Down
2 changes: 2 additions & 0 deletions changes/v5.0.12-en.md
Expand Up @@ -13,6 +13,8 @@

- Add `limiter` update API [#9133](https://github.com/emqx/emqx/pull/9133).

- Avoid creating temporary zip files when syncing data directory during cluster startup [#9429](https://github.com/emqx/emqx/pull/9429).

## Bug fixes

- Fix that the obsolete SSL files aren't deleted after the ExHook config update [#9432](https://github.com/emqx/emqx/pull/9432).
2 changes: 2 additions & 0 deletions changes/v5.0.12-zh.md
Expand Up @@ -13,6 +13,8 @@

- 添加 `limiter` 更新 API [#9133](https://github.com/emqx/emqx/pull/9133)

- EMQX 集群启动时同步 data 目录不需要在磁盘上产生临时的zip文件 [#9429](https://github.com/emqx/emqx/pull/9429)

## 修复

- 修复 ExHook 更新 SSL 相关配置后,过时的 SSL 文件没有被删除的问题 [#9432](https://github.com/emqx/emqx/pull/9432)

0 comments on commit 64ab4ca

Please sign in to comment.