|
|
@@ -53,16 +53,16 @@ end_per_testcase(_TC, _Config) ->
|
|
|
t_lease_initial(_Config) ->
|
|
|
ConnPub = emqtt_connect_pub(<<"client_pub">>),
|
|
|
|
|
|
- %% Need to pre-reate some streams in "topic/#".
|
|
|
+ %% Need to pre-create some streams in "topic/#".
|
|
|
%% Leader is dummy by far and won't update streams after the first lease to the agent.
|
|
|
%% So there should be some streams already when the agent connects.
|
|
|
- ok = init_streams(ConnPub, <<"topic/1">>),
|
|
|
+ ok = init_streams(ConnPub, <<"topic1/1">>),
|
|
|
|
|
|
ConnShared = emqtt_connect_sub(<<"client_shared">>),
|
|
|
- {ok, _, _} = emqtt:subscribe(ConnShared, <<"$share/gr1/topic/#">>, 1),
|
|
|
+ {ok, _, _} = emqtt:subscribe(ConnShared, <<"$share/gr1/topic1/#">>, 1),
|
|
|
|
|
|
- {ok, _} = emqtt:publish(ConnPub, <<"topic/1">>, <<"hello2">>, 1),
|
|
|
- ?assertReceive({publish, #{payload := <<"hello2">>}}, 10000),
|
|
|
+ {ok, _} = emqtt:publish(ConnPub, <<"topic1/1">>, <<"hello2">>, 1),
|
|
|
+ ?assertReceive({publish, #{payload := <<"hello2">>}}, 10_000),
|
|
|
|
|
|
ok = emqtt:disconnect(ConnShared),
|
|
|
ok = emqtt:disconnect(ConnPub).
|
|
|
@@ -70,10 +70,10 @@ t_lease_initial(_Config) ->
|
|
|
t_lease_reconnect(_Config) ->
|
|
|
ConnPub = emqtt_connect_pub(<<"client_pub">>),
|
|
|
|
|
|
- %% Need to pre-reate some streams in "topic/#".
|
|
|
+ %% Need to pre-create some streams in "topic/#".
|
|
|
%% Leader is dummy by far and won't update streams after the first lease to the agent.
|
|
|
%% So there should be some streams already when the agent connects.
|
|
|
- ok = init_streams(ConnPub, <<"topic/2">>),
|
|
|
+ ok = init_streams(ConnPub, <<"topic2/2">>),
|
|
|
|
|
|
ConnShared = emqtt_connect_sub(<<"client_shared">>),
|
|
|
|
|
|
@@ -81,25 +81,52 @@ t_lease_reconnect(_Config) ->
|
|
|
ok = supervisor:terminate_child(emqx_ds_shared_sub_sup, emqx_ds_shared_sub_registry),
|
|
|
|
|
|
?assertWaitEvent(
|
|
|
- {ok, _, _} = emqtt:subscribe(ConnShared, <<"$share/gr1/topic/#">>, 1),
|
|
|
+ {ok, _, _} = emqtt:subscribe(ConnShared, <<"$share/gr2/topic2/#">>, 1),
|
|
|
#{?snk_kind := find_leader_timeout},
|
|
|
- 5000
|
|
|
+ 5_000
|
|
|
),
|
|
|
|
|
|
%% Start registry, agent should retry after some time and find the leader.
|
|
|
?assertWaitEvent(
|
|
|
{ok, _} = supervisor:restart_child(emqx_ds_shared_sub_sup, emqx_ds_shared_sub_registry),
|
|
|
#{?snk_kind := leader_lease_streams},
|
|
|
- 5000
|
|
|
+ 5_000
|
|
|
),
|
|
|
|
|
|
- {ok, _} = emqtt:publish(ConnPub, <<"topic/2">>, <<"hello2">>, 1),
|
|
|
+ ct:sleep(1_000),
|
|
|
+ {ok, _} = emqtt:publish(ConnPub, <<"topic2/2">>, <<"hello2">>, 1),
|
|
|
|
|
|
- ?assertReceive({publish, #{payload := <<"hello2">>}}, 10000),
|
|
|
+ ?assertReceive({publish, #{payload := <<"hello2">>}}, 10_000),
|
|
|
|
|
|
ok = emqtt:disconnect(ConnShared),
|
|
|
ok = emqtt:disconnect(ConnPub).
|
|
|
|
|
|
+t_renew_lease_timeout(_Config) ->
|
|
|
+ ConnShared = emqtt_connect_sub(<<"client_shared">>),
|
|
|
+
|
|
|
+ ?assertWaitEvent(
|
|
|
+ {ok, _, _} = emqtt:subscribe(ConnShared, <<"$share/gr3/topic3/#">>, 1),
|
|
|
+ #{?snk_kind := leader_lease_streams},
|
|
|
+ 5_000
|
|
|
+ ),
|
|
|
+
|
|
|
+ ?check_trace(
|
|
|
+ ?wait_async_action(
|
|
|
+ ok = terminate_leaders(),
|
|
|
+ #{?snk_kind := leader_lease_streams},
|
|
|
+ 5_000
|
|
|
+ ),
|
|
|
+ fun(Trace) ->
|
|
|
+ ?strict_causality(
|
|
|
+ #{?snk_kind := renew_lease_timeout},
|
|
|
+ #{?snk_kind := leader_lease_streams},
|
|
|
+ Trace
|
|
|
+ )
|
|
|
+ end
|
|
|
+ ),
|
|
|
+
|
|
|
+ ok = emqtt:disconnect(ConnShared).
|
|
|
+
|
|
|
%%--------------------------------------------------------------------
|
|
|
%% Helper functions
|
|
|
%%--------------------------------------------------------------------
|
|
|
@@ -109,7 +136,7 @@ init_streams(ConnPub, Topic) ->
|
|
|
{ok, _, _} = emqtt:subscribe(ConnRegular, Topic, 1),
|
|
|
{ok, _} = emqtt:publish(ConnPub, Topic, <<"hello1">>, 1),
|
|
|
|
|
|
- ?assertReceive({publish, #{payload := <<"hello1">>}}, 5000),
|
|
|
+ ?assertReceive({publish, #{payload := <<"hello1">>}}, 5_000),
|
|
|
|
|
|
ok = emqtt:disconnect(ConnRegular).
|
|
|
|
|
|
@@ -118,7 +145,7 @@ emqtt_connect_sub(ClientId) ->
|
|
|
{client_id, ClientId},
|
|
|
{clean_start, true},
|
|
|
{proto_ver, v5},
|
|
|
- {properties, #{'Session-Expiry-Interval' => 7200}}
|
|
|
+ {properties, #{'Session-Expiry-Interval' => 7_200}}
|
|
|
]),
|
|
|
{ok, _} = emqtt:connect(C),
|
|
|
C.
|