test(prometheus): update and simplify testsuites setup
This commit is contained in:
parent
a64850a84b
commit
ece1c6c6dc
|
@ -17,13 +17,12 @@
|
||||||
-module(emqx_prometheus_SUITE).
|
-module(emqx_prometheus_SUITE).
|
||||||
|
|
||||||
-include_lib("stdlib/include/assert.hrl").
|
-include_lib("stdlib/include/assert.hrl").
|
||||||
|
-include_lib("common_test/include/ct.hrl").
|
||||||
|
|
||||||
-compile(nowarn_export_all).
|
-compile(nowarn_export_all).
|
||||||
-compile(export_all).
|
-compile(export_all).
|
||||||
|
|
||||||
-define(CLUSTER_RPC_SHARD, emqx_cluster_rpc_shard).
|
|
||||||
-define(LEGACY_CONF_DEFAULT, <<
|
-define(LEGACY_CONF_DEFAULT, <<
|
||||||
"\n"
|
|
||||||
"prometheus {\n"
|
"prometheus {\n"
|
||||||
" push_gateway_server = \"http://127.0.0.1:9091\"\n"
|
" push_gateway_server = \"http://127.0.0.1:9091\"\n"
|
||||||
" interval = \"1s\"\n"
|
" interval = \"1s\"\n"
|
||||||
|
@ -38,6 +37,7 @@
|
||||||
" vm_msacc_collector = disabled\n"
|
" vm_msacc_collector = disabled\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
>>).
|
>>).
|
||||||
|
|
||||||
-define(CONF_DEFAULT, #{
|
-define(CONF_DEFAULT, #{
|
||||||
<<"prometheus">> =>
|
<<"prometheus">> =>
|
||||||
#{
|
#{
|
||||||
|
@ -84,40 +84,29 @@ common_tests() ->
|
||||||
emqx_common_test_helpers:all(?MODULE).
|
emqx_common_test_helpers:all(?MODULE).
|
||||||
|
|
||||||
init_per_group(new_config, Config) ->
|
init_per_group(new_config, Config) ->
|
||||||
init_group(),
|
Apps = emqx_cth_suite:start(
|
||||||
load_config(),
|
[
|
||||||
emqx_common_test_helpers:start_apps([emqx_prometheus]),
|
%% coverage olp metrics
|
||||||
%% coverage olp metrics
|
{emqx, "overload_protection.enable = true"},
|
||||||
{ok, _} = emqx:update_config([overload_protection, enable], true),
|
{emqx_license, "license.key = default"},
|
||||||
Config;
|
{emqx_prometheus, #{config => config(default)}}
|
||||||
|
],
|
||||||
|
#{work_dir => emqx_cth_suite:work_dir(Config)}
|
||||||
|
),
|
||||||
|
[{suite_apps, Apps} | Config];
|
||||||
init_per_group(legacy_config, Config) ->
|
init_per_group(legacy_config, Config) ->
|
||||||
init_group(),
|
Apps = emqx_cth_suite:start(
|
||||||
load_legacy_config(),
|
[
|
||||||
emqx_common_test_helpers:start_apps([emqx_prometheus]),
|
{emqx, "overload_protection.enable = false"},
|
||||||
{ok, _} = emqx:update_config([overload_protection, enable], false),
|
{emqx_license, "license.key = default"},
|
||||||
Config.
|
{emqx_prometheus, #{config => config(legacy)}}
|
||||||
|
],
|
||||||
init_group() ->
|
#{work_dir => emqx_cth_suite:work_dir(Config)}
|
||||||
application:load(emqx_conf),
|
),
|
||||||
ok = ekka:start(),
|
[{suite_apps, Apps} | Config].
|
||||||
ok = mria_rlog:wait_for_shards([?CLUSTER_RPC_SHARD], infinity),
|
|
||||||
meck:new(emqx_alarm, [non_strict, passthrough, no_link]),
|
|
||||||
meck:expect(emqx_alarm, activate, 3, ok),
|
|
||||||
meck:expect(emqx_alarm, deactivate, 3, ok),
|
|
||||||
meck:new(emqx_license_checker, [non_strict, passthrough, no_link]),
|
|
||||||
meck:expect(emqx_license_checker, expiry_epoch, fun() -> 1859673600 end).
|
|
||||||
|
|
||||||
end_group() ->
|
|
||||||
ekka:stop(),
|
|
||||||
mria:stop(),
|
|
||||||
mria_mnesia:delete_schema(),
|
|
||||||
meck:unload(emqx_alarm),
|
|
||||||
meck:unload(emqx_license_checker),
|
|
||||||
emqx_common_test_helpers:stop_apps([emqx_prometheus]).
|
|
||||||
|
|
||||||
end_per_group(_Group, Config) ->
|
end_per_group(_Group, Config) ->
|
||||||
end_group(),
|
ok = emqx_cth_suite:stop(?config(suite_apps, Config)).
|
||||||
Config.
|
|
||||||
|
|
||||||
init_per_testcase(t_assert_push, Config) ->
|
init_per_testcase(t_assert_push, Config) ->
|
||||||
meck:new(httpc, [passthrough]),
|
meck:new(httpc, [passthrough]),
|
||||||
|
@ -137,11 +126,10 @@ end_per_testcase(t_assert_push, _Config) ->
|
||||||
end_per_testcase(_Testcase, _Config) ->
|
end_per_testcase(_Testcase, _Config) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
load_config() ->
|
config(default) ->
|
||||||
ok = emqx_common_test_helpers:load_config(emqx_prometheus_schema, ?CONF_DEFAULT).
|
?CONF_DEFAULT;
|
||||||
|
config(legacy) ->
|
||||||
load_legacy_config() ->
|
?LEGACY_CONF_DEFAULT.
|
||||||
ok = emqx_common_test_helpers:load_config(emqx_prometheus_schema, ?LEGACY_CONF_DEFAULT).
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Test cases
|
%% Test cases
|
||||||
|
|
|
@ -21,9 +21,6 @@
|
||||||
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
-include_lib("common_test/include/ct.hrl").
|
-include_lib("common_test/include/ct.hrl").
|
||||||
-define(CLUSTER_RPC_SHARD, emqx_cluster_rpc_shard).
|
|
||||||
|
|
||||||
-define(LOGT(Format, Args), ct:pal("TEST_SUITE: " ++ Format, Args)).
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Setups
|
%% Setups
|
||||||
|
@ -41,41 +38,38 @@ groups() ->
|
||||||
].
|
].
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
emqx_prometheus_SUITE:init_group(),
|
Apps = emqx_cth_suite:start(
|
||||||
emqx_mgmt_api_test_util:init_suite([emqx_conf]),
|
[
|
||||||
Config.
|
emqx,
|
||||||
|
emqx_conf,
|
||||||
|
emqx_management,
|
||||||
|
{emqx_prometheus, #{start => false}},
|
||||||
|
{emqx_dashboard, "dashboard.listeners.http { enable = true, bind = 18083 }"},
|
||||||
|
{emqx_license, "license.key = default"}
|
||||||
|
],
|
||||||
|
#{work_dir => emqx_cth_suite:work_dir(Config)}
|
||||||
|
),
|
||||||
|
{ok, _} = emqx_common_test_http:create_default_app(),
|
||||||
|
[{suite_apps, Apps} | Config].
|
||||||
|
|
||||||
end_per_suite(Config) ->
|
end_per_suite(Config) ->
|
||||||
emqx_prometheus_SUITE:end_group(),
|
ok = emqx_cth_suite:stop(?config(suite_apps, Config)).
|
||||||
emqx_mgmt_api_test_util:end_suite([emqx_conf]),
|
|
||||||
Config.
|
|
||||||
|
|
||||||
init_per_group(new_config, Config) ->
|
init_per_group(new_config, Config) ->
|
||||||
emqx_common_test_helpers:start_apps(
|
Apps = emqx_cth_suite:start_app(
|
||||||
[emqx_prometheus],
|
emqx_prometheus,
|
||||||
fun(App) -> set_special_configs(App, new_config) end
|
#{config => emqx_prometheus_SUITE:config(default)}
|
||||||
),
|
),
|
||||||
Config;
|
[{group_apps, Apps} | Config];
|
||||||
init_per_group(legacy_config, Config) ->
|
init_per_group(legacy_config, Config) ->
|
||||||
emqx_common_test_helpers:start_apps(
|
Apps = emqx_cth_suite:start_app(
|
||||||
[emqx_prometheus],
|
emqx_prometheus,
|
||||||
fun(App) -> set_special_configs(App, legacy_config) end
|
#{config => emqx_prometheus_SUITE:config(legacy)}
|
||||||
),
|
),
|
||||||
Config.
|
[{group_apps, Apps} | Config].
|
||||||
|
|
||||||
end_per_group(_Group, Config) ->
|
end_per_group(_Group, Config) ->
|
||||||
_ = application:stop(emqx_prometheus),
|
ok = emqx_cth_suite:stop_apps(?config(group_apps, Config)).
|
||||||
Config.
|
|
||||||
|
|
||||||
set_special_configs(emqx_dashboard, _) ->
|
|
||||||
emqx_dashboard_api_test_helpers:set_default_config();
|
|
||||||
set_special_configs(emqx_prometheus, new_config) ->
|
|
||||||
emqx_prometheus_SUITE:load_config(),
|
|
||||||
ok;
|
|
||||||
set_special_configs(emqx_prometheus, legacy_config) ->
|
|
||||||
emqx_prometheus_SUITE:load_legacy_config(),
|
|
||||||
ok;
|
|
||||||
set_special_configs(_App, _) ->
|
|
||||||
ok.
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Cases
|
%% Cases
|
||||||
|
|
Loading…
Reference in New Issue