Merge pull request #12390 from zhongwencool/license-app-reboot

fix: reboot emqx_dashboard after emqx_licencse
This commit is contained in:
zhongwencool 2024-01-25 17:08:48 +08:00 committed by GitHub
commit 33cfd66e41
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 45 additions and 18 deletions

View File

@ -166,8 +166,9 @@ is_app(Name) ->
sorted_reboot_apps() ->
RebootApps = reboot_apps(),
Apps0 = [{App, app_deps(App, RebootApps)} || App <- RebootApps],
Apps = inject_bridge_deps(Apps0),
sorted_reboot_apps(Apps).
Apps1 = inject_bridge_deps(Apps0),
Apps2 = inject_dashboard_deps(Apps1),
sorted_reboot_apps(Apps2).
app_deps(App, RebootApps) ->
case application:get_key(App, applications) of
@ -193,6 +194,18 @@ inject_bridge_deps(RebootAppDeps) ->
end,
RebootAppDeps
).
inject_dashboard_deps(Reboots) ->
Apps = [emqx_license],
Deps = lists:filter(fun(App) -> lists:keymember(App, 1, Reboots) end, Apps),
lists:map(
fun
({emqx_dashboard, Deps0}) when is_list(Deps0) ->
{emqx_dashboard, Deps0 ++ Deps};
(App) ->
App
end,
Reboots
).
sorted_reboot_apps(Apps) ->
G = digraph:new(),
@ -201,7 +214,8 @@ sorted_reboot_apps(Apps) ->
case digraph_utils:topsort(G) of
Sorted when is_list(Sorted) ->
%% ensure emqx_conf boot up first
[emqx_conf | Sorted ++ (NoDepApps -- Sorted)];
AllApps = Sorted ++ (NoDepApps -- Sorted),
[emqx_conf | lists:delete(emqx_conf, AllApps)];
false ->
Loops = find_loops(G),
error({circular_application_dependency, Loops})

View File

@ -24,25 +24,27 @@
-include_lib("common_test/include/ct.hrl").
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
-define(APPS, [
emqx_prometheus,
emqx_modules,
emqx_dashboard,
emqx_gateway,
emqx_resource,
emqx_rule_engine,
emqx_bridge,
emqx_management,
emqx_retainer,
emqx_exhook,
emqx_auth,
emqx_plugin,
emqx_opentelemetry
]).
all() -> emqx_common_test_helpers:all(?MODULE).
init_per_suite(Config) ->
emqx_common_test_helpers:start_apps([emqx_conf, emqx_opentelemetry]),
application:set_env(emqx_machine, applications, [
emqx_prometheus,
emqx_modules,
emqx_dashboard,
emqx_gateway,
emqx_resource,
emqx_rule_engine,
emqx_bridge,
emqx_management,
emqx_retainer,
emqx_exhook,
emqx_auth,
emqx_plugin,
emqx_opentelemetry
]),
application:load(emqx_dashboard),
Config.
end_per_suite(_Config) ->
@ -60,7 +62,11 @@ init_per_testcase(t_open_ports_check = TestCase, Config) ->
],
Nodes = emqx_cth_cluster:start(Cluster, #{work_dir => emqx_cth_suite:work_dir(TestCase, Config)}),
[{nodes, Nodes} | Config];
init_per_testcase(t_sorted_reboot_apps, Config) ->
application:set_env(emqx_machine, applications, ?APPS ++ [emqx_license]),
Config;
init_per_testcase(_TestCase, Config) ->
application:set_env(emqx_machine, applications, ?APPS),
Config.
end_per_testcase(t_custom_shard_transports, Config) ->
@ -88,6 +94,12 @@ t_shutdown_reboot(_Config) ->
ok = emqx_machine_boot:stop_apps(),
false = emqx:is_running(node()).
t_sorted_reboot_apps(_Config) ->
Apps = emqx_machine_boot:sorted_reboot_apps(),
SortApps = [App || App <- Apps, (App =:= emqx_dashboard orelse App =:= emqx_license)],
%% make sure emqx_license start early than emqx_dashboard
?assertEqual([emqx_license, emqx_dashboard], SortApps).
t_custom_shard_transports(_Config) ->
%% used to ensure the atom exists
Shard = test_shard,

View File

@ -0,0 +1 @@
Fixed /license API request maybe crash during cluster join processes.