fix: ct failed again

This commit is contained in:
Zhongwen Deng 2022-05-31 19:20:09 +08:00
parent fe5998d773
commit d61b44ef97
11 changed files with 71 additions and 16 deletions

View File

@ -22,6 +22,7 @@
-export([ -export([
init_load/1, init_load/1,
init_load/2, init_load/2,
init_load/3,
read_override_conf/1, read_override_conf/1,
delete_override_conf_files/0, delete_override_conf_files/0,
check_config/2, check_config/2,

View File

@ -51,6 +51,7 @@
render_config_file/2, render_config_file/2,
read_schema_configs/2, read_schema_configs/2,
load_config/2, load_config/2,
load_config/3,
is_tcp_server_available/2, is_tcp_server_available/2,
is_tcp_server_available/3 is_tcp_server_available/3
]). ]).
@ -465,11 +466,19 @@ copy_certs(emqx_conf, Dest0) ->
copy_certs(_, _) -> copy_certs(_, _) ->
ok. ok.
load_config(SchemaModule, Config) -> load_config(SchemaModule, Config, Opts) ->
ConfigBin =
case is_map(Config) of
true -> jsx:encode(Config);
false -> Config
end,
ok = emqx_config:delete_override_conf_files(), ok = emqx_config:delete_override_conf_files(),
ok = emqx_config:init_load(SchemaModule, Config), ok = emqx_config:init_load(SchemaModule, ConfigBin, Opts),
ok. ok.
load_config(SchemaModule, Config) ->
load_config(SchemaModule, Config, #{raw_with_default => false}).
-spec is_tcp_server_available( -spec is_tcp_server_available(
Host :: inet:socket_address() | inet:hostname(), Host :: inet:socket_address() | inet:hostname(),
Port :: inet:port_number() Port :: inet:port_number()

View File

@ -142,8 +142,9 @@ setup_fake_telemetry_data() ->
} }
} }
}, },
ok = emqx_common_test_helpers:load_config(emqx_connector_schema, ConnectorConf), Opts = #{raw_with_default => true},
ok = emqx_common_test_helpers:load_config(emqx_bridge_schema, Conf), ok = emqx_common_test_helpers:load_config(emqx_connector_schema, ConnectorConf, Opts),
ok = emqx_common_test_helpers:load_config(emqx_bridge_schema, Conf, Opts),
ok = snabbkaffe:start_trace(), ok = snabbkaffe:start_trace(),
Predicate = fun(#{?snk_kind := K}) -> K =:= emqx_bridge_monitor_loaded_bridge end, Predicate = fun(#{?snk_kind := K}) -> K =:= emqx_bridge_monitor_loaded_bridge end,

View File

@ -32,7 +32,9 @@ all() ->
emqx_common_test_helpers:all(?MODULE). emqx_common_test_helpers:all(?MODULE).
init_per_suite(Config) -> init_per_suite(Config) ->
ok = emqx_common_test_helpers:load_config(emqx_modules_schema, ?BASE_CONF), ok = emqx_common_test_helpers:load_config(emqx_modules_schema, jsx:encode(?BASE_CONF), #{
raw_with_default => true
}),
ok = emqx_common_test_helpers:start_apps( ok = emqx_common_test_helpers:start_apps(
[emqx_conf, emqx_modules, emqx_dashboard], [emqx_conf, emqx_modules, emqx_dashboard],

View File

@ -29,7 +29,9 @@ all() ->
emqx_common_test_helpers:all(?MODULE). emqx_common_test_helpers:all(?MODULE).
init_per_suite(Conf) -> init_per_suite(Conf) ->
emqx_common_test_helpers:load_config(emqx_modules_schema, <<"gateway {}">>), emqx_common_test_helpers:load_config(emqx_modules_schema, <<"gateway {}">>, #{
raw_with_default => true
}),
emqx_common_test_helpers:start_apps([emqx_conf, emqx_modules]), emqx_common_test_helpers:start_apps([emqx_conf, emqx_modules]),
Conf. Conf.

View File

@ -157,13 +157,17 @@ t_rewrite_re_error(_Config) ->
ok. ok.
t_list(_Config) -> t_list(_Config) ->
ok = emqx_common_test_helpers:load_config(emqx_modules_schema, ?REWRITE), ok = emqx_common_test_helpers:load_config(emqx_modules_schema, jsx:encode(?REWRITE), #{
raw_with_default => true
}),
Expect = maps:get(<<"rewrite">>, ?REWRITE), Expect = maps:get(<<"rewrite">>, ?REWRITE),
?assertEqual(Expect, emqx_rewrite:list()), ?assertEqual(Expect, emqx_rewrite:list()),
ok. ok.
t_update(_Config) -> t_update(_Config) ->
ok = emqx_common_test_helpers:load_config(emqx_modules_schema, ?REWRITE), ok = emqx_common_test_helpers:load_config(emqx_modules_schema, jsx:encode(?REWRITE), #{
raw_with_default => true
}),
Init = emqx_rewrite:list(), Init = emqx_rewrite:list(),
Rules = [ Rules = [
#{ #{
@ -179,7 +183,9 @@ t_update(_Config) ->
ok. ok.
t_update_disable(_Config) -> t_update_disable(_Config) ->
ok = emqx_common_test_helpers:load_config(emqx_modules_schema, ?REWRITE), ok = emqx_common_test_helpers:load_config(emqx_modules_schema, jsx:encode(?REWRITE), #{
raw_with_default => true
}),
?assertEqual(ok, emqx_rewrite:update([])), ?assertEqual(ok, emqx_rewrite:update([])),
timer:sleep(150), timer:sleep(150),
@ -194,7 +200,9 @@ t_update_disable(_Config) ->
ok. ok.
t_update_re_failed(_Config) -> t_update_re_failed(_Config) ->
ok = emqx_common_test_helpers:load_config(emqx_modules_schema, ?REWRITE), ok = emqx_common_test_helpers:load_config(emqx_modules_schema, jsx:encode(?REWRITE), #{
raw_with_default => true
}),
Re = <<"*^test/*">>, Re = <<"*^test/*">>,
Rules = [ Rules = [
#{ #{
@ -249,7 +257,9 @@ receive_publish(Timeout) ->
end. end.
init() -> init() ->
ok = emqx_common_test_helpers:load_config(emqx_modules_schema, ?REWRITE), ok = emqx_common_test_helpers:load_config(emqx_modules_schema, jsx:encode(?REWRITE), #{
raw_with_default => true
}),
ok = emqx_rewrite:enable(), ok = emqx_rewrite:enable(),
{ok, C} = emqtt:start_link([{clientid, <<"c1">>}, {username, <<"u1">>}]), {ok, C} = emqtt:start_link([{clientid, <<"c1">>}, {username, <<"u1">>}]),
{ok, _} = emqtt:connect(C), {ok, _} = emqtt:connect(C),

View File

@ -33,7 +33,9 @@ init_per_testcase(_, Config) ->
Config. Config.
init_per_suite(Config) -> init_per_suite(Config) ->
ok = emqx_common_test_helpers:load_config(emqx_modules_schema, ?BASE_CONF), ok = emqx_common_test_helpers:load_config(emqx_modules_schema, jsx:encode(?BASE_CONF), #{
raw_with_default => true
}),
ok = emqx_common_test_helpers:start_apps( ok = emqx_common_test_helpers:start_apps(
[emqx_conf, emqx_modules, emqx_dashboard], [emqx_conf, emqx_modules, emqx_dashboard],

View File

@ -25,6 +25,11 @@
-import(proplists, [get_value/2]). -import(proplists, [get_value/2]).
-define(BASE_CONF, #{
<<"dealyed">> => <<"true">>,
<<"max_delayed_messages">> => <<"0">>
}).
all() -> emqx_common_test_helpers:all(?MODULE). all() -> emqx_common_test_helpers:all(?MODULE).
init_per_suite(Config) -> init_per_suite(Config) ->
@ -36,6 +41,9 @@ init_per_suite(Config) ->
emqx_common_test_helpers:deps_path(emqx_authz, "etc/acl.conf") emqx_common_test_helpers:deps_path(emqx_authz, "etc/acl.conf")
end end
), ),
ok = emqx_common_test_helpers:load_config(emqx_modules_schema, jsx:encode(?BASE_CONF), #{
raw_with_default => true
}),
emqx_common_test_helpers:start_apps( emqx_common_test_helpers:start_apps(
[emqx_conf, emqx_authn, emqx_authz, emqx_modules], [emqx_conf, emqx_authn, emqx_authz, emqx_modules],
fun set_special_configs/1 fun set_special_configs/1
@ -144,7 +152,9 @@ init_per_testcase(t_exhook_info, Config) ->
{ok, _} = emqx_exhook_demo_svr:start(), {ok, _} = emqx_exhook_demo_svr:start(),
{ok, Sock} = gen_tcp:connect("localhost", 9000, [], 3000), {ok, Sock} = gen_tcp:connect("localhost", 9000, [], 3000),
_ = gen_tcp:close(Sock), _ = gen_tcp:close(Sock),
ok = emqx_common_test_helpers:load_config(emqx_exhook_schema, ExhookConf), ok = emqx_common_test_helpers:load_config(emqx_exhook_schema, ExhookConf, #{
raw_with_default => true
}),
{ok, _} = application:ensure_all_started(emqx_exhook), {ok, _} = application:ensure_all_started(emqx_exhook),
Config; Config;
init_per_testcase(t_cluster_uuid, Config) -> init_per_testcase(t_cluster_uuid, Config) ->
@ -166,6 +176,9 @@ init_per_testcase(t_uuid_restored_from_file, Config) ->
%% clear the UUIDs in the DB %% clear the UUIDs in the DB
{atomic, ok} = mria:clear_table(emqx_telemetry), {atomic, ok} = mria:clear_table(emqx_telemetry),
emqx_common_test_helpers:stop_apps([emqx_conf, emqx_authn, emqx_authz, emqx_modules]), emqx_common_test_helpers:stop_apps([emqx_conf, emqx_authn, emqx_authz, emqx_modules]),
ok = emqx_common_test_helpers:load_config(emqx_modules_schema, jsx:encode(?BASE_CONF), #{
raw_with_default => true
}),
emqx_common_test_helpers:start_apps( emqx_common_test_helpers:start_apps(
[emqx_conf, emqx_authn, emqx_authz, emqx_modules], [emqx_conf, emqx_authn, emqx_authz, emqx_modules],
fun set_special_configs/1 fun set_special_configs/1
@ -319,6 +332,9 @@ t_uuid_saved_to_file(_Config) ->
%% clear the UUIDs in the DB %% clear the UUIDs in the DB
{atomic, ok} = mria:clear_table(emqx_telemetry), {atomic, ok} = mria:clear_table(emqx_telemetry),
emqx_common_test_helpers:stop_apps([emqx_conf, emqx_authn, emqx_authz, emqx_modules]), emqx_common_test_helpers:stop_apps([emqx_conf, emqx_authn, emqx_authz, emqx_modules]),
ok = emqx_common_test_helpers:load_config(emqx_modules_schema, jsx:encode(?BASE_CONF), #{
raw_with_default => true
}),
emqx_common_test_helpers:start_apps( emqx_common_test_helpers:start_apps(
[emqx_conf, emqx_authn, emqx_authz, emqx_modules], [emqx_conf, emqx_authn, emqx_authz, emqx_modules],
fun set_special_configs/1 fun set_special_configs/1
@ -841,6 +857,12 @@ setup_slave(Node) ->
(_) -> (_) ->
ok ok
end, end,
ok = rpc:call(
Node,
emqx_common_test_helpers,
load_config,
[emqx_modules_schema, jsx:encode(?BASE_CONF), #{raw_with_default => true}]
),
ok = rpc:call( ok = rpc:call(
Node, Node,
emqx_common_test_helpers, emqx_common_test_helpers,

View File

@ -29,7 +29,9 @@ all() ->
emqx_common_test_helpers:all(?MODULE). emqx_common_test_helpers:all(?MODULE).
init_per_suite(Config) -> init_per_suite(Config) ->
ok = emqx_common_test_helpers:load_config(emqx_modules_schema, ?BASE_CONF), ok = emqx_common_test_helpers:load_config(emqx_modules_schema, jsx:encode(?BASE_CONF), #{
raw_with_default => true
}),
ok = emqx_common_test_helpers:start_apps( ok = emqx_common_test_helpers:start_apps(
[emqx_conf, emqx_authn, emqx_authz, emqx_modules, emqx_dashboard], [emqx_conf, emqx_authn, emqx_authz, emqx_modules, emqx_dashboard],

View File

@ -29,7 +29,9 @@ all() -> emqx_common_test_helpers:all(?MODULE).
init_per_suite(Config) -> init_per_suite(Config) ->
emqx_common_test_helpers:boot_modules(all), emqx_common_test_helpers:boot_modules(all),
emqx_common_test_helpers:start_apps([emqx_conf, emqx_modules]), emqx_common_test_helpers:start_apps([emqx_conf, emqx_modules]),
ok = emqx_common_test_helpers:load_config(emqx_modules_schema, ?TOPIC), ok = emqx_common_test_helpers:load_config(emqx_modules_schema, jsx:encode(?TOPIC), #{
raw_with_default => true
}),
Config. Config.
end_per_suite(_Config) -> end_per_suite(_Config) ->

View File

@ -40,7 +40,9 @@ init_per_testcase(_, Config) ->
Config. Config.
init_per_suite(Config) -> init_per_suite(Config) ->
ok = emqx_common_test_helpers:load_config(emqx_modules_schema, ?BASE_CONF), ok = emqx_common_test_helpers:load_config(emqx_modules_schema, jsx:encode(?BASE_CONF), #{
raw_with_default => true
}),
ok = emqx_common_test_helpers:start_apps( ok = emqx_common_test_helpers:start_apps(
[emqx_conf, emqx_modules, emqx_dashboard], [emqx_conf, emqx_modules, emqx_dashboard],