fix(emqx_sn): willmsgs not sent
This commit is contained in:
parent
5154a00252
commit
dc95c1476a
|
@ -792,9 +792,10 @@ stop(Reason, State) ->
|
||||||
?LOG(stop_log_level(Reason), "stop due to ~p", [Reason]),
|
?LOG(stop_log_level(Reason), "stop due to ~p", [Reason]),
|
||||||
case Reason of
|
case Reason of
|
||||||
%% FIXME: The Will-Msg should publish when a Session terminated!
|
%% FIXME: The Will-Msg should publish when a Session terminated!
|
||||||
asleep_timeout -> do_publish_will(State);
|
Reason when Reason =:= normal ->
|
||||||
keepalive_timeout -> do_publish_will(State);
|
ok;
|
||||||
_ -> ok
|
_ ->
|
||||||
|
do_publish_will(State)
|
||||||
end,
|
end,
|
||||||
{stop, {shutdown, Reason}, State}.
|
{stop, {shutdown, Reason}, State}.
|
||||||
|
|
||||||
|
|
|
@ -808,25 +808,34 @@ t_publish_qos2_case03(_) ->
|
||||||
t_will_case01(_) ->
|
t_will_case01(_) ->
|
||||||
QoS = 1,
|
QoS = 1,
|
||||||
Duration = 1,
|
Duration = 1,
|
||||||
|
WillMsg = <<10, 11, 12, 13, 14>>,
|
||||||
|
WillTopic = <<"abc">>,
|
||||||
{ok, Socket} = gen_udp:open(0, [binary]),
|
{ok, Socket} = gen_udp:open(0, [binary]),
|
||||||
ClientId = <<"test">>,
|
ClientId = <<"test">>,
|
||||||
|
|
||||||
|
ok = emqx_broker:subscribe(WillTopic),
|
||||||
|
|
||||||
send_connect_msg_with_will(Socket, Duration, ClientId),
|
send_connect_msg_with_will(Socket, Duration, ClientId),
|
||||||
?assertEqual(<<2, ?SN_WILLTOPICREQ>>, receive_response(Socket)),
|
?assertEqual(<<2, ?SN_WILLTOPICREQ>>, receive_response(Socket)),
|
||||||
|
|
||||||
send_willtopic_msg(Socket, <<"abc">>, QoS),
|
send_willtopic_msg(Socket, WillTopic, QoS),
|
||||||
?assertEqual(<<2, ?SN_WILLMSGREQ>>, receive_response(Socket)),
|
?assertEqual(<<2, ?SN_WILLMSGREQ>>, receive_response(Socket)),
|
||||||
|
|
||||||
send_willmsg_msg(Socket, <<10, 11, 12, 13, 14>>),
|
send_willmsg_msg(Socket, WillMsg),
|
||||||
?assertEqual(<<3, ?SN_CONNACK, 0>>, receive_response(Socket)),
|
?assertEqual(<<3, ?SN_CONNACK, 0>>, receive_response(Socket)),
|
||||||
|
|
||||||
send_pingreq_msg(Socket, undefined),
|
send_pingreq_msg(Socket, undefined),
|
||||||
?assertEqual(<<2, ?SN_PINGRESP>>, receive_response(Socket)),
|
?assertEqual(<<2, ?SN_PINGRESP>>, receive_response(Socket)),
|
||||||
|
|
||||||
% wait udp client keepalive timeout
|
% wait udp client keepalive timeout
|
||||||
timer:sleep(10000),
|
timer:sleep(2000),
|
||||||
|
|
||||||
receive_response(Socket), % ignore PUBACK
|
|
||||||
|
|
||||||
|
receive
|
||||||
|
{deliver, WillTopic, #message{payload = WillMsg}} -> ok;
|
||||||
|
Msg -> ct:print("recevived --- unex: ~p", [Msg])
|
||||||
|
after
|
||||||
|
1000 -> ct:fail(wait_willmsg_timeout)
|
||||||
|
end,
|
||||||
send_disconnect_msg(Socket, undefined),
|
send_disconnect_msg(Socket, undefined),
|
||||||
?assertEqual(udp_receive_timeout, receive_response(Socket)),
|
?assertEqual(udp_receive_timeout, receive_response(Socket)),
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue