Просмотр исходного кода

test(retainer): fix flow control test case error

firest 3 лет назад
Родитель
Сommit
89de8274a0

+ 1 - 2
apps/emqx/src/emqx_limiter/etc/emqx_limiter.conf

@@ -2,5 +2,4 @@
 ## EMQX Rate Limiter
 ##--------------------------------------------------------------------
 
-limiter {
-}
+limiter {}

+ 2 - 1
apps/emqx/src/emqx_limiter/src/emqx_limiter_server_sup.erl

@@ -54,7 +54,8 @@ start(Type, Cfg) ->
 
 stop(Type) ->
     Id = emqx_limiter_server:name(Type),
-    supervisor:terminate_child(?MODULE, Id).
+    _ = supervisor:terminate_child(?MODULE, Id),
+    supervisor:delete_child(?MODULE, Id).
 
 %%--------------------------------------------------------------------
 %%  Supervisor callbacks

+ 1 - 1
apps/emqx/test/emqx_common_test_helpers.erl

@@ -151,7 +151,7 @@ start_apps(Apps, Handler) when is_function(Handler) ->
     %% Because, minirest, ekka etc.. application will scan these modules
     lists:foreach(fun load/1, [emqx | Apps]),
     ok = start_ekka(),
-    ok = emqx_ratelimiter_SUITE:base_conf(),
+    ok = emqx_ratelimiter_SUITE:load_conf(),
     lists:foreach(fun(App) -> start_app(App, Handler) end, [emqx | Apps]).
 
 load(App) ->

+ 9 - 2
apps/emqx/test/emqx_ratelimiter_SUITE.erl

@@ -29,6 +29,7 @@
     "\n"
     "limiter {\n"
     "  bytes_in {\n"
+    "    enable = true\n"
     "    bucket.default {\n"
     "      rate = infinity\n"
     "      capacity = infinity\n"
@@ -36,6 +37,7 @@
     "  }\n"
     "\n"
     "  message_in {\n"
+    "    enable = true\n"
     "    bucket.default {\n"
     "      rate = infinity\n"
     "      capacity = infinity\n"
@@ -43,6 +45,7 @@
     "  }\n"
     "\n"
     "  connection {\n"
+    "    enable = true\n"
     "    bucket.default {\n"
     "      rate = infinity\n"
     "      capacity = infinity\n"
@@ -50,6 +53,7 @@
     "  }\n"
     "\n"
     "  message_routing {\n"
+    "    enable = true\n"
     "    bucket.default {\n"
     "      rate = infinity\n"
     "      capacity = infinity\n"
@@ -57,6 +61,7 @@
     "  }\n"
     "\n"
     "  batch {\n"
+    "    enable = true\n"
     "    bucket.retainer {\n"
     "      rate = infinity\n"
     "      capacity = infinity\n"
@@ -79,7 +84,6 @@
 -define(LOGT(Format, Args), ct:pal("TEST_SUITE: " ++ Format, Args)).
 -define(RATE(Rate), to_rate(Rate)).
 -define(NOW, erlang:system_time(millisecond)).
--define(CONST(X), fun(_) -> X end).
 
 %%--------------------------------------------------------------------
 %% Setups
@@ -98,9 +102,12 @@ end_per_suite(_Config) ->
 init_per_testcase(_TestCase, Config) ->
     Config.
 
-base_conf() ->
+load_conf() ->
     emqx_common_test_helpers:load_config(emqx_limiter_schema, ?BASE_CONF).
 
+init_config() ->
+    emqx_config:init_load(emqx_limiter_schema, ?BASE_CONF).
+
 %%--------------------------------------------------------------------
 %% Test Cases Bucket Level
 %%--------------------------------------------------------------------

+ 9 - 6
apps/emqx_retainer/test/emqx_retainer_SUITE.erl

@@ -71,16 +71,17 @@ common_tests() ->
 %%--------------------------------------------------------------------
 
 init_per_suite(Config) ->
-    load_base_conf(),
-    emqx_ratelimiter_SUITE:base_conf(),
-    emqx_common_test_helpers:start_apps([emqx_conf, ?APP]),
+    emqx_common_test_helpers:start_apps([emqx_conf]),
+    load_conf(),
+    emqx_limiter_sup:start_link(),
+    timer:sleep(200),
+    ok = application:ensure_started(?APP),
     Config.
 
 end_per_suite(_Config) ->
     ekka:stop(),
     mria:stop(),
     mria_mnesia:delete_schema(),
-
     emqx_common_test_helpers:stop_apps([?APP, emqx_conf]).
 
 init_per_group(mnesia_without_indices, Config) ->
@@ -111,8 +112,10 @@ init_per_testcase(t_get_basic_usage_info, Config) ->
 init_per_testcase(_TestCase, Config) ->
     Config.
 
-load_base_conf() ->
-    ok = emqx_common_test_helpers:load_config(emqx_retainer_schema, ?BASE_CONF).
+load_conf() ->
+    ok = emqx_config:delete_override_conf_files(),
+    emqx_ratelimiter_SUITE:init_config(),
+    ok = emqx_config:init_load(emqx_retainer_schema, ?BASE_CONF).
 
 %%--------------------------------------------------------------------
 %% Test Cases

+ 1 - 1
apps/emqx_retainer/test/emqx_retainer_api_SUITE.erl

@@ -34,7 +34,7 @@ init_per_suite(Config) ->
     application:load(emqx_conf),
     ok = ekka:start(),
     ok = mria_rlog:wait_for_shards([?CLUSTER_RPC_SHARD], infinity),
-    emqx_retainer_SUITE:load_base_conf(),
+    emqx_retainer_SUITE:load_conf(),
     emqx_mgmt_api_test_util:init_suite([emqx_retainer, emqx_conf]),
     %% make sure no "$SYS/#" topics
     emqx_conf:update([sys_topics], raw_systopic_conf(), #{override_to => cluster}),

+ 1 - 1
apps/emqx_retainer/test/emqx_retainer_cli_SUITE.erl

@@ -27,7 +27,7 @@
 all() -> emqx_common_test_helpers:all(?MODULE).
 
 init_per_suite(Config) ->
-    emqx_retainer_SUITE:load_base_conf(),
+    emqx_retainer_SUITE:load_conf(),
     %% Start Apps
     emqx_common_test_helpers:start_apps([emqx_retainer]),
     Config.

+ 1 - 1
apps/emqx_retainer/test/emqx_retainer_mqtt_v5_SUITE.erl

@@ -24,7 +24,7 @@
 all() -> emqx_common_test_helpers:all(?MODULE).
 
 init_per_suite(Config) ->
-    emqx_retainer_SUITE:load_base_conf(),
+    emqx_retainer_SUITE:load_conf(),
     %% Start Apps
     emqx_common_test_helpers:start_apps([emqx_retainer]),
     Config.