feat(psk): manage mria tables explicitly during startup
Also switch test suite to `emqx_cth_suite` tooling.
This commit is contained in:
parent
b07df487f0
commit
82a4e6ef68
|
@ -2,7 +2,7 @@
|
||||||
{application, emqx_psk, [
|
{application, emqx_psk, [
|
||||||
{description, "EMQX PSK"},
|
{description, "EMQX PSK"},
|
||||||
% strict semver, bump manually!
|
% strict semver, bump manually!
|
||||||
{vsn, "5.0.5"},
|
{vsn, "5.0.6"},
|
||||||
{modules, []},
|
{modules, []},
|
||||||
{registered, [emqx_psk_sup]},
|
{registered, [emqx_psk_sup]},
|
||||||
{applications, [kernel, stdlib]},
|
{applications, [kernel, stdlib]},
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-export([
|
-export([
|
||||||
|
create_tables/0,
|
||||||
start_link/0,
|
start_link/0,
|
||||||
stop/0
|
stop/0
|
||||||
]).
|
]).
|
||||||
|
@ -63,10 +64,6 @@
|
||||||
extra :: term()
|
extra :: term()
|
||||||
}).
|
}).
|
||||||
|
|
||||||
-export([mnesia/1]).
|
|
||||||
|
|
||||||
-boot_mnesia({mnesia, [boot]}).
|
|
||||||
|
|
||||||
-include("emqx_psk.hrl").
|
-include("emqx_psk.hrl").
|
||||||
|
|
||||||
-define(CR, 13).
|
-define(CR, 13).
|
||||||
|
@ -81,8 +78,8 @@
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
|
|
||||||
%% @doc Create or replicate tables.
|
%% @doc Create or replicate tables.
|
||||||
-spec mnesia(boot | copy) -> ok.
|
-spec create_tables() -> [mria:table()].
|
||||||
mnesia(boot) ->
|
create_tables() ->
|
||||||
ok = mria:create_table(?TAB, [
|
ok = mria:create_table(?TAB, [
|
||||||
{rlog_shard, ?PSK_SHARD},
|
{rlog_shard, ?PSK_SHARD},
|
||||||
{type, ordered_set},
|
{type, ordered_set},
|
||||||
|
@ -90,7 +87,8 @@ mnesia(boot) ->
|
||||||
{record_name, psk_entry},
|
{record_name, psk_entry},
|
||||||
{attributes, record_info(fields, psk_entry)},
|
{attributes, record_info(fields, psk_entry)},
|
||||||
{storage_properties, [{ets, [{read_concurrency, true}]}]}
|
{storage_properties, [{ets, [{read_concurrency, true}]}]}
|
||||||
]).
|
]),
|
||||||
|
[?TAB].
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% Data backup
|
%% Data backup
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
-include("emqx_psk.hrl").
|
-include("emqx_psk.hrl").
|
||||||
|
|
||||||
start(_Type, _Args) ->
|
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),
|
emqx_conf:add_handler([?PSK_KEY], emqx_psk),
|
||||||
{ok, Sup} = emqx_psk_sup:start_link(),
|
{ok, Sup} = emqx_psk_sup:start_link(),
|
||||||
{ok, Sup}.
|
{ok, Sup}.
|
||||||
|
|
|
@ -34,30 +34,25 @@ groups() ->
|
||||||
].
|
].
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
meck:new(emqx_config, [non_strict, passthrough, no_history, no_link]),
|
Apps = emqx_cth_suite:start(
|
||||||
meck:expect(emqx_config, get, fun
|
[
|
||||||
([psk_authentication, enable]) -> true;
|
emqx,
|
||||||
([psk_authentication, chunk_size]) -> 50;
|
{emqx_psk, #{
|
||||||
(KeyPath) -> meck:passthrough([KeyPath])
|
config => #{
|
||||||
end),
|
psk_authentication => #{
|
||||||
meck:expect(emqx_config, get, fun
|
enable => true,
|
||||||
([psk_authentication, init_file], _) ->
|
init_file => filename:join(?config(data_dir, Config), "init.psk"),
|
||||||
filename:join([
|
separator => <<":">>
|
||||||
code:lib_dir(emqx_psk, test),
|
}
|
||||||
"data/init.psk"
|
}
|
||||||
]);
|
}}
|
||||||
([psk_authentication, separator], _) ->
|
],
|
||||||
<<":">>;
|
#{work_dir => emqx_cth_suite:work_dir(Config)}
|
||||||
(KeyPath, Default) ->
|
),
|
||||||
meck:passthrough([KeyPath, Default])
|
[{suite_apps, Apps} | Config].
|
||||||
end),
|
|
||||||
emqx_common_test_helpers:start_apps([emqx_psk]),
|
|
||||||
Config.
|
|
||||||
|
|
||||||
end_per_suite(_) ->
|
end_per_suite(Config) ->
|
||||||
meck:unload(emqx_config),
|
ok = emqx_cth_suite:stop(?config(suite_apps, Config)).
|
||||||
emqx_common_test_helpers:stop_apps([emqx_psk]),
|
|
||||||
ok.
|
|
||||||
|
|
||||||
t_psk_lookup(_) ->
|
t_psk_lookup(_) ->
|
||||||
PSKIdentity1 = <<"myclient1">>,
|
PSKIdentity1 = <<"myclient1">>,
|
||||||
|
|
Loading…
Reference in New Issue