Parcourir la source

test: render config for emqx_conf only for ee bridge tests

Zaiming (Stone) Shi il y a 3 ans
Parent
commit
dc14cd450d

+ 3 - 9
apps/emqx/test/emqx_common_test_helpers.erl

@@ -33,7 +33,8 @@
     proj_root/0,
     deps_path/2,
     flush/0,
-    flush/1
+    flush/1,
+    render_and_load_app_config/1
 ]).
 
 -export([
@@ -167,14 +168,6 @@ start_apps(Apps, SpecAppConfig) when is_function(SpecAppConfig) ->
     %% Load all application code to beam vm first
     %% Because, minirest, ekka etc.. application will scan these modules
     lists:foreach(fun load/1, [emqx | Apps]),
-    %% load emqx_conf config before starting ekka
-    case application:load(emqx_conf) of
-        {error, _} ->
-            %% running test only for emqx app (standalone)
-            ok;
-        _ ->
-            render_and_load_app_config(emqx_conf)
-    end,
     ok = start_ekka(),
     ok = emqx_ratelimiter_SUITE:load_conf(),
     lists:foreach(fun(App) -> start_app(App, SpecAppConfig) end, [emqx | Apps]).
@@ -187,6 +180,7 @@ load(App) ->
     end.
 
 render_and_load_app_config(App) ->
+    load(App),
     Schema = app_schema(App),
     Conf = app_path(App, filename:join(["etc", app_conf_file(App)])),
     try

+ 2 - 0
lib-ee/emqx_ee_bridge/test/emqx_bridge_impl_kafka_producer_SUITE.erl

@@ -67,6 +67,8 @@ init_per_suite(Config) ->
     %% Need to unload emqx_authz. See emqx_machine_SUITE:init_per_suite for
     %% more info.
     application:unload(emqx_authz),
+    %% some configs in emqx_conf app are mandatory
+    emqx_common_test_helpers:render_and_load_app_config(emqx_conf),
     emqx_common_test_helpers:start_apps(
         [emqx_conf, emqx_rule_engine, emqx_bridge, emqx_management, emqx_dashboard],
         fun set_special_configs/1

+ 10 - 4
lib-ee/emqx_ee_bridge/test/emqx_ee_bridge_influxdb_SUITE.erl

@@ -89,8 +89,7 @@ init_per_group(InfluxDBType, Config0) when
             ProxyHost = os:getenv("PROXY_HOST", "toxiproxy"),
             ProxyPort = list_to_integer(os:getenv("PROXY_PORT", "8474")),
             emqx_common_test_helpers:reset_proxy(ProxyHost, ProxyPort),
-            ok = emqx_common_test_helpers:start_apps([emqx_conf]),
-            ok = emqx_connector_test_helpers:start_apps([emqx_resource, emqx_bridge]),
+            ok = start_apps(),
             {ok, _} = application:ensure_all_started(emqx_connector),
             Config = [{use_tls, UseTLS} | Config0],
             {Name, ConfigString, InfluxDBConfig} = influxdb_config(
@@ -158,8 +157,7 @@ init_per_group(InfluxDBType, Config0) when
             ProxyHost = os:getenv("PROXY_HOST", "toxiproxy"),
             ProxyPort = list_to_integer(os:getenv("PROXY_PORT", "8474")),
             emqx_common_test_helpers:reset_proxy(ProxyHost, ProxyPort),
-            ok = emqx_common_test_helpers:start_apps([emqx_conf]),
-            ok = emqx_connector_test_helpers:start_apps([emqx_resource, emqx_bridge]),
+            ok = start_apps(),
             {ok, _} = application:ensure_all_started(emqx_connector),
             Config = [{use_tls, UseTLS} | Config0],
             {Name, ConfigString, InfluxDBConfig} = influxdb_config(
@@ -855,3 +853,11 @@ t_write_failure(Config) ->
         end
     ),
     ok.
+
+start_apps() ->
+    %% some configs in emqx_conf app are mandatory
+    %% we want to make sure they are loaded before
+    %% ekka start in emqx_common_test_helpers:start_apps/1
+    emqx_common_test_helpers:render_and_load_app_config(emqx_conf),
+    ok = emqx_common_test_helpers:start_apps([emqx_conf]),
+    ok = emqx_connector_test_helpers:start_apps([emqx_resource, emqx_bridge]).

+ 11 - 6
lib-ee/emqx_ee_bridge/test/emqx_ee_bridge_mongodb_SUITE.erl

@@ -40,8 +40,7 @@ init_per_group(Type = rs, Config) ->
     MongoPort = list_to_integer(os:getenv("MONGO_RS_PORT", "27017")),
     case emqx_common_test_helpers:is_tcp_server_available(MongoHost, MongoPort) of
         true ->
-            ensure_loaded(),
-            ok = emqx_common_test_helpers:start_apps([emqx_conf, emqx_bridge]),
+            ok = start_apps(),
             emqx_mgmt_api_test_util:init_suite(),
             {Name, MongoConfig} = mongo_config(MongoHost, MongoPort, Type),
             [
@@ -60,8 +59,7 @@ init_per_group(Type = sharded, Config) ->
     MongoPort = list_to_integer(os:getenv("MONGO_SHARDED_PORT", "27017")),
     case emqx_common_test_helpers:is_tcp_server_available(MongoHost, MongoPort) of
         true ->
-            ensure_loaded(),
-            ok = emqx_common_test_helpers:start_apps([emqx_conf, emqx_bridge]),
+            ok = start_apps(),
             emqx_mgmt_api_test_util:init_suite(),
             {Name, MongoConfig} = mongo_config(MongoHost, MongoPort, Type),
             [
@@ -80,8 +78,7 @@ init_per_group(Type = single, Config) ->
     MongoPort = list_to_integer(os:getenv("MONGO_SINGLE_PORT", "27017")),
     case emqx_common_test_helpers:is_tcp_server_available(MongoHost, MongoPort) of
         true ->
-            ensure_loaded(),
-            ok = emqx_common_test_helpers:start_apps([emqx_conf, emqx_bridge]),
+            ok = start_apps(),
             emqx_mgmt_api_test_util:init_suite(),
             {Name, MongoConfig} = mongo_config(MongoHost, MongoPort, Type),
             [
@@ -121,6 +118,14 @@ end_per_testcase(_Testcase, Config) ->
 %% Helper fns
 %%------------------------------------------------------------------------------
 
+start_apps() ->
+    ensure_loaded(),
+    %% some configs in emqx_conf app are mandatory,
+    %% we want to make sure they are loaded before
+    %% ekka start in emqx_common_test_helpers:start_apps/1
+    emqx_common_test_helpers:render_and_load_app_config(emqx_conf),
+    ok = emqx_common_test_helpers:start_apps([emqx_conf, emqx_bridge]).
+
 ensure_loaded() ->
     _ = application:load(emqx_ee_bridge),
     _ = emqx_ee_bridge:module_info(),