|
|
@@ -224,8 +224,8 @@ t_callback_crash(_Config) ->
|
|
|
ok = emqx_config_handler:remove_handler(CrashPath),
|
|
|
ok.
|
|
|
|
|
|
-t_pre_callback_error(_Config) ->
|
|
|
- callback_error(
|
|
|
+t_pre_assert_update_result(_Config) ->
|
|
|
+ assert_update_result(
|
|
|
[sysmon, os, mem_check_interval],
|
|
|
<<"100s">>,
|
|
|
{error, {pre_config_update, ?MODULE, pre_config_update_error}}
|
|
|
@@ -233,7 +233,7 @@ t_pre_callback_error(_Config) ->
|
|
|
ok.
|
|
|
|
|
|
t_post_update_error(_Config) ->
|
|
|
- callback_error(
|
|
|
+ assert_update_result(
|
|
|
[sysmon, os, sysmem_high_watermark],
|
|
|
<<"60%">>,
|
|
|
{error, {post_config_update, ?MODULE, post_config_update_error}}
|
|
|
@@ -243,7 +243,7 @@ t_post_update_error(_Config) ->
|
|
|
t_post_update_propagate_error_wkey(_Config) ->
|
|
|
Conf0 = emqx_config:get_raw([sysmon]),
|
|
|
Conf1 = emqx_utils_maps:deep_put([<<"os">>, <<"sysmem_high_watermark">>], Conf0, <<"60%">>),
|
|
|
- callback_error(
|
|
|
+ assert_update_result(
|
|
|
[
|
|
|
[sysmon, '?', sysmem_high_watermark],
|
|
|
[sysmon]
|
|
|
@@ -257,7 +257,7 @@ t_post_update_propagate_error_wkey(_Config) ->
|
|
|
t_post_update_propagate_error_key(_Config) ->
|
|
|
Conf0 = emqx_config:get_raw([sysmon]),
|
|
|
Conf1 = emqx_utils_maps:deep_put([<<"os">>, <<"sysmem_high_watermark">>], Conf0, <<"60%">>),
|
|
|
- callback_error(
|
|
|
+ assert_update_result(
|
|
|
[
|
|
|
[sysmon, os, sysmem_high_watermark],
|
|
|
[sysmon]
|
|
|
@@ -271,7 +271,7 @@ t_post_update_propagate_error_key(_Config) ->
|
|
|
t_pre_update_propagate_error_wkey(_Config) ->
|
|
|
Conf0 = emqx_config:get_raw([sysmon]),
|
|
|
Conf1 = emqx_utils_maps:deep_put([<<"os">>, <<"mem_check_interval">>], Conf0, <<"70s">>),
|
|
|
- callback_error(
|
|
|
+ assert_update_result(
|
|
|
[
|
|
|
[sysmon, '?', mem_check_interval],
|
|
|
[sysmon]
|
|
|
@@ -285,7 +285,7 @@ t_pre_update_propagate_error_wkey(_Config) ->
|
|
|
t_pre_update_propagate_error_key(_Config) ->
|
|
|
Conf0 = emqx_config:get_raw([sysmon]),
|
|
|
Conf1 = emqx_utils_maps:deep_put([<<"os">>, <<"mem_check_interval">>], Conf0, <<"70s">>),
|
|
|
- callback_error(
|
|
|
+ assert_update_result(
|
|
|
[
|
|
|
[sysmon, os, mem_check_interval],
|
|
|
[sysmon]
|
|
|
@@ -296,6 +296,25 @@ t_pre_update_propagate_error_key(_Config) ->
|
|
|
),
|
|
|
ok.
|
|
|
|
|
|
+t_pre_update_propagate_key_rewrite(_Config) ->
|
|
|
+ Conf0 = emqx_config:get_raw([sysmon]),
|
|
|
+ Conf1 = emqx_utils_maps:deep_put([<<"os">>, <<"cpu_check_interval">>], Conf0, <<"333s">>),
|
|
|
+ with_update_result(
|
|
|
+ [
|
|
|
+ [sysmon, '?', cpu_check_interval],
|
|
|
+ [sysmon]
|
|
|
+ ],
|
|
|
+ [sysmon],
|
|
|
+ Conf1,
|
|
|
+ fun(_, Result) ->
|
|
|
+ ?assertMatch(
|
|
|
+ {ok, #{config := #{os := #{cpu_check_interval := 444000}}}},
|
|
|
+ Result
|
|
|
+ )
|
|
|
+ end
|
|
|
+ ),
|
|
|
+ ok.
|
|
|
+
|
|
|
t_handler_root() ->
|
|
|
%% Don't rely on default emqx_config_handler's merge behaviour.
|
|
|
RootKey = [],
|
|
|
@@ -352,6 +371,8 @@ pre_config_update([sysmon, os, sysmem_high_watermark], UpdateReq, _RawConf) ->
|
|
|
pre_config_update([sysmon, os, mem_check_interval], _UpdateReq, _RawConf) ->
|
|
|
{error, pre_config_update_error}.
|
|
|
|
|
|
+propagated_pre_config_update([sysmon, os, cpu_check_interval], <<"333s">>, _RawConf) ->
|
|
|
+ {ok, <<"444s">>};
|
|
|
propagated_pre_config_update([sysmon, os, mem_check_interval], _UpdateReq, _RawConf) ->
|
|
|
{error, pre_config_update_error};
|
|
|
propagated_pre_config_update(_ConfKeyPath, _UpdateReq, _RawConf) ->
|
|
|
@@ -386,27 +407,32 @@ wait_for_new_pid() ->
|
|
|
Pid
|
|
|
end.
|
|
|
|
|
|
-callback_error(FailedPath, Update, ExpectError) ->
|
|
|
- callback_error([FailedPath], FailedPath, Update, ExpectError).
|
|
|
-
|
|
|
-callback_error(Paths, UpdatePath, Update, ExpectError) ->
|
|
|
+assert_update_result(FailedPath, Update, Expect) ->
|
|
|
+ assert_update_result([FailedPath], FailedPath, Update, Expect).
|
|
|
+
|
|
|
+assert_update_result(Paths, UpdatePath, Update, Expect) ->
|
|
|
+ with_update_result(Paths, UpdatePath, Update, fun(Old, Result) ->
|
|
|
+ case Expect of
|
|
|
+ {error, {post_config_update, ?MODULE, post_config_update_error}} ->
|
|
|
+ ?assertMatch(
|
|
|
+ {error, {post_config_update, ?MODULE, {post_config_update_error, _}}}, Result
|
|
|
+ );
|
|
|
+ _ ->
|
|
|
+ ?assertEqual(Expect, Result)
|
|
|
+ end,
|
|
|
+ New = emqx:get_raw_config(UpdatePath, undefined),
|
|
|
+ ?assertEqual(Old, New)
|
|
|
+ end).
|
|
|
+
|
|
|
+with_update_result(Paths, UpdatePath, Update, Fun) ->
|
|
|
ok = lists:foreach(
|
|
|
fun(Path) -> emqx_config_handler:add_handler(Path, ?MODULE) end,
|
|
|
Paths
|
|
|
),
|
|
|
Opts = #{rawconf_with_defaults => true},
|
|
|
Old = emqx:get_raw_config(UpdatePath, undefined),
|
|
|
- Error = emqx:update_config(UpdatePath, Update, Opts),
|
|
|
- case ExpectError of
|
|
|
- {error, {post_config_update, ?MODULE, post_config_update_error}} ->
|
|
|
- ?assertMatch(
|
|
|
- {error, {post_config_update, ?MODULE, {post_config_update_error, _}}}, Error
|
|
|
- );
|
|
|
- _ ->
|
|
|
- ?assertEqual(ExpectError, Error)
|
|
|
- end,
|
|
|
- New = emqx:get_raw_config(UpdatePath, undefined),
|
|
|
- ?assertEqual(Old, New),
|
|
|
+ Result = emqx:update_config(UpdatePath, Update, Opts),
|
|
|
+ _ = Fun(Old, Result),
|
|
|
ok = lists:foreach(
|
|
|
fun(Path) -> emqx_config_handler:remove_handler(Path) end,
|
|
|
Paths
|