feat(ocsp_cache): give ocsp cache table an heir
This commit is contained in:
parent
f6707d1dd0
commit
04378f242c
|
@ -149,9 +149,10 @@ inject_sni_fun(ListenerID, Conf0) ->
|
|||
|
||||
init(_Args) ->
|
||||
logger:set_process_metadata(#{domain => [emqx, ocsp, cache]}),
|
||||
_ = ets:new(?CACHE_TAB, [
|
||||
emqx_tables:new(?CACHE_TAB, [
|
||||
named_table,
|
||||
protected,
|
||||
public,
|
||||
{heir, whereis(emqx_kernel_sup), none},
|
||||
{read_concurrency, true}
|
||||
]),
|
||||
?tp(ocsp_cache_init, #{}),
|
||||
|
|
|
@ -147,6 +147,7 @@ init_per_testcase(t_ocsp_responder_error_responses, Config) ->
|
|||
hocon_tconf:check_plain(emqx_schema, ConfBin, #{required => false, atom_keys => false}),
|
||||
emqx_config:put_listener_conf(Type, Name, [], ListenerOpts),
|
||||
snabbkaffe:start_trace(),
|
||||
_Heir = spawn_dummy_heir(),
|
||||
{ok, CachePid} = emqx_ocsp_cache:start_link(),
|
||||
[
|
||||
{cache_pid, CachePid}
|
||||
|
@ -164,6 +165,7 @@ init_per_testcase(_TestCase, Config) ->
|
|||
{ok, {{"HTTP/1.0", 200, 'OK'}, [], <<"ocsp response">>}}
|
||||
end
|
||||
),
|
||||
_Heir = spawn_dummy_heir(),
|
||||
{ok, CachePid} = emqx_ocsp_cache:start_link(),
|
||||
DataDir = ?config(data_dir, Config),
|
||||
Type = ssl,
|
||||
|
@ -225,6 +227,17 @@ end_per_testcase(_TestCase, Config) ->
|
|||
%% Helper functions
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
%% The real cache makes `emqx_kernel_sup' the heir to its ETS table.
|
||||
%% In some tests, we don't start the full supervision tree, so we need
|
||||
%% this dummy process.
|
||||
spawn_dummy_heir() ->
|
||||
spawn_link(fun() ->
|
||||
true = register(emqx_kernel_sup, self()),
|
||||
receive
|
||||
stop -> ok
|
||||
end
|
||||
end).
|
||||
|
||||
does_module_exist(Mod) ->
|
||||
case erlang:module_loaded(Mod) of
|
||||
true ->
|
||||
|
@ -508,11 +521,13 @@ t_request_ocsp_response_restart_cache(Config) ->
|
|||
ok
|
||||
end,
|
||||
fun(Trace) ->
|
||||
%% Only one fetch because the cache table was preserved by
|
||||
%% its heir ("emqx_kernel_sup").
|
||||
?assertMatch(
|
||||
[_, _],
|
||||
[_],
|
||||
?of_kind(ocsp_http_fetch_and_cache, Trace)
|
||||
),
|
||||
assert_http_get(2),
|
||||
assert_http_get(1),
|
||||
ok
|
||||
end
|
||||
).
|
||||
|
|
Loading…
Reference in New Issue