refactor: address review comments
This commit is contained in:
parent
64fcdb671d
commit
59b94788bf
|
@ -23,7 +23,7 @@
|
||||||
-define(SHARED_SUB_SHARD, emqx_shared_sub_shard).
|
-define(SHARED_SUB_SHARD, emqx_shared_sub_shard).
|
||||||
-define(CM_SHARD, emqx_cm_shard).
|
-define(CM_SHARD, emqx_cm_shard).
|
||||||
-define(ROUTE_SHARD, route_shard).
|
-define(ROUTE_SHARD, route_shard).
|
||||||
-define(PS_ROUTER_SHARD, ps_router_shard).
|
-define(PS_ROUTER_SHARD, persistent_session_router_shard).
|
||||||
|
|
||||||
%% Banner
|
%% Banner
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
|
@ -144,13 +144,13 @@ t_non_persistent_session_subscription(_Config) ->
|
||||||
SubTopicFilter = <<"t/#">>,
|
SubTopicFilter = <<"t/#">>,
|
||||||
?check_trace(
|
?check_trace(
|
||||||
begin
|
begin
|
||||||
ct:pal("starting"),
|
?tp(notice, "starting", #{}),
|
||||||
Client = start_client(#{
|
Client = start_client(#{
|
||||||
clientid => ClientId,
|
clientid => ClientId,
|
||||||
properties => #{'Session-Expiry-Interval' => 0}
|
properties => #{'Session-Expiry-Interval' => 0}
|
||||||
}),
|
}),
|
||||||
{ok, _} = emqtt:connect(Client),
|
{ok, _} = emqtt:connect(Client),
|
||||||
ct:pal("subscribing"),
|
?tp(notice, "subscribing", #{}),
|
||||||
{ok, _, [?RC_GRANTED_QOS_2]} = emqtt:subscribe(Client, SubTopicFilter, qos2),
|
{ok, _, [?RC_GRANTED_QOS_2]} = emqtt:subscribe(Client, SubTopicFilter, qos2),
|
||||||
IteratorRefs = get_all_iterator_refs(node()),
|
IteratorRefs = get_all_iterator_refs(node()),
|
||||||
IteratorIds = get_all_iterator_ids(node()),
|
IteratorIds = get_all_iterator_ids(node()),
|
||||||
|
@ -198,7 +198,7 @@ t_session_subscription_idempotency(Config) ->
|
||||||
|
|
||||||
spawn_link(fun() ->
|
spawn_link(fun() ->
|
||||||
?tp(will_restart_node, #{}),
|
?tp(will_restart_node, #{}),
|
||||||
ct:pal("restarting node ~p", [Node1]),
|
?tp(notice, "restarting node", #{node => Node1}),
|
||||||
true = monitor_node(Node1, true),
|
true = monitor_node(Node1, true),
|
||||||
ok = erpc:call(Node1, init, restart, []),
|
ok = erpc:call(Node1, init, restart, []),
|
||||||
receive
|
receive
|
||||||
|
@ -207,10 +207,10 @@ t_session_subscription_idempotency(Config) ->
|
||||||
after 10_000 ->
|
after 10_000 ->
|
||||||
ct:fail("node ~p didn't stop", [Node1])
|
ct:fail("node ~p didn't stop", [Node1])
|
||||||
end,
|
end,
|
||||||
ct:pal("waiting for nodeup ~p", [Node1]),
|
?tp(notice, "waiting for nodeup", #{node => Node1}),
|
||||||
wait_nodeup(Node1),
|
wait_nodeup(Node1),
|
||||||
wait_gen_rpc_down(Node1Spec),
|
wait_gen_rpc_down(Node1Spec),
|
||||||
ct:pal("restarting apps on ~p", [Node1]),
|
?tp(notice, "restarting apps", #{node => Node1}),
|
||||||
Apps = maps:get(apps, Node1Spec),
|
Apps = maps:get(apps, Node1Spec),
|
||||||
ok = erpc:call(Node1, emqx_cth_suite, load_apps, [Apps]),
|
ok = erpc:call(Node1, emqx_cth_suite, load_apps, [Apps]),
|
||||||
_ = erpc:call(Node1, emqx_cth_suite, start_apps, [Apps, Node1Spec]),
|
_ = erpc:call(Node1, emqx_cth_suite, start_apps, [Apps, Node1Spec]),
|
||||||
|
@ -218,15 +218,15 @@ t_session_subscription_idempotency(Config) ->
|
||||||
%% end....
|
%% end....
|
||||||
ok = emqx_cth_cluster:set_node_opts(Node1, Node1Spec),
|
ok = emqx_cth_cluster:set_node_opts(Node1, Node1Spec),
|
||||||
ok = snabbkaffe:forward_trace(Node1),
|
ok = snabbkaffe:forward_trace(Node1),
|
||||||
ct:pal("node ~p restarted", [Node1]),
|
?tp(notice, "node restarted", #{node => Node1}),
|
||||||
?tp(restarted_node, #{}),
|
?tp(restarted_node, #{}),
|
||||||
ok
|
ok
|
||||||
end),
|
end),
|
||||||
|
|
||||||
ct:pal("starting 1"),
|
?tp(notice, "starting 1", #{}),
|
||||||
Client0 = start_client(#{port => Port, clientid => ClientId}),
|
Client0 = start_client(#{port => Port, clientid => ClientId}),
|
||||||
{ok, _} = emqtt:connect(Client0),
|
{ok, _} = emqtt:connect(Client0),
|
||||||
ct:pal("subscribing 1"),
|
?tp(notice, "subscribing 1", #{}),
|
||||||
process_flag(trap_exit, true),
|
process_flag(trap_exit, true),
|
||||||
catch emqtt:subscribe(Client0, SubTopicFilter, qos2),
|
catch emqtt:subscribe(Client0, SubTopicFilter, qos2),
|
||||||
receive
|
receive
|
||||||
|
@ -237,10 +237,10 @@ t_session_subscription_idempotency(Config) ->
|
||||||
process_flag(trap_exit, false),
|
process_flag(trap_exit, false),
|
||||||
|
|
||||||
{ok, _} = ?block_until(#{?snk_kind := restarted_node}, 15_000),
|
{ok, _} = ?block_until(#{?snk_kind := restarted_node}, 15_000),
|
||||||
ct:pal("starting 2"),
|
?tp(notice, "starting 2", #{}),
|
||||||
Client1 = start_client(#{port => Port, clientid => ClientId}),
|
Client1 = start_client(#{port => Port, clientid => ClientId}),
|
||||||
{ok, _} = emqtt:connect(Client1),
|
{ok, _} = emqtt:connect(Client1),
|
||||||
ct:pal("subscribing 2"),
|
?tp(notice, "subscribing 2", #{}),
|
||||||
{ok, _, [2]} = emqtt:subscribe(Client1, SubTopicFilter, qos2),
|
{ok, _, [2]} = emqtt:subscribe(Client1, SubTopicFilter, qos2),
|
||||||
|
|
||||||
ok = emqtt:stop(Client1),
|
ok = emqtt:stop(Client1),
|
||||||
|
@ -286,7 +286,7 @@ t_session_unsubscription_idempotency(Config) ->
|
||||||
|
|
||||||
spawn_link(fun() ->
|
spawn_link(fun() ->
|
||||||
?tp(will_restart_node, #{}),
|
?tp(will_restart_node, #{}),
|
||||||
ct:pal("restarting node ~p", [Node1]),
|
?tp(notice, "restarting node", #{node => Node1}),
|
||||||
true = monitor_node(Node1, true),
|
true = monitor_node(Node1, true),
|
||||||
ok = erpc:call(Node1, init, restart, []),
|
ok = erpc:call(Node1, init, restart, []),
|
||||||
receive
|
receive
|
||||||
|
@ -295,10 +295,10 @@ t_session_unsubscription_idempotency(Config) ->
|
||||||
after 10_000 ->
|
after 10_000 ->
|
||||||
ct:fail("node ~p didn't stop", [Node1])
|
ct:fail("node ~p didn't stop", [Node1])
|
||||||
end,
|
end,
|
||||||
ct:pal("waiting for nodeup ~p", [Node1]),
|
?tp(notice, "waiting for nodeup", #{node => Node1}),
|
||||||
wait_nodeup(Node1),
|
wait_nodeup(Node1),
|
||||||
wait_gen_rpc_down(Node1Spec),
|
wait_gen_rpc_down(Node1Spec),
|
||||||
ct:pal("restarting apps on ~p", [Node1]),
|
?tp(notice, "restarting apps", #{node => Node1}),
|
||||||
Apps = maps:get(apps, Node1Spec),
|
Apps = maps:get(apps, Node1Spec),
|
||||||
ok = erpc:call(Node1, emqx_cth_suite, load_apps, [Apps]),
|
ok = erpc:call(Node1, emqx_cth_suite, load_apps, [Apps]),
|
||||||
_ = erpc:call(Node1, emqx_cth_suite, start_apps, [Apps, Node1Spec]),
|
_ = erpc:call(Node1, emqx_cth_suite, start_apps, [Apps, Node1Spec]),
|
||||||
|
@ -306,17 +306,17 @@ t_session_unsubscription_idempotency(Config) ->
|
||||||
%% end....
|
%% end....
|
||||||
ok = emqx_cth_cluster:set_node_opts(Node1, Node1Spec),
|
ok = emqx_cth_cluster:set_node_opts(Node1, Node1Spec),
|
||||||
ok = snabbkaffe:forward_trace(Node1),
|
ok = snabbkaffe:forward_trace(Node1),
|
||||||
ct:pal("node ~p restarted", [Node1]),
|
?tp(notice, "node restarted", #{node => Node1}),
|
||||||
?tp(restarted_node, #{}),
|
?tp(restarted_node, #{}),
|
||||||
ok
|
ok
|
||||||
end),
|
end),
|
||||||
|
|
||||||
ct:pal("starting 1"),
|
?tp(notice, "starting 1", #{}),
|
||||||
Client0 = start_client(#{port => Port, clientid => ClientId}),
|
Client0 = start_client(#{port => Port, clientid => ClientId}),
|
||||||
{ok, _} = emqtt:connect(Client0),
|
{ok, _} = emqtt:connect(Client0),
|
||||||
ct:pal("subscribing 1"),
|
?tp(notice, "subscribing 1", #{}),
|
||||||
{ok, _, [?RC_GRANTED_QOS_2]} = emqtt:subscribe(Client0, SubTopicFilter, qos2),
|
{ok, _, [?RC_GRANTED_QOS_2]} = emqtt:subscribe(Client0, SubTopicFilter, qos2),
|
||||||
ct:pal("unsubscribing 1"),
|
?tp(notice, "unsubscribing 1", #{}),
|
||||||
process_flag(trap_exit, true),
|
process_flag(trap_exit, true),
|
||||||
catch emqtt:unsubscribe(Client0, SubTopicFilter),
|
catch emqtt:unsubscribe(Client0, SubTopicFilter),
|
||||||
receive
|
receive
|
||||||
|
@ -327,12 +327,12 @@ t_session_unsubscription_idempotency(Config) ->
|
||||||
process_flag(trap_exit, false),
|
process_flag(trap_exit, false),
|
||||||
|
|
||||||
{ok, _} = ?block_until(#{?snk_kind := restarted_node}, 15_000),
|
{ok, _} = ?block_until(#{?snk_kind := restarted_node}, 15_000),
|
||||||
ct:pal("starting 2"),
|
?tp(notice, "starting 2", #{}),
|
||||||
Client1 = start_client(#{port => Port, clientid => ClientId}),
|
Client1 = start_client(#{port => Port, clientid => ClientId}),
|
||||||
{ok, _} = emqtt:connect(Client1),
|
{ok, _} = emqtt:connect(Client1),
|
||||||
ct:pal("subscribing 2"),
|
?tp(notice, "subscribing 2", #{}),
|
||||||
{ok, _, [?RC_GRANTED_QOS_2]} = emqtt:subscribe(Client1, SubTopicFilter, qos2),
|
{ok, _, [?RC_GRANTED_QOS_2]} = emqtt:subscribe(Client1, SubTopicFilter, qos2),
|
||||||
ct:pal("unsubscribing 2"),
|
?tp(notice, "unsubscribing 2", #{}),
|
||||||
{{ok, _, [?RC_SUCCESS]}, {ok, _}} =
|
{{ok, _, [?RC_SUCCESS]}, {ok, _}} =
|
||||||
?wait_async_action(
|
?wait_async_action(
|
||||||
emqtt:unsubscribe(Client1, SubTopicFilter),
|
emqtt:unsubscribe(Client1, SubTopicFilter),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Copyright (c) 2022-2023 EMQ Technologies Co., Ltd. All Rights Reserved.
|
%% Copyright (c) 2023 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||||
%%
|
%%
|
||||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
%% you may not use this file except in compliance with the License.
|
%% you may not use this file except in compliance with the License.
|
||||||
|
@ -19,14 +19,12 @@
|
||||||
-define(PS_ROUTER_TAB, emqx_ds_ps_router).
|
-define(PS_ROUTER_TAB, emqx_ds_ps_router).
|
||||||
-define(PS_FILTERS_TAB, emqx_ds_ps_filters).
|
-define(PS_FILTERS_TAB, emqx_ds_ps_filters).
|
||||||
|
|
||||||
-type dest() :: emqx_ds:session_id().
|
|
||||||
|
|
||||||
-record(ps_route, {
|
-record(ps_route, {
|
||||||
topic :: binary(),
|
topic :: binary(),
|
||||||
dest :: emqx_ds:session_id()
|
dest :: emqx_ds:session_id()
|
||||||
}).
|
}).
|
||||||
-record(ps_routeidx, {
|
-record(ps_routeidx, {
|
||||||
entry :: emqx_topic_index:key(dest()),
|
entry :: emqx_topic_index:key(emqx_persistent_session_ds_router:dest()),
|
||||||
unused = [] :: nil()
|
unused = [] :: nil()
|
||||||
}).
|
}).
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,10 @@
|
||||||
-export([has_route/2]).
|
-export([has_route/2]).
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
|
-type dest() :: emqx_ds:session_id().
|
||||||
|
|
||||||
|
-export_type([dest/0]).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Table Initialization
|
%% Table Initialization
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
-compile(export_all).
|
-compile(export_all).
|
||||||
-compile(nowarn_export_all).
|
-compile(nowarn_export_all).
|
||||||
|
|
||||||
|
-import(emqx_common_test_helpers, [on_exit/1]).
|
||||||
|
|
||||||
-define(DS_SHARD, <<"local">>).
|
-define(DS_SHARD, <<"local">>).
|
||||||
|
|
||||||
all() ->
|
all() ->
|
||||||
|
@ -34,33 +36,31 @@ init_per_suite(Config) ->
|
||||||
%% TODO: remove after other suites start to use `emx_cth_suite'
|
%% TODO: remove after other suites start to use `emx_cth_suite'
|
||||||
application:stop(emqx),
|
application:stop(emqx),
|
||||||
application:stop(emqx_durable_storage),
|
application:stop(emqx_durable_storage),
|
||||||
TCApps = emqx_cth_suite:start(
|
Config.
|
||||||
app_specs(),
|
|
||||||
#{work_dir => emqx_cth_suite:work_dir(Config)}
|
|
||||||
),
|
|
||||||
[{tc_apps, TCApps} | Config].
|
|
||||||
|
|
||||||
end_per_suite(Config) ->
|
end_per_suite(_Config) ->
|
||||||
TCApps = ?config(tc_apps, Config),
|
|
||||||
emqx_cth_suite:stop(TCApps),
|
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
init_per_testcase(t_session_subscription_iterators, Config) ->
|
init_per_testcase(t_session_subscription_iterators = TestCase, Config) ->
|
||||||
Cluster = cluster(),
|
Cluster = cluster(),
|
||||||
Nodes = emqx_cth_cluster:start(Cluster, #{work_dir => ?config(priv_dir, Config)}),
|
Nodes = emqx_cth_cluster:start(Cluster, #{work_dir => emqx_cth_suite:work_dir(TestCase, Config)}),
|
||||||
[{nodes, Nodes} | Config];
|
[{nodes, Nodes} | Config];
|
||||||
init_per_testcase(_TestCase, Config) ->
|
init_per_testcase(TestCase, Config) ->
|
||||||
Config.
|
Apps = emqx_cth_suite:start(
|
||||||
|
app_specs(),
|
||||||
|
#{work_dir => emqx_cth_suite:work_dir(TestCase, Config)}
|
||||||
|
),
|
||||||
|
[{apps, Apps} | Config].
|
||||||
|
|
||||||
end_per_testcase(t_session_subscription_iterators, Config) ->
|
end_per_testcase(t_session_subscription_iterators, Config) ->
|
||||||
Nodes = ?config(nodes, Config),
|
Nodes = ?config(nodes, Config),
|
||||||
|
emqx_common_test_helpers:call_janitor(60_000),
|
||||||
ok = emqx_cth_cluster:stop(Nodes),
|
ok = emqx_cth_cluster:stop(Nodes),
|
||||||
ok = emqx_ds_storage_layer:discard_iterator_prefix(?DS_SHARD, _Prefix = <<>>),
|
|
||||||
delete_all_messages(),
|
|
||||||
ok;
|
ok;
|
||||||
end_per_testcase(_TestCase, _Config) ->
|
end_per_testcase(_TestCase, Config) ->
|
||||||
ok = emqx_ds_storage_layer:discard_iterator_prefix(?DS_SHARD, _Prefix = <<>>),
|
Apps = ?config(apps, Config),
|
||||||
delete_all_messages(),
|
emqx_common_test_helpers:call_janitor(60_000),
|
||||||
|
emqx_cth_suite:stop(Apps),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
t_messages_persisted(_Config) ->
|
t_messages_persisted(_Config) ->
|
||||||
|
@ -256,6 +256,7 @@ connect(Opts0 = #{}) ->
|
||||||
Defaults = #{proto_ver => v5},
|
Defaults = #{proto_ver => v5},
|
||||||
Opts = maps:to_list(emqx_utils_maps:deep_merge(Defaults, Opts0)),
|
Opts = maps:to_list(emqx_utils_maps:deep_merge(Defaults, Opts0)),
|
||||||
{ok, Client} = emqtt:start_link(Opts),
|
{ok, Client} = emqtt:start_link(Opts),
|
||||||
|
on_exit(fun() -> catch emqtt:stop(Client) end),
|
||||||
{ok, _} = emqtt:connect(Client),
|
{ok, _} = emqtt:connect(Client),
|
||||||
Client.
|
Client.
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Copyright (c) 2017-2023 EMQ Technologies Co., Ltd. All Rights Reserved.
|
%% Copyright (c) 2023 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||||
%%
|
%%
|
||||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
%% you may not use this file except in compliance with the License.
|
%% you may not use this file except in compliance with the License.
|
||||||
|
|
Loading…
Reference in New Issue