From 08f085d8230df603b6b0d2b6e8ddb7930066d11e Mon Sep 17 00:00:00 2001 From: JianBo He Date: Fri, 14 Jun 2024 15:07:12 +0800 Subject: [PATCH 1/3] fix: gateway app must depends on all auth apps --- apps/emqx_gateway/src/emqx_gateway.app.src | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/emqx_gateway/src/emqx_gateway.app.src b/apps/emqx_gateway/src/emqx_gateway.app.src index fa8a774ed..d7cc2f2d7 100644 --- a/apps/emqx_gateway/src/emqx_gateway.app.src +++ b/apps/emqx_gateway/src/emqx_gateway.app.src @@ -4,7 +4,9 @@ {vsn, "0.1.33"}, {registered, []}, {mod, {emqx_gateway_app, []}}, - {applications, [kernel, stdlib, emqx, emqx_auth, emqx_ctl]}, + {applications, [kernel, stdlib, emqx, emqx_auth, emqx_ctl, emqx_auth_http, + emqx_auth_mnesia, emqx_auth_jwt, emqx_auth_mysql, emqx_auth_postgresql, + emqx_auth_mongodb, emqx_auth_redis, emqx_auth_ldap]}, {env, []}, {modules, []}, {licenses, ["Apache 2.0"]}, From a8af90f912ca01fbe7c76c1f332b85cdf24059fc Mon Sep 17 00:00:00 2001 From: JianBo He Date: Fri, 14 Jun 2024 15:12:38 +0800 Subject: [PATCH 2/3] chore: add changes --- apps/emqx_gateway/src/emqx_gateway.app.src | 18 +++++++++++++++--- changes/ce/fix-13258.en.md | 1 + 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 changes/ce/fix-13258.en.md diff --git a/apps/emqx_gateway/src/emqx_gateway.app.src b/apps/emqx_gateway/src/emqx_gateway.app.src index d7cc2f2d7..25a81801b 100644 --- a/apps/emqx_gateway/src/emqx_gateway.app.src +++ b/apps/emqx_gateway/src/emqx_gateway.app.src @@ -4,9 +4,21 @@ {vsn, "0.1.33"}, {registered, []}, {mod, {emqx_gateway_app, []}}, - {applications, [kernel, stdlib, emqx, emqx_auth, emqx_ctl, emqx_auth_http, - emqx_auth_mnesia, emqx_auth_jwt, emqx_auth_mysql, emqx_auth_postgresql, - emqx_auth_mongodb, emqx_auth_redis, emqx_auth_ldap]}, + {applications, [ + kernel, + stdlib, + emqx, + emqx_auth, + emqx_ctl, + emqx_auth_http, + emqx_auth_mnesia, + emqx_auth_jwt, + emqx_auth_mysql, + emqx_auth_postgresql, + emqx_auth_mongodb, + emqx_auth_redis, + emqx_auth_ldap + ]}, {env, []}, {modules, []}, {licenses, ["Apache 2.0"]}, diff --git a/changes/ce/fix-13258.en.md b/changes/ce/fix-13258.en.md new file mode 100644 index 000000000..4084ed6f1 --- /dev/null +++ b/changes/ce/fix-13258.en.md @@ -0,0 +1 @@ +Fix an issue where the MQTT-SN gateway would not restart correctly due to incorrect startup order of gateway dependencies. From d8e6c07ca0963a5db84243e36d633a243ab0592f Mon Sep 17 00:00:00 2001 From: JianBo He Date: Fri, 21 Jun 2024 11:04:23 +0800 Subject: [PATCH 3/3] chore: fix failed tests --- apps/emqx_gateway/test/emqx_gateway_SUITE.erl | 47 ++----------------- .../test/emqx_gateway_api_SUITE.erl | 5 +- .../test/emqx_gateway_authn_SUITE.erl | 3 +- .../test/emqx_gateway_authz_SUITE.erl | 2 - .../test/emqx_gateway_cli_SUITE.erl | 23 +++++---- .../test/emqx_gateway_conf_SUITE.erl | 16 +++++-- 6 files changed, 28 insertions(+), 68 deletions(-) diff --git a/apps/emqx_gateway/test/emqx_gateway_SUITE.erl b/apps/emqx_gateway/test/emqx_gateway_SUITE.erl index d5e6f52b3..ac351cdee 100644 --- a/apps/emqx_gateway/test/emqx_gateway_SUITE.erl +++ b/apps/emqx_gateway/test/emqx_gateway_SUITE.erl @@ -36,10 +36,7 @@ init_per_suite(Config) -> Apps = emqx_cth_suite:start( [ {emqx_conf, ?CONF_DEFAULT}, - emqx_gateway, - emqx_auth, - emqx_auth_redis, - emqx_auth_mnesia + emqx_gateway ], #{work_dir => emqx_cth_suite:work_dir(Config)} ), @@ -50,25 +47,6 @@ end_per_suite(Config) -> emqx_config:delete_override_conf_files(), ok. -init_per_testcase(t_get_basic_usage_info_2, Config) -> - DataDir = ?config(data_dir, Config), - application:stop(emqx_gateway), - ok = setup_fake_usage_data(DataDir), - Config; -init_per_testcase(_TestCase, Config) -> - Config. - -end_per_testcase(t_get_basic_usage_info_2, _Config) -> - emqx_gateway_cm:unregister_channel(lwm2m, <<"client_id">>), - emqx_config:put([gateway], #{}), - emqx_common_test_helpers:stop_apps([emqx_gateway]), - emqx_config:erase(gateway), - emqx_common_test_helpers:load_config(emqx_gateway_schema, ?CONF_DEFAULT), - emqx_common_test_helpers:start_apps([emqx_gateway]), - ok; -end_per_testcase(_TestCase, _Config) -> - ok. - %%-------------------------------------------------------------------- %% cases %%-------------------------------------------------------------------- @@ -160,27 +138,8 @@ t_get_basic_usage_info_1(_Config) -> } }, emqx_gateway:get_basic_usage_info() - ). - -t_get_basic_usage_info_2(_Config) -> - ?assertEqual( - #{ - lwm2m => - #{ - authn => <<"password_based:redis">>, - listeners => - [ - #{ - authn => - <<"password_based:built_in_database">>, - type => udp - } - ], - num_clients => 1 - } - }, - emqx_gateway:get_basic_usage_info() - ). + ), + ok = emqx_gateway:unload(?GWNAME). %%-------------------------------------------------------------------- %% helper functions diff --git a/apps/emqx_gateway/test/emqx_gateway_api_SUITE.erl b/apps/emqx_gateway/test/emqx_gateway_api_SUITE.erl index 6e2afe105..e74b25a06 100644 --- a/apps/emqx_gateway/test/emqx_gateway_api_SUITE.erl +++ b/apps/emqx_gateway/test/emqx_gateway_api_SUITE.erl @@ -48,8 +48,6 @@ init_per_suite(Conf) -> Apps = emqx_cth_suite:start( [ emqx_conf, - emqx_auth, - emqx_auth_mnesia, emqx_management, {emqx_dashboard, "dashboard.listeners.http { enable = true, bind = 18083 }"}, {emqx_gateway, ?CONF_DEFAULT} @@ -62,7 +60,8 @@ init_per_suite(Conf) -> end_per_suite(Conf) -> _ = emqx_common_test_http:delete_default_app(), - ok = emqx_cth_suite:stop(proplists:get_value(suite_apps, Conf)). + ok = emqx_cth_suite:stop(proplists:get_value(suite_apps, Conf)), + emqx_config:delete_override_conf_files(). init_per_testcase(t_gateway_fail, Config) -> meck:expect( diff --git a/apps/emqx_gateway/test/emqx_gateway_authn_SUITE.erl b/apps/emqx_gateway/test/emqx_gateway_authn_SUITE.erl index 1489f8a55..936856c2e 100644 --- a/apps/emqx_gateway/test/emqx_gateway_authn_SUITE.erl +++ b/apps/emqx_gateway/test/emqx_gateway_authn_SUITE.erl @@ -57,8 +57,6 @@ init_per_group(AuthName, Conf) -> Apps = emqx_cth_suite:start( [ emqx_conf, - emqx_auth, - emqx_auth_http, emqx_management, {emqx_dashboard, "dashboard.listeners.http { enable = true, bind = 18083 }"}, {emqx_gateway, emqx_gateway_auth_ct:list_gateway_conf()} @@ -73,6 +71,7 @@ init_per_group(AuthName, Conf) -> end_per_group(AuthName, Conf) -> ok = emqx_gateway_auth_ct:stop_auth(AuthName), _ = emqx_common_test_http:delete_default_app(), + emqx_config:delete_override_conf_files(), ok = emqx_cth_suite:stop(?config(group_apps, Conf)), Conf. diff --git a/apps/emqx_gateway/test/emqx_gateway_authz_SUITE.erl b/apps/emqx_gateway/test/emqx_gateway_authz_SUITE.erl index 45f716a9e..5b262158f 100644 --- a/apps/emqx_gateway/test/emqx_gateway_authz_SUITE.erl +++ b/apps/emqx_gateway/test/emqx_gateway_authz_SUITE.erl @@ -57,8 +57,6 @@ init_per_group(AuthName, Conf) -> Apps = emqx_cth_suite:start( [ {emqx_conf, "authorization { no_match = deny, cache { enable = false } }"}, - emqx_auth, - emqx_auth_http, {emqx_gateway, emqx_gateway_auth_ct:list_gateway_conf()} | emqx_gateway_test_utils:all_gateway_apps() ], diff --git a/apps/emqx_gateway/test/emqx_gateway_cli_SUITE.erl b/apps/emqx_gateway/test/emqx_gateway_cli_SUITE.erl index 2281262df..5ec956f31 100644 --- a/apps/emqx_gateway/test/emqx_gateway_cli_SUITE.erl +++ b/apps/emqx_gateway/test/emqx_gateway_cli_SUITE.erl @@ -20,6 +20,7 @@ -compile(nowarn_export_all). -include_lib("eunit/include/eunit.hrl"). +-include_lib("common_test/include/ct.hrl"). -define(GP(S), begin S, @@ -29,13 +30,6 @@ end end). -%% this parses to #{}, will not cause config cleanup -%% so we will need call emqx_config:erase --define(CONF_DEFAULT, << - "\n" - "gateway {}\n" ->>). - %% The config with json format for mqtt-sn gateway -define(CONF_MQTTSN, "\n" @@ -65,13 +59,18 @@ all() -> emqx_common_test_helpers:all(?MODULE). init_per_suite(Conf) -> emqx_config:erase(gateway), emqx_gateway_test_utils:load_all_gateway_apps(), - emqx_common_test_helpers:load_config(emqx_gateway_schema, ?CONF_DEFAULT), - emqx_mgmt_api_test_util:init_suite([emqx_conf, emqx_auth, emqx_gateway]), - Conf. + Apps = emqx_cth_suite:start( + [ + {emqx_conf, <<"gateway {}">>}, + emqx_gateway + ], + #{work_dir => emqx_cth_suite:work_dir(Conf)} + ), + [{suite_apps, Apps} | Conf]. end_per_suite(Conf) -> - emqx_mgmt_api_test_util:end_suite([emqx_gateway, emqx_auth, emqx_conf]), - Conf. + emqx_cth_suite:stop(?config(suite_apps, Conf)), + emqx_config:delete_override_conf_files(). init_per_testcase(_, Conf) -> Self = self(), diff --git a/apps/emqx_gateway/test/emqx_gateway_conf_SUITE.erl b/apps/emqx_gateway/test/emqx_gateway_conf_SUITE.erl index a600d7915..e084214bf 100644 --- a/apps/emqx_gateway/test/emqx_gateway_conf_SUITE.erl +++ b/apps/emqx_gateway/test/emqx_gateway_conf_SUITE.erl @@ -28,6 +28,7 @@ ). -include_lib("eunit/include/eunit.hrl"). +-include_lib("common_test/include/ct.hrl"). %%-------------------------------------------------------------------- %% Setups @@ -38,12 +39,17 @@ all() -> init_per_suite(Conf) -> emqx_gateway_test_utils:load_all_gateway_apps(), - emqx_common_test_helpers:load_config(emqx_gateway_schema, <<"gateway {}">>), - emqx_common_test_helpers:start_apps([emqx_conf, emqx_auth, emqx_auth_mnesia, emqx_gateway]), - Conf. + Apps = emqx_cth_suite:start( + [ + {emqx_conf, <<"gateway {}">>}, + emqx_gateway + ], + #{work_dir => emqx_cth_suite:work_dir(Conf)} + ), + [{suite_apps, Apps} | Conf]. -end_per_suite(_Conf) -> - emqx_common_test_helpers:stop_apps([emqx_gateway, emqx_auth, emqx_auth_mnesia, emqx_conf]), +end_per_suite(Conf) -> + emqx_cth_suite:stop(?config(suite_apps, Conf)), emqx_config:delete_override_conf_files(). init_per_testcase(_CaseName, Conf) ->