Pārlūkot izejas kodu

test: start emqx_opentelemetry in emqx_machine SUITE

zhongwencool 2 gadi atpakaļ
vecāks
revīzija
8ab6eb5638

+ 4 - 3
apps/emqx_machine/test/emqx_machine_SUITE.erl

@@ -42,7 +42,7 @@ init_per_suite(Config) ->
     %%   Unload emqx_authz to avoid reboot this application
     %%
     application:unload(emqx_authz),
-    emqx_common_test_helpers:start_apps([emqx_conf]),
+    emqx_common_test_helpers:start_apps([emqx_conf, emqx_opentelemetry]),
     application:set_env(emqx_machine, applications, [
         emqx_prometheus,
         emqx_modules,
@@ -56,12 +56,13 @@ init_per_suite(Config) ->
         emqx_exhook,
         emqx_authn,
         emqx_authz,
-        emqx_plugin
+        emqx_plugin,
+        emqx_opentelemetry
     ]),
     Config.
 
 end_per_suite(_Config) ->
-    emqx_common_test_helpers:stop_apps([]).
+    emqx_common_test_helpers:stop_apps([emqx_opentelemetry, emqx_conf]).
 
 init_per_testcase(t_custom_shard_transports, Config) ->
     OldConfig = application:get_env(emqx_machine, custom_shard_transports),

+ 9 - 4
apps/emqx_opentelemetry/src/emqx_otel.erl

@@ -30,10 +30,15 @@ start_otel(Conf) ->
 
 stop_otel() ->
     ok = cleanup(),
-    case supervisor:terminate_child(?SUPERVISOR, ?MODULE) of
-        ok -> supervisor:delete_child(?SUPERVISOR, ?MODULE);
-        {error, not_found} -> ok;
-        Error -> Error
+    case erlang:whereis(?SUPERVISOR) of
+        undefined ->
+            ok;
+        Pid ->
+            case supervisor:terminate_child(Pid, ?MODULE) of
+                ok -> supervisor:delete_child(Pid, ?MODULE);
+                {error, not_found} -> ok;
+                Error -> Error
+            end
     end.
 
 start_link(Conf) ->