Jelajahi Sumber

fix: ct failed again

Zhongwen Deng 3 tahun lalu
induk
melakukan
d61b44ef97

+ 1 - 0
apps/emqx/src/emqx_config.erl

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

+ 11 - 2
apps/emqx/test/emqx_common_test_helpers.erl

@@ -51,6 +51,7 @@
     render_config_file/2,
     read_schema_configs/2,
     load_config/2,
+    load_config/3,
     is_tcp_server_available/2,
     is_tcp_server_available/3
 ]).
@@ -465,11 +466,19 @@ copy_certs(emqx_conf, Dest0) ->
 copy_certs(_, _) ->
     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:init_load(SchemaModule, Config),
+    ok = emqx_config:init_load(SchemaModule, ConfigBin, Opts),
     ok.
 
+load_config(SchemaModule, Config) ->
+    load_config(SchemaModule, Config, #{raw_with_default => false}).
+
 -spec is_tcp_server_available(
     Host :: inet:socket_address() | inet:hostname(),
     Port :: inet:port_number()

+ 3 - 2
apps/emqx_bridge/test/emqx_bridge_SUITE.erl

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

+ 3 - 1
apps/emqx_modules/test/emqx_delayed_api_SUITE.erl

@@ -32,7 +32,9 @@ all() ->
     emqx_common_test_helpers:all(?MODULE).
 
 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(
         [emqx_conf, emqx_modules, emqx_dashboard],

+ 3 - 1
apps/emqx_modules/test/emqx_modules_conf_SUITE.erl

@@ -29,7 +29,9 @@ all() ->
     emqx_common_test_helpers:all(?MODULE).
 
 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]),
     Conf.
 

+ 15 - 5
apps/emqx_modules/test/emqx_rewrite_SUITE.erl

@@ -157,13 +157,17 @@ t_rewrite_re_error(_Config) ->
     ok.
 
 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),
     ?assertEqual(Expect, emqx_rewrite:list()),
     ok.
 
 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(),
     Rules = [
         #{
@@ -179,7 +183,9 @@ t_update(_Config) ->
     ok.
 
 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([])),
     timer:sleep(150),
 
@@ -194,7 +200,9 @@ t_update_disable(_Config) ->
     ok.
 
 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/*">>,
     Rules = [
         #{
@@ -249,7 +257,9 @@ receive_publish(Timeout) ->
     end.
 
 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, C} = emqtt:start_link([{clientid, <<"c1">>}, {username, <<"u1">>}]),
     {ok, _} = emqtt:connect(C),

+ 3 - 1
apps/emqx_modules/test/emqx_rewrite_api_SUITE.erl

@@ -33,7 +33,9 @@ init_per_testcase(_, Config) ->
     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(
         [emqx_conf, emqx_modules, emqx_dashboard],

+ 23 - 1
apps/emqx_modules/test/emqx_telemetry_SUITE.erl

@@ -25,6 +25,11 @@
 
 -import(proplists, [get_value/2]).
 
+-define(BASE_CONF, #{
+    <<"dealyed">> => <<"true">>,
+    <<"max_delayed_messages">> => <<"0">>
+}).
+
 all() -> emqx_common_test_helpers:all(?MODULE).
 
 init_per_suite(Config) ->
@@ -36,6 +41,9 @@ init_per_suite(Config) ->
             emqx_common_test_helpers:deps_path(emqx_authz, "etc/acl.conf")
         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_conf, emqx_authn, emqx_authz, emqx_modules],
         fun set_special_configs/1
@@ -144,7 +152,9 @@ init_per_testcase(t_exhook_info, Config) ->
     {ok, _} = emqx_exhook_demo_svr:start(),
     {ok, Sock} = gen_tcp:connect("localhost", 9000, [], 3000),
     _ = 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),
     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
     {atomic, ok} = mria:clear_table(emqx_telemetry),
     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_conf, emqx_authn, emqx_authz, emqx_modules],
         fun set_special_configs/1
@@ -319,6 +332,9 @@ t_uuid_saved_to_file(_Config) ->
     %% clear the UUIDs in the DB
     {atomic, ok} = mria:clear_table(emqx_telemetry),
     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_conf, emqx_authn, emqx_authz, emqx_modules],
         fun set_special_configs/1
@@ -841,6 +857,12 @@ setup_slave(Node) ->
             (_) ->
                 ok
         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(
         Node,
         emqx_common_test_helpers,

+ 3 - 1
apps/emqx_modules/test/emqx_telemetry_api_SUITE.erl

@@ -29,7 +29,9 @@ all() ->
     emqx_common_test_helpers:all(?MODULE).
 
 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(
         [emqx_conf, emqx_authn, emqx_authz, emqx_modules, emqx_dashboard],

+ 3 - 1
apps/emqx_modules/test/emqx_topic_metrics_SUITE.erl

@@ -29,7 +29,9 @@ all() -> emqx_common_test_helpers:all(?MODULE).
 init_per_suite(Config) ->
     emqx_common_test_helpers:boot_modules(all),
     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.
 
 end_per_suite(_Config) ->

+ 3 - 1
apps/emqx_modules/test/emqx_topic_metrics_api_SUITE.erl

@@ -40,7 +40,9 @@ init_per_testcase(_, Config) ->
     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(
         [emqx_conf, emqx_modules, emqx_dashboard],