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

feat(psk): manage mria tables explicitly during startup

Also switch test suite to `emqx_cth_suite` tooling.
Andrew Mayorov 2 лет назад
Родитель
Сommit
82a4e6ef68

+ 1 - 1
apps/emqx_psk/src/emqx_psk.app.src

@@ -2,7 +2,7 @@
 {application, emqx_psk, [
     {description, "EMQX PSK"},
     % strict semver, bump manually!
-    {vsn, "5.0.5"},
+    {vsn, "5.0.6"},
     {modules, []},
     {registered, [emqx_psk_sup]},
     {applications, [kernel, stdlib]},

+ 5 - 7
apps/emqx_psk/src/emqx_psk.erl

@@ -32,6 +32,7 @@
 ]).
 
 -export([
+    create_tables/0,
     start_link/0,
     stop/0
 ]).
@@ -63,10 +64,6 @@
     extra :: term()
 }).
 
--export([mnesia/1]).
-
--boot_mnesia({mnesia, [boot]}).
-
 -include("emqx_psk.hrl").
 
 -define(CR, 13).
@@ -81,8 +78,8 @@
 %%------------------------------------------------------------------------------
 
 %% @doc Create or replicate tables.
--spec mnesia(boot | copy) -> ok.
-mnesia(boot) ->
+-spec create_tables() -> [mria:table()].
+create_tables() ->
     ok = mria:create_table(?TAB, [
         {rlog_shard, ?PSK_SHARD},
         {type, ordered_set},
@@ -90,7 +87,8 @@ mnesia(boot) ->
         {record_name, psk_entry},
         {attributes, record_info(fields, psk_entry)},
         {storage_properties, [{ets, [{read_concurrency, true}]}]}
-    ]).
+    ]),
+    [?TAB].
 
 %%------------------------------------------------------------------------------
 %% Data backup

+ 1 - 1
apps/emqx_psk/src/emqx_psk_app.erl

@@ -26,7 +26,7 @@
 -include("emqx_psk.hrl").
 
 start(_Type, _Args) ->
-    ok = mria:wait_for_tables([?TAB]),
+    ok = mria:wait_for_tables(emqx_psk:create_tables()),
     emqx_conf:add_handler([?PSK_KEY], emqx_psk),
     {ok, Sup} = emqx_psk_sup:start_link(),
     {ok, Sup}.

+ 19 - 24
apps/emqx_psk/test/emqx_psk_SUITE.erl

@@ -34,30 +34,25 @@ groups() ->
     ].
 
 init_per_suite(Config) ->
-    meck:new(emqx_config, [non_strict, passthrough, no_history, no_link]),
-    meck:expect(emqx_config, get, fun
-        ([psk_authentication, enable]) -> true;
-        ([psk_authentication, chunk_size]) -> 50;
-        (KeyPath) -> meck:passthrough([KeyPath])
-    end),
-    meck:expect(emqx_config, get, fun
-        ([psk_authentication, init_file], _) ->
-            filename:join([
-                code:lib_dir(emqx_psk, test),
-                "data/init.psk"
-            ]);
-        ([psk_authentication, separator], _) ->
-            <<":">>;
-        (KeyPath, Default) ->
-            meck:passthrough([KeyPath, Default])
-    end),
-    emqx_common_test_helpers:start_apps([emqx_psk]),
-    Config.
-
-end_per_suite(_) ->
-    meck:unload(emqx_config),
-    emqx_common_test_helpers:stop_apps([emqx_psk]),
-    ok.
+    Apps = emqx_cth_suite:start(
+        [
+            emqx,
+            {emqx_psk, #{
+                config => #{
+                    psk_authentication => #{
+                        enable => true,
+                        init_file => filename:join(?config(data_dir, Config), "init.psk"),
+                        separator => <<":">>
+                    }
+                }
+            }}
+        ],
+        #{work_dir => emqx_cth_suite:work_dir(Config)}
+    ),
+    [{suite_apps, Apps} | Config].
+
+end_per_suite(Config) ->
+    ok = emqx_cth_suite:stop(?config(suite_apps, Config)).
 
 t_psk_lookup(_) ->
     PSKIdentity1 = <<"myclient1">>,

apps/emqx_psk/test/data/init.psk → apps/emqx_psk/test/emqx_psk_SUITE_data/init.psk