|
|
@@ -51,21 +51,34 @@ end_per_suite(_Config) ->
|
|
|
ok.
|
|
|
|
|
|
init_per_testcase(_TestCase, Config) ->
|
|
|
+ %% CM Meck
|
|
|
+ ok = meck:new(emqx_cm, [passthrough, no_history]),
|
|
|
+ %% Access Control Meck
|
|
|
+ ok = meck:new(emqx_access_control, [passthrough, no_history]),
|
|
|
+ ok = meck:expect(emqx_access_control, authenticate,
|
|
|
+ fun(_) -> {ok, #{auth_result => success}} end),
|
|
|
+ ok = meck:expect(emqx_access_control, check_acl, fun(_, _, _) -> allow end),
|
|
|
+ %% Broker Meck
|
|
|
ok = meck:new(emqx_broker, [passthrough, no_history]),
|
|
|
+ %% Hooks Meck
|
|
|
ok = meck:new(emqx_hooks, [passthrough, no_history]),
|
|
|
ok = meck:expect(emqx_hooks, run, fun(_Hook, _Args) -> ok end),
|
|
|
ok = meck:expect(emqx_hooks, run_fold, fun(_Hook, _Args, Acc) -> Acc end),
|
|
|
+ %% Session Meck
|
|
|
ok = meck:new(emqx_session, [passthrough, no_history]),
|
|
|
+ %% Metrics
|
|
|
ok = meck:new(emqx_metrics, [passthrough, no_history]),
|
|
|
ok = meck:expect(emqx_metrics, inc, fun(_) -> ok end),
|
|
|
ok = meck:expect(emqx_metrics, inc, fun(_, _) -> ok end),
|
|
|
Config.
|
|
|
|
|
|
end_per_testcase(_TestCase, Config) ->
|
|
|
+ ok = meck:unload(emqx_access_control),
|
|
|
ok = meck:unload(emqx_metrics),
|
|
|
ok = meck:unload(emqx_session),
|
|
|
ok = meck:unload(emqx_broker),
|
|
|
ok = meck:unload(emqx_hooks),
|
|
|
+ ok = meck:unload(emqx_cm),
|
|
|
Config.
|
|
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
@@ -106,9 +119,12 @@ t_chan_init(_) ->
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
|
|
t_handle_in_connect_packet_sucess(_) ->
|
|
|
- ConnAck = ?CONNACK_PACKET(?RC_SUCCESS, 0, #{}),
|
|
|
- {ok, {connack, ConnAck}, Channel}
|
|
|
- = emqx_channel:handle_in(?CONNECT_PACKET(connpkt()), channel()),
|
|
|
+ ok = meck:expect(emqx_cm, open_session,
|
|
|
+ fun(true, _ClientInfo, _ConnInfo) ->
|
|
|
+ {ok, #{session => session(), present => false}}
|
|
|
+ end),
|
|
|
+ {ok, [{connack, ?CONNACK_PACKET(?RC_SUCCESS, 0)}], Channel}
|
|
|
+ = emqx_channel:handle_in(?CONNECT_PACKET(connpkt()), channel(#{conn_state => idle})),
|
|
|
ClientInfo = emqx_channel:info(clientinfo, Channel),
|
|
|
?assertMatch(#{clientid := <<"clientid">>,
|
|
|
username := <<"username">>
|
|
|
@@ -117,8 +133,8 @@ t_handle_in_connect_packet_sucess(_) ->
|
|
|
|
|
|
t_handle_in_unexpected_connect_packet(_) ->
|
|
|
Channel = emqx_channel:set_field(conn_state, connected, channel()),
|
|
|
- Result = emqx_channel:handle_in(?CONNECT_PACKET(connpkt()), Channel),
|
|
|
- ?assertEqual({shutdown, protocol_error, Channel}, Result).
|
|
|
+ {shutdown, protocol_error, ?DISCONNECT_PACKET(?RC_PROTOCOL_ERROR), Channel}
|
|
|
+ = emqx_channel:handle_in(?CONNECT_PACKET(connpkt()), Channel).
|
|
|
|
|
|
t_handle_in_qos0_publish(_) ->
|
|
|
ok = meck:expect(emqx_broker, publish, fun(_) -> ok end),
|
|
|
@@ -133,15 +149,16 @@ t_handle_in_qos1_publish(_) ->
|
|
|
Publish = ?PUBLISH_PACKET(?QOS_1, <<"topic">>, 1, <<"payload">>),
|
|
|
{ok, ?PUBACK_PACKET(1, RC), NChannel} = emqx_channel:handle_in(Publish, Channel),
|
|
|
?assert((RC == ?RC_SUCCESS) orelse (RC == ?RC_NO_MATCHING_SUBSCRIBERS)),
|
|
|
- ?assertEqual(#{publish_in => 1}, emqx_channel:info(pub_stats, NChannel)).
|
|
|
+ ?assertEqual(#{publish_in => 1, puback_out => 1}, emqx_channel:info(pub_stats, NChannel)).
|
|
|
|
|
|
t_handle_in_qos2_publish(_) ->
|
|
|
ok = meck:expect(emqx_session, publish, fun(_, _Msg, Session) -> {ok, [], Session} end),
|
|
|
+ ok = meck:expect(emqx_session, info, fun(awaiting_rel_timeout, _Session) -> 300000 end),
|
|
|
Channel = channel(#{conn_state => connected}),
|
|
|
Publish = ?PUBLISH_PACKET(?QOS_2, <<"topic">>, 1, <<"payload">>),
|
|
|
{ok, ?PUBREC_PACKET(1, RC), NChannel} = emqx_channel:handle_in(Publish, Channel),
|
|
|
?assert((RC == ?RC_SUCCESS) orelse (RC == ?RC_NO_MATCHING_SUBSCRIBERS)),
|
|
|
- ?assertEqual(#{publish_in => 1}, emqx_channel:info(pub_stats, NChannel)).
|
|
|
+ ?assertEqual(#{publish_in => 1, pubrec_out => 1}, emqx_channel:info(pub_stats, NChannel)).
|
|
|
|
|
|
t_handle_in_puback_ok(_) ->
|
|
|
Msg = emqx_message:make(<<"t">>, <<"payload">>),
|
|
|
@@ -156,18 +173,16 @@ t_handle_in_puback_id_in_use(_) ->
|
|
|
fun(_, _Session) ->
|
|
|
{error, ?RC_PACKET_IDENTIFIER_IN_USE}
|
|
|
end),
|
|
|
- Channel = channel(#{conn_state => connected}),
|
|
|
- PubAck = ?PUBACK_PACKET(1, ?RC_SUCCESS),
|
|
|
- {ok, Channel} = emqx_channel:handle_in(PubAck, Channel).
|
|
|
+ {ok, Channel} = emqx_channel:handle_in(?PUBACK_PACKET(1, ?RC_SUCCESS), channel()),
|
|
|
+ ?assertEqual(#{puback_in => 1}, emqx_channel:info(pub_stats, Channel)).
|
|
|
|
|
|
t_handle_in_puback_id_not_found(_) ->
|
|
|
ok = meck:expect(emqx_session, puback,
|
|
|
fun(_, _Session) ->
|
|
|
{error, ?RC_PACKET_IDENTIFIER_NOT_FOUND}
|
|
|
end),
|
|
|
- Channel = channel(#{conn_state => connected}),
|
|
|
- PubAck = ?PUBACK_PACKET(1, ?RC_SUCCESS),
|
|
|
- {ok, Channel} = emqx_channel:handle_in(PubAck, Channel).
|
|
|
+ {ok, Channel} = emqx_channel:handle_in(?PUBACK_PACKET(1, ?RC_SUCCESS), channel()),
|
|
|
+ ?assertEqual(#{puback_in => 1}, emqx_channel:info(pub_stats, Channel)).
|
|
|
|
|
|
t_handle_in_pubrec_ok(_) ->
|
|
|
Msg = emqx_message:make(test,?QOS_2, <<"t">>, <<"payload">>),
|
|
|
@@ -183,18 +198,20 @@ t_handle_in_pubrec_id_in_use(_) ->
|
|
|
fun(_, Session) ->
|
|
|
{error, ?RC_PACKET_IDENTIFIER_IN_USE}
|
|
|
end),
|
|
|
- Channel = channel(#{conn_state => connected}),
|
|
|
{ok, ?PUBREL_PACKET(1, ?RC_PACKET_IDENTIFIER_IN_USE), Channel}
|
|
|
- = emqx_channel:handle_in(?PUBREC_PACKET(1, ?RC_SUCCESS), Channel).
|
|
|
+ = emqx_channel:handle_in(?PUBREC_PACKET(1, ?RC_SUCCESS), channel()),
|
|
|
+ ?assertEqual(#{pubrec_in => 1, pubrel_out => 1},
|
|
|
+ emqx_channel:info(pub_stats, Channel)).
|
|
|
|
|
|
t_handle_in_pubrec_id_not_found(_) ->
|
|
|
ok = meck:expect(emqx_session, pubrec,
|
|
|
fun(_, Session) ->
|
|
|
{error, ?RC_PACKET_IDENTIFIER_NOT_FOUND}
|
|
|
end),
|
|
|
- Channel = channel(#{conn_state => connected}),
|
|
|
{ok, ?PUBREL_PACKET(1, ?RC_PACKET_IDENTIFIER_NOT_FOUND), Channel}
|
|
|
- = emqx_channel:handle_in(?PUBREC_PACKET(1, ?RC_SUCCESS), Channel).
|
|
|
+ = emqx_channel:handle_in(?PUBREC_PACKET(1, ?RC_SUCCESS), channel()),
|
|
|
+ ?assertEqual(#{pubrec_in => 1, pubrel_out => 1},
|
|
|
+ emqx_channel:info(pub_stats, Channel)).
|
|
|
|
|
|
t_handle_in_pubrel_ok(_) ->
|
|
|
ok = meck:expect(emqx_session, pubrel, fun(_, Session) -> {ok, Session} end),
|
|
|
@@ -209,15 +226,13 @@ t_handle_in_pubrel_not_found_error(_) ->
|
|
|
fun(_PacketId, _Session) ->
|
|
|
{error, ?RC_PACKET_IDENTIFIER_NOT_FOUND}
|
|
|
end),
|
|
|
- Channel = channel(#{conn_state => connected}),
|
|
|
- {ok, ?PUBCOMP_PACKET(1, ?RC_PACKET_IDENTIFIER_NOT_FOUND), Channel}
|
|
|
- = emqx_channel:handle_in(?PUBREL_PACKET(1, ?RC_SUCCESS), Channel).
|
|
|
+ {ok, ?PUBCOMP_PACKET(1, ?RC_PACKET_IDENTIFIER_NOT_FOUND), _Channel}
|
|
|
+ = emqx_channel:handle_in(?PUBREL_PACKET(1, ?RC_SUCCESS), channel()).
|
|
|
|
|
|
t_handle_in_pubcomp_ok(_) ->
|
|
|
ok = meck:expect(emqx_session, pubcomp, fun(_, Session) -> {ok, Session} end),
|
|
|
- Channel = channel(#{conn_state => connected}),
|
|
|
- {ok, Channel1} = emqx_channel:handle_in(?PUBCOMP_PACKET(1, ?RC_SUCCESS), Channel),
|
|
|
- ?assertEqual(#{pubcomp_in => 1}, emqx_channel:info(pub_stats, Channel1)).
|
|
|
+ {ok, Channel} = emqx_channel:handle_in(?PUBCOMP_PACKET(1, ?RC_SUCCESS), channel()),
|
|
|
+ ?assertEqual(#{pubcomp_in => 1}, emqx_channel:info(pub_stats, Channel)).
|
|
|
|
|
|
t_handle_in_pubcomp_not_found_error(_) ->
|
|
|
ok = meck:expect(emqx_session, pubcomp,
|
|
|
@@ -270,35 +285,38 @@ t_handle_in_frame_error(_) ->
|
|
|
{shutdown, frame_too_large, ?CONNACK_PACKET(?RC_MALFORMED_PACKET), _}
|
|
|
= emqx_channel:handle_in({frame_error, frame_too_large}, ConnectingChan),
|
|
|
ConnectedChan = channel(#{conn_state => connected}),
|
|
|
- {shutdown, frame_too_large, ?DISCONNECT_PACKET(?RC_MALFORMED_PACKET), _}
|
|
|
+ {shutdown, malformed_Packet, ?DISCONNECT_PACKET(?RC_MALFORMED_PACKET), _}
|
|
|
= emqx_channel:handle_in({frame_error, frame_too_large}, ConnectedChan),
|
|
|
DisconnectedChan = channel(#{conn_state => disconnected}),
|
|
|
{ok, DisconnectedChan}
|
|
|
= emqx_channel:handle_in({frame_error, frame_too_large}, DisconnectedChan).
|
|
|
|
|
|
+%% TODO:
|
|
|
t_handle_in_expected_packet(_) ->
|
|
|
- {ok, _Chan} = emqx_channel:handle_in(packet, channel()).
|
|
|
+ {shutdown, protocol_error, ?DISCONNECT_PACKET(?RC_PROTOCOL_ERROR), _Chan}
|
|
|
+ = emqx_channel:handle_in(packet, channel()).
|
|
|
|
|
|
t_process_connect(_) ->
|
|
|
ok = meck:expect(emqx_cm, open_session,
|
|
|
fun(true, _ClientInfo, _ConnInfo) ->
|
|
|
{ok, #{session => session(), present => false}}
|
|
|
end),
|
|
|
- ConnPkt = connpkt(),
|
|
|
- {ok, ?CONNACK_PACKET(?RC_SUCCESS), ConnPkt, _}
|
|
|
- = emqx_channel:process_connect(ConnPkt, channel()).
|
|
|
+ {ok, [{connack, ?CONNACK_PACKET(?RC_SUCCESS)}], _Channel}
|
|
|
+ = emqx_channel:process_connect(connpkt(), channel(#{conn_state => idle})).
|
|
|
|
|
|
-t_handle_publish(_) ->
|
|
|
- Publish = ?PUBLISH_PACKET(?QOS_1, <<"t">>, 1, <<"payload">>),
|
|
|
- {ok, ?PUBACK_PACKET(1, ?RC_SUCCESS), _Channel}
|
|
|
- = emqx_channel:handle_publish(Publish, channel()).
|
|
|
+t_handle_publish_qos0(_) ->
|
|
|
+ ok = meck:expect(emqx_broker, publish, fun(_) -> [] end),
|
|
|
+ Publish = ?PUBLISH_PACKET(?QOS_0, <<"t">>, 1, <<"payload">>),
|
|
|
+ {ok, _Channel} = emqx_channel:handle_publish(Publish, channel()).
|
|
|
|
|
|
t_process_publish_qos1(_) ->
|
|
|
+ ok = meck:expect(emqx_broker, publish, fun(_) -> [] end),
|
|
|
Msg = emqx_message:make(test, ?QOS_1, <<"t">>, <<"payload">>),
|
|
|
- {ok, ?PUBACK_PACKET(1, ?RC_SUCCESS), _Channel}
|
|
|
+ {ok, ?PUBACK_PACKET(1, ?RC_NO_MATCHING_SUBSCRIBERS), _Channel}
|
|
|
= emqx_channel:process_publish(1, Msg, channel()).
|
|
|
|
|
|
t_process_subscribe(_) ->
|
|
|
+ ok = meck:expect(emqx_session, subscribe, fun(_, _, _, Session) -> {ok, Session} end),
|
|
|
TopicFilters = [{<<"+">>, ?DEFAULT_SUBOPTS}],
|
|
|
{[?RC_SUCCESS], _Channel} = emqx_channel:process_subscribe(TopicFilters, channel()).
|
|
|
|
|
|
@@ -312,11 +330,17 @@ t_process_unsubscribe(_) ->
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
|
|
t_handle_out_delivers(_) ->
|
|
|
- ok = emqx_meck:expect(emqx_session, deliver,
|
|
|
- fun(Delivers, Session) ->
|
|
|
- Msgs = [Msg || {deliver, _, Msg} <- Delivers],
|
|
|
- [{publish, PacketId, Msg} || {PacketId, Msg} <- lists:zip(lists:seq(1, length(Msgs)), Msgs)]
|
|
|
- end),
|
|
|
+ WithPacketId = fun(Msgs) ->
|
|
|
+ lists:zip(lists:seq(1, length(Msgs)), Msgs)
|
|
|
+ end,
|
|
|
+ ok = meck:expect(emqx_session, deliver,
|
|
|
+ fun(Delivers, Session) ->
|
|
|
+ Msgs = [Msg || {deliver, _, Msg} <- Delivers],
|
|
|
+ Publishes = [{publish, PacketId, Msg}
|
|
|
+ || {PacketId, Msg} <- WithPacketId(Msgs)],
|
|
|
+ {ok, Publishes, Session}
|
|
|
+ end),
|
|
|
+ ok = meck:expect(emqx_session, info, fun(retry_interval, _Session) -> 20000 end),
|
|
|
Msg0 = emqx_message:make(test, ?QOS_1, <<"t1">>, <<"qos1">>),
|
|
|
Msg1 = emqx_message:make(test, ?QOS_2, <<"t2">>, <<"qos2">>),
|
|
|
Delivers = [{deliver, <<"+">>, Msg0}, {deliver, <<"+">>, Msg1}],
|
|
|
@@ -334,7 +358,7 @@ t_handle_out_publishes(_) ->
|
|
|
|
|
|
t_handle_out_publish(_) ->
|
|
|
Msg = emqx_message:make(<<"clientid">>, ?QOS_1, <<"t">>, <<"payload">>),
|
|
|
- {ok, ?PUBLISH_PACKET(?QOS_1, <<"t">>, <<"payload">>), _Channel}
|
|
|
+ {ok, ?PUBLISH_PACKET(?QOS_1, <<"t">>, 1, <<"payload">>), _Chan}
|
|
|
= emqx_channel:handle_out({publish, 1, Msg}, channel()).
|
|
|
|
|
|
t_handle_out_publish_nl(_) ->
|
|
|
@@ -345,13 +369,12 @@ t_handle_out_publish_nl(_) ->
|
|
|
{ok, Channel} = emqx_channel:handle_out(Publish, Channel).
|
|
|
|
|
|
t_handle_out_connack_sucess(_) ->
|
|
|
- Channel = channel(#{conn_state => connected}),
|
|
|
- {ok, {connack, ?CONNACK_PACKET(?RC_SUCCESS, SP, _)}, _Chan}
|
|
|
- = emqx_channel:handle_out({connack, ?RC_SUCCESS, 0, connpkt()}, Channel).
|
|
|
+ {ok, [{connack, ?CONNACK_PACKET(?RC_SUCCESS, SP, _)}], _Chan}
|
|
|
+ = emqx_channel:handle_out(connack, {?RC_SUCCESS, 0, connpkt()}, channel()).
|
|
|
|
|
|
t_handle_out_connack_failure(_) ->
|
|
|
{shutdown, not_authorized, ?CONNACK_PACKET(?RC_NOT_AUTHORIZED), _Chan}
|
|
|
- = emqx_channel:handle_out({connack, ?RC_NOT_AUTHORIZED, connpkt()}, channel()).
|
|
|
+ = emqx_channel:handle_out(connack, {?RC_NOT_AUTHORIZED, connpkt()}, channel()).
|
|
|
|
|
|
t_handle_out_puback(_) ->
|
|
|
Channel = channel(#{conn_state => connected}),
|
|
|
@@ -362,33 +385,33 @@ t_handle_out_puback(_) ->
|
|
|
t_handle_out_pubrec(_) ->
|
|
|
Channel = channel(#{conn_state => connected}),
|
|
|
{ok, ?PUBREC_PACKET(1, ?RC_SUCCESS), NChannel}
|
|
|
- = emqx_channel:handle_out({pubrec, 1, ?RC_SUCCESS}, Channel),
|
|
|
+ = emqx_channel:handle_out(pubrec, {1, ?RC_SUCCESS}, Channel),
|
|
|
?assertEqual(#{pubrec_out => 1}, emqx_channel:info(pub_stats, NChannel)).
|
|
|
|
|
|
t_handle_out_pubrel(_) ->
|
|
|
Channel = channel(#{conn_state => connected}),
|
|
|
{ok, ?PUBREL_PACKET(1), Channel1}
|
|
|
- = emqx_channel:handle_out({pubrel, 1, ?RC_SUCCESS}, Channel),
|
|
|
+ = emqx_channel:handle_out(pubrel, {1, ?RC_SUCCESS}, Channel),
|
|
|
{ok, ?PUBREL_PACKET(2, ?RC_SUCCESS), Channel2}
|
|
|
- = emqx_channel:handle_out({pubrel, 2, ?RC_SUCCESS}, Channel1),
|
|
|
+ = emqx_channel:handle_out(pubrel, {2, ?RC_SUCCESS}, Channel1),
|
|
|
?assertEqual(#{pubrel_out => 2}, emqx_channel:info(pub_stats, Channel2)).
|
|
|
|
|
|
t_handle_out_pubcomp(_) ->
|
|
|
{ok, ?PUBCOMP_PACKET(1, ?RC_SUCCESS), Channel}
|
|
|
- = emqx_channel:handle_out({pubcomp, 2, ?RC_SUCCESS}, channel()),
|
|
|
+ = emqx_channel:handle_out(pubcomp, {1, ?RC_SUCCESS}, channel()),
|
|
|
?assertEqual(#{pubcomp_out => 1}, emqx_channel:info(pub_stats, Channel)).
|
|
|
|
|
|
t_handle_out_suback(_) ->
|
|
|
{ok, ?SUBACK_PACKET(1, [?QOS_2]), _Channel}
|
|
|
- = emqx_channel:handle_out({suback, 1, [?QOS_2]}, channel()).
|
|
|
+ = emqx_channel:handle_out(suback, {1, [?QOS_2]}, channel()).
|
|
|
|
|
|
t_handle_out_unsuback(_) ->
|
|
|
{ok, ?UNSUBACK_PACKET(1, [?RC_SUCCESS]), _Channel}
|
|
|
- = emqx_channel:handle_out({unsuback, 1, [?RC_SUCCESS]}, channel()).
|
|
|
+ = emqx_channel:handle_out(unsuback, {1, [?RC_SUCCESS]}, channel()).
|
|
|
|
|
|
t_handle_out_disconnect(_) ->
|
|
|
{shutdown, normal, ?DISCONNECT_PACKET(?RC_SUCCESS), _Chan}
|
|
|
- = emqx_channel:handle_out({disconnect, ?RC_SUCCESS}, channel()).
|
|
|
+ = emqx_channel:handle_out(disconnect, ?RC_SUCCESS, channel()).
|
|
|
|
|
|
t_handle_out_unexpected(_) ->
|
|
|
{ok, _Channel} = emqx_channel:handle_out(unexpected, <<"data">>, channel()).
|
|
|
@@ -430,26 +453,40 @@ t_handle_info_unsubscribe(_) ->
|
|
|
{ok, _Chan} = emqx_channel:handle_info({unsubscribe, topic_filters()}, channel()).
|
|
|
|
|
|
t_handle_info_sock_closed(_) ->
|
|
|
- {ok, _Chan} = emqx_channel:handle_out({sock_closed, reason}, channel(#{conn_state => disconnected})).
|
|
|
+ {ok, _Chan} = emqx_channel:handle_out({sock_closed, reason},
|
|
|
+ channel(#{conn_state => disconnected})).
|
|
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
%% Test cases for handle_timeout
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
|
|
t_handle_timeout_emit_stats(_) ->
|
|
|
- {ok, _Chan} = emqx_channel:handle_timeout(make_ref(), {emit_stats, []}, channel()).
|
|
|
+ ok = meck:expect(emqx_cm, set_chan_stats, fun(_, _) -> ok end),
|
|
|
+ TRef = make_ref(),
|
|
|
+ Channel = emqx_channel:set_field(timers, #{stats_timer => TRef}, channel()),
|
|
|
+ {ok, _Chan} = emqx_channel:handle_timeout(TRef, {emit_stats, []}, Channel).
|
|
|
|
|
|
t_handle_timeout_keepalive(_) ->
|
|
|
+ TRef = make_ref(),
|
|
|
+ Channel = emqx_channel:set_field(timers, #{alive_timer => TRef}, channel()),
|
|
|
{ok, _Chan} = emqx_channel:handle_timeout(make_ref(), {keepalive, 10}, channel()).
|
|
|
|
|
|
t_handle_timeout_retry_delivery(_) ->
|
|
|
- {ok, _Chan} = emqx_channel:handle_timeout(make_ref(), retry_delivery, channel()).
|
|
|
+ ok = meck:expect(emqx_session, retry, fun(Session) -> {ok, Session} end),
|
|
|
+ TRef = make_ref(),
|
|
|
+ Channel = emqx_channel:set_field(timers, #{retry_timer => TRef}, channel()),
|
|
|
+ {ok, _Chan} = emqx_channel:handle_timeout(TRef, retry_delivery, channel()).
|
|
|
|
|
|
t_handle_timeout_expire_awaiting_rel(_) ->
|
|
|
- {ok, _Chan} = emqx_channel:handle_timeout(make_ref(), expire_awaiting_rel, channel()).
|
|
|
+ ok = meck:expect(emqx_session, expire, fun(_, Session) -> {ok, Session} end),
|
|
|
+ TRef = make_ref(),
|
|
|
+ Channel = emqx_channel:set_field(timers, #{await_timer => TRef}, channel()),
|
|
|
+ {ok, _Chan} = emqx_channel:handle_timeout(TRef, expire_awaiting_rel, Channel).
|
|
|
|
|
|
t_handle_timeout_expire_session(_) ->
|
|
|
- {shutdown, expired, _Chan} = emqx_channel:handle_timeout(make_ref(), expire_awaiting_rel, channel()).
|
|
|
+ TRef = make_ref(),
|
|
|
+ Channel = emqx_channel:set_field(timers, #{expire_timer => TRef}, channel()),
|
|
|
+ {shutdown, expired, _Chan} = emqx_channel:handle_timeout(TRef, expire_session, Channel).
|
|
|
|
|
|
t_handle_timeout_will_message(_) ->
|
|
|
{ok, _Chan} = emqx_channel:handle_timeout(make_ref(), will_message, channel()).
|
|
|
@@ -471,7 +508,6 @@ t_check_flapping(_) ->
|
|
|
ok = emqx_channel:check_flapping(connpkt(), channel()).
|
|
|
|
|
|
t_auth_connect(_) ->
|
|
|
- ok = meck:expect(emqx_access_control, authenticate, fun(_) -> {ok, #{}} end),
|
|
|
{ok, _Chan} = emqx_channel:auth_connect(connpkt(), channel()).
|
|
|
|
|
|
t_process_alias(_) ->
|
|
|
@@ -481,15 +517,22 @@ t_process_alias(_) ->
|
|
|
= emqx_channel:process_alias(#mqtt_packet{variable = Publish}, Channel).
|
|
|
|
|
|
t_check_pub_acl(_) ->
|
|
|
+ ok = meck:new(emqx_zone, [passthrough, no_history]),
|
|
|
+ ok = meck:expect(emqx_zone, enable_acl, fun(_) -> true end),
|
|
|
Publish = ?PUBLISH_PACKET(?QOS_0, <<"t">>, 1, <<"payload">>),
|
|
|
- ok = emqx_channel:check_pub_acl(Publish, channel()).
|
|
|
+ ok = emqx_channel:check_pub_acl(Publish, channel()),
|
|
|
+ ok = meck:unload(emqx_zone).
|
|
|
|
|
|
t_check_pub_alias(_) ->
|
|
|
Publish = #mqtt_packet_publish{topic_name = <<>>, properties = #{'Topic-Alias' => 1}},
|
|
|
- ok = emqx_channel:check_pub_alias(#mqtt_packet{variable = Publish}, channel()).
|
|
|
+ Channel = emqx_channel:set_field(alias_maximum, #{inbound => 10}, channel()),
|
|
|
+ ok = emqx_channel:check_pub_alias(#mqtt_packet{variable = Publish}, Channel).
|
|
|
|
|
|
t_check_subscribe(_) ->
|
|
|
- ok = emqx_channel:check_subscribe(<<"t">>, ?DEFAULT_SUBOPTS, channel()).
|
|
|
+ ok = meck:new(emqx_zone, [passthrough, no_history]),
|
|
|
+ ok = meck:expect(emqx_zone, enable_acl, fun(_) -> true end),
|
|
|
+ ok = emqx_channel:check_subscribe(<<"t">>, ?DEFAULT_SUBOPTS, channel()),
|
|
|
+ ok = meck:unload(emqx_zone).
|
|
|
|
|
|
t_enrich_caps(_) ->
|
|
|
ok = meck:new(emqx_mqtt_caps, [passthrough, no_history]),
|