fix(coap): fix system topic case

This commit is contained in:
firest 2022-03-23 17:25:52 +08:00
parent ab51d8ab8e
commit ab2f5b9bb7
2 changed files with 19 additions and 15 deletions

View File

@ -638,8 +638,8 @@ process_connection({open, Req}, Result,
Channel);
process_connection({close, Msg}, _, Channel, _) ->
Reply = emqx_coap_message:piggyback({ok, deleted}, Msg),
NChannel = ensure_disconnected(close_connection, Channel),
{shutdown, close, Reply, NChannel}.
NChannel = ensure_disconnected(normal, Channel),
{shutdown, normal, Reply, NChannel}.
process_subscribe({Sub, Msg}, Result, #channel{session = Session} = Channel, Iter) ->
Result2 = emqx_coap_session:process_subscribe(Sub, Msg, Result, Session),

View File

@ -294,26 +294,30 @@ t_clients_get_subscription_api(_) ->
t_on_offline_event(_) ->
Fun = fun(Channel) ->
application:start(emqx_modules),
emqx_event_message_SUITE:load_config(),
emqx_hooks:add('client.connected', {emqx_sys, on_client_connected, []}),
emqx_hooks:add('client.disconnected', {emqx_sys, on_client_disconnected, []}),
ConnectedSub = <<"$SYS/brokers/+/gateway/coap/clients/+/connected">>,
emqx_broker:subscribe(ConnectedSub),
timer:sleep(100),
emqx_event_message:enable(),
timer:sleep(200),
emqx_broker:subscribe(<<"$event/#">>),
Token = connection(Channel),
?assertMatch(#message{topic = <<"$event/client_connected">>}, receive_deliver(500)),
?assertMatch(#message{}, receive_deliver(500)),
DisconnectedSub = <<"$SYS/brokers/+/gateway/coap/clients/+/disconnected">>,
emqx_broker:subscribe(DisconnectedSub),
timer:sleep(100),
disconnection(Channel, Token),
?assertMatch(#message{topic = <<"$event/client_disconnected">>}, receive_deliver(500)),
?assertMatch(#message{}, receive_deliver(500)),
emqx_broker:unsubscribe(<<"$event/#">>),
emqx_event_message:disable(),
application:stop(emqx_modules),
timer:sleep(200)
emqx_broker:unsubscribe(ConnectedSub),
emqx_broker:unsubscribe(DisconnectedSub),
emqx_hooks:del('client.connected', {emqx_sys, on_client_connected}),
emqx_hooks:del('client.disconnected', {emqx_sys, on_client_disconnected}),
timer:sleep(500)
end,
do(Fun).