fix(test): change application:set_env/3 to emqx_config:put/2
This commit is contained in:
parent
5fd54d13d2
commit
c2e7acc1f1
|
@ -270,6 +270,9 @@ match_compact([Word | Words], Prefix, IsWildcard, Acc0) ->
|
||||||
is_compact() ->
|
is_compact() ->
|
||||||
emqx_config:get([broker, perf, trie_compaction], true).
|
emqx_config:get([broker, perf, trie_compaction], true).
|
||||||
|
|
||||||
|
set_compact(Bool) ->
|
||||||
|
emqx_config:put([broker, perf, trie_compaction], Bool).
|
||||||
|
|
||||||
-ifdef(TEST).
|
-ifdef(TEST).
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
|
@ -325,9 +328,6 @@ do_compact_test() ->
|
||||||
do_compact(words(<<"a/+/+/+/+/b">>))),
|
do_compact(words(<<"a/+/+/+/+/b">>))),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
set_compact(Bool) ->
|
|
||||||
emqx_config:put([broker, perf, trie_compaction], Bool).
|
|
||||||
|
|
||||||
clear_tables() -> ekka_mnesia:clear_table(?TRIE).
|
clear_tables() -> ekka_mnesia:clear_table(?TRIE).
|
||||||
|
|
||||||
-endif. % TEST
|
-endif. % TEST
|
||||||
|
|
|
@ -42,26 +42,26 @@ end_per_testcase(_TestCase, Config) ->
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
t_is_enabled(_) ->
|
t_is_enabled(_) ->
|
||||||
application:set_env(emqx, enable_session_registry, false),
|
emqx_config:put([broker, enable_session_registry], false),
|
||||||
?assertEqual(false, emqx_cm_registry:is_enabled()),
|
?assertEqual(false, emqx_cm_registry:is_enabled()),
|
||||||
application:set_env(emqx, enable_session_registry, true),
|
emqx_config:put([broker, enable_session_registry], true),
|
||||||
?assertEqual(true, emqx_cm_registry:is_enabled()).
|
?assertEqual(true, emqx_cm_registry:is_enabled()).
|
||||||
|
|
||||||
t_register_unregister_channel(_) ->
|
t_register_unregister_channel(_) ->
|
||||||
ClientId = <<"clientid">>,
|
ClientId = <<"clientid">>,
|
||||||
application:set_env(emqx, enable_session_registry, false),
|
emqx_config:put([broker, enable_session_registry], false),
|
||||||
emqx_cm_registry:register_channel(ClientId),
|
emqx_cm_registry:register_channel(ClientId),
|
||||||
?assertEqual([], emqx_cm_registry:lookup_channels(ClientId)),
|
?assertEqual([], emqx_cm_registry:lookup_channels(ClientId)),
|
||||||
|
|
||||||
application:set_env(emqx, enable_session_registry, true),
|
emqx_config:put([broker, enable_session_registry], true),
|
||||||
emqx_cm_registry:register_channel(ClientId),
|
emqx_cm_registry:register_channel(ClientId),
|
||||||
?assertEqual([self()], emqx_cm_registry:lookup_channels(ClientId)),
|
?assertEqual([self()], emqx_cm_registry:lookup_channels(ClientId)),
|
||||||
|
|
||||||
application:set_env(emqx, enable_session_registry, false),
|
emqx_config:put([broker, enable_session_registry], false),
|
||||||
emqx_cm_registry:unregister_channel(ClientId),
|
emqx_cm_registry:unregister_channel(ClientId),
|
||||||
?assertEqual([self()], emqx_cm_registry:lookup_channels(ClientId)),
|
?assertEqual([self()], emqx_cm_registry:lookup_channels(ClientId)),
|
||||||
|
|
||||||
application:set_env(emqx, enable_session_registry, true),
|
emqx_config:put([broker, enable_session_registry], true),
|
||||||
emqx_cm_registry:unregister_channel(ClientId),
|
emqx_cm_registry:unregister_channel(ClientId),
|
||||||
?assertEqual([], emqx_cm_registry:lookup_channels(ClientId)).
|
?assertEqual([], emqx_cm_registry:lookup_channels(ClientId)).
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
all() -> emqx_ct:all(?MODULE).
|
all() -> emqx_ct:all(?MODULE).
|
||||||
|
|
||||||
t_run_gc(_) ->
|
t_run_gc(_) ->
|
||||||
ok = application:set_env(emqx, global_gc_interval, 1),
|
ok = emqx_config:put([node, global_gc_interval], 1),
|
||||||
{ok, _} = emqx_global_gc:start_link(),
|
{ok, _} = emqx_global_gc:start_link(),
|
||||||
ok = timer:sleep(1500),
|
ok = timer:sleep(1500),
|
||||||
{ok, MilliSecs} = emqx_global_gc:run(),
|
{ok, MilliSecs} = emqx_global_gc:run(),
|
||||||
|
|
|
@ -786,7 +786,7 @@ t_shared_subscriptions_client_terminates_when_qos_eq_2('end', _Config) ->
|
||||||
t_shared_subscriptions_client_terminates_when_qos_eq_2(Config) ->
|
t_shared_subscriptions_client_terminates_when_qos_eq_2(Config) ->
|
||||||
ConnFun = ?config(conn_fun, Config),
|
ConnFun = ?config(conn_fun, Config),
|
||||||
process_flag(trap_exit, true),
|
process_flag(trap_exit, true),
|
||||||
application:set_env(emqx, shared_dispatch_ack_enabled, true),
|
emqx_config:put([broker, shared_dispatch_ack_enabled], true),
|
||||||
|
|
||||||
Topic = nth(1, ?TOPICS),
|
Topic = nth(1, ?TOPICS),
|
||||||
SharedTopic = list_to_binary("$share/sharename/" ++ binary_to_list(<<"TopicA">>)),
|
SharedTopic = list_to_binary("$share/sharename/" ++ binary_to_list(<<"TopicA">>)),
|
||||||
|
|
|
@ -40,17 +40,11 @@ init_per_suite(Config) ->
|
||||||
ct:pal("Executing ~s~n", [CmdPath]),
|
ct:pal("Executing ~s~n", [CmdPath]),
|
||||||
ct:pal("~n ~s~n", [os:cmd(CmdPath)]),
|
ct:pal("~n ~s~n", [os:cmd(CmdPath)]),
|
||||||
|
|
||||||
put(loaded_file, filename:join([DataPath, "loaded_plugins"])),
|
|
||||||
emqx_ct_helpers:boot_modules([]),
|
emqx_ct_helpers:boot_modules([]),
|
||||||
emqx_ct_helpers:start_apps([], fun(_) -> set_special_cfg(DataPath) end),
|
emqx_ct_helpers:start_apps([]),
|
||||||
|
emqx_config:put([plugins, expand_plugins_dir], DataPath),
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
set_special_cfg(PluginsDir) ->
|
|
||||||
application:set_env(emqx, plugins_loaded_file, get(loaded_file)),
|
|
||||||
application:set_env(emqx, expand_plugins_dir, PluginsDir),
|
|
||||||
ok.
|
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
emqx_ct_helpers:stop_apps([]).
|
emqx_ct_helpers:stop_apps([]).
|
||||||
|
|
||||||
|
@ -62,8 +56,7 @@ t_load(_) ->
|
||||||
?assertEqual({error, not_started}, emqx_plugins:unload(emqx_mini_plugin)),
|
?assertEqual({error, not_started}, emqx_plugins:unload(emqx_mini_plugin)),
|
||||||
?assertEqual({error, not_started}, emqx_plugins:unload(emqx_hocon_plugin)),
|
?assertEqual({error, not_started}, emqx_plugins:unload(emqx_hocon_plugin)),
|
||||||
|
|
||||||
application:set_env(emqx, expand_plugins_dir, undefined),
|
emqx_config:put([plugins, expand_plugins_dir], undefined).
|
||||||
application:set_env(emqx, plugins_loaded_file, undefined).
|
|
||||||
|
|
||||||
t_load_ext_plugin(_) ->
|
t_load_ext_plugin(_) ->
|
||||||
?assertError({plugin_app_file_not_found, _},
|
?assertError({plugin_app_file_not_found, _},
|
||||||
|
|
|
@ -322,8 +322,8 @@ ensure_config(Strategy) ->
|
||||||
ensure_config(Strategy, _AckEnabled = true).
|
ensure_config(Strategy, _AckEnabled = true).
|
||||||
|
|
||||||
ensure_config(Strategy, AckEnabled) ->
|
ensure_config(Strategy, AckEnabled) ->
|
||||||
application:set_env(emqx, shared_subscription_strategy, Strategy),
|
emqx_config:put([broker, shared_subscription_strategy], Strategy),
|
||||||
application:set_env(emqx, shared_dispatch_ack_enabled, AckEnabled),
|
emqx_config:put([broker, shared_dispatch_ack_enabled], AckEnabled),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
subscribed(Group, Topic, Pid) ->
|
subscribed(Group, Topic, Pid) ->
|
||||||
|
|
|
@ -25,8 +25,6 @@ all() -> emqx_ct:all(?MODULE).
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
application:load(emqx),
|
application:load(emqx),
|
||||||
ok = application:set_env(emqx, broker_sys_interval, 1),
|
|
||||||
ok = application:set_env(emqx, broker_sys_heartbeat, 1),
|
|
||||||
ok = emqx_logger:set_log_level(emergency),
|
ok = emqx_logger:set_log_level(emergency),
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
|
|
|
@ -34,14 +34,14 @@ groups() ->
|
||||||
[{compact, Cases}, {not_compact, Cases}].
|
[{compact, Cases}, {not_compact, Cases}].
|
||||||
|
|
||||||
init_per_group(compact, Config) ->
|
init_per_group(compact, Config) ->
|
||||||
emqx_trie:put_compaction_flag(true),
|
emqx_trie:set_compact(true),
|
||||||
Config;
|
Config;
|
||||||
init_per_group(not_compact, Config) ->
|
init_per_group(not_compact, Config) ->
|
||||||
emqx_trie:put_compaction_flag(false),
|
emqx_trie:set_compact(false),
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_group(_, _) ->
|
end_per_group(_, _) ->
|
||||||
emqx_trie:put_default_compaction_flag().
|
ok.
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
application:load(emqx),
|
application:load(emqx),
|
||||||
|
|
|
@ -65,9 +65,6 @@ init_per_suite(Config) ->
|
||||||
end_per_suite(_) ->
|
end_per_suite(_) ->
|
||||||
emqx_ct_helpers:stop_apps([emqx_gateway]).
|
emqx_ct_helpers:stop_apps([emqx_gateway]).
|
||||||
|
|
||||||
set_special_confs(emqx) ->
|
|
||||||
application:set_env(emqx, plugins_loaded_file,
|
|
||||||
emqx_ct_helpers:deps_path(emqx, "test/emqx_SUITE_data/loaded_plugins"));
|
|
||||||
set_special_confs(emqx_gateway) ->
|
set_special_confs(emqx_gateway) ->
|
||||||
emqx_config:put(
|
emqx_config:put(
|
||||||
[emqx_gateway],
|
[emqx_gateway],
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% Copyright (c) 2020-2021 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||||
|
%%
|
||||||
|
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
%% you may not use this file except in compliance with the License.
|
||||||
|
%% You may obtain a copy of the License at
|
||||||
|
%%
|
||||||
|
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
%%
|
||||||
|
%% Unless required by applicable law or agreed to in writing, software
|
||||||
|
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
%% See the License for the specific language governing permissions and
|
||||||
|
%% limitations under the License.
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
|
-module(emqx_telemetry_SUITE).
|
||||||
|
|
||||||
|
-compile(export_all).
|
||||||
|
-compile(nowarn_export_all).
|
||||||
|
|
||||||
|
-include_lib("common_test/include/ct.hrl").
|
||||||
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
|
||||||
|
|
||||||
|
-import(proplists, [get_value/2]).
|
||||||
|
|
||||||
|
all() -> emqx_ct:all(?MODULE).
|
||||||
|
|
||||||
|
init_per_testcase(_, Config) ->
|
||||||
|
emqx_ct_helpers:boot_modules(all),
|
||||||
|
emqx_ct_helpers:start_apps([emqx_telemetry]),
|
||||||
|
emqx_config:put([emqx_telemetry, enable], true),
|
||||||
|
Config.
|
||||||
|
|
||||||
|
end_per_testcase(_, _Config) ->
|
||||||
|
emqx_ct_helpers:stop_apps([emqx_telemetry]).
|
||||||
|
|
||||||
|
t_uuid(_) ->
|
||||||
|
UUID = emqx_telemetry:generate_uuid(),
|
||||||
|
Parts = binary:split(UUID, <<"-">>, [global, trim]),
|
||||||
|
?assertEqual(5, length(Parts)),
|
||||||
|
{ok, UUID2} = emqx_telemetry:get_uuid(),
|
||||||
|
emqx_telemetry:stop(),
|
||||||
|
emqx_telemetry:start_link([{enabled, true}]),
|
||||||
|
{ok, UUID3} = emqx_telemetry:get_uuid(),
|
||||||
|
?assertEqual(UUID2, UUID3).
|
||||||
|
|
||||||
|
t_official_version(_) ->
|
||||||
|
true = emqx_telemetry:official_version("0.0.0"),
|
||||||
|
true = emqx_telemetry:official_version("1.1.1"),
|
||||||
|
true = emqx_telemetry:official_version("10.10.10"),
|
||||||
|
false = emqx_telemetry:official_version("0.0.0.0"),
|
||||||
|
false = emqx_telemetry:official_version("1.1.a"),
|
||||||
|
true = emqx_telemetry:official_version("0.0-alpha.1"),
|
||||||
|
true = emqx_telemetry:official_version("1.1-alpha.1"),
|
||||||
|
true = emqx_telemetry:official_version("10.10-alpha.10"),
|
||||||
|
false = emqx_telemetry:official_version("1.1-alpha.0"),
|
||||||
|
true = emqx_telemetry:official_version("1.1-beta.1"),
|
||||||
|
true = emqx_telemetry:official_version("1.1-rc.1"),
|
||||||
|
false = emqx_telemetry:official_version("1.1-alpha.a").
|
||||||
|
|
||||||
|
t_get_telemetry(_) ->
|
||||||
|
{ok, TelemetryData} = emqx_telemetry:get_telemetry(),
|
||||||
|
OTPVersion = bin(erlang:system_info(otp_release)),
|
||||||
|
?assertEqual(OTPVersion, get_value(otp_version, TelemetryData)),
|
||||||
|
{ok, UUID} = emqx_telemetry:get_uuid(),
|
||||||
|
?assertEqual(UUID, get_value(uuid, TelemetryData)),
|
||||||
|
?assertEqual(0, get_value(num_clients, TelemetryData)).
|
||||||
|
|
||||||
|
t_enable(_) ->
|
||||||
|
ok = emqx_telemetry:enable(),
|
||||||
|
?assertEqual(true, emqx_telemetry:is_enabled()),
|
||||||
|
ok = emqx_telemetry:disable(),
|
||||||
|
?assertEqual(false, emqx_telemetry:is_enabled()).
|
||||||
|
|
||||||
|
t_send_after_enable(_) ->
|
||||||
|
ok = emqx_telemetry:disable(),
|
||||||
|
ok = snabbkaffe:start_trace(),
|
||||||
|
try
|
||||||
|
ok = emqx_telemetry:enable(),
|
||||||
|
?assertMatch({ok, _}, ?block_until(#{?snk_kind := telemetry_data_reported}, 2000, 100))
|
||||||
|
after
|
||||||
|
ok = snabbkaffe:stop()
|
||||||
|
end.
|
||||||
|
|
||||||
|
bin(L) when is_list(L) ->
|
||||||
|
list_to_binary(L);
|
||||||
|
bin(B) when is_binary(B) ->
|
||||||
|
B.
|
Loading…
Reference in New Issue