fix(stomp): ensure the subscripton_cnt timely updated
This commit is contained in:
parent
6fe99be367
commit
bad0c35bb9
|
@ -499,7 +499,7 @@ handle_in(
|
||||||
[{MountedTopic, SubOpts} | _] ->
|
[{MountedTopic, SubOpts} | _] ->
|
||||||
NSubs = [{SubId, MountedTopic, Ack, SubOpts} | Subs],
|
NSubs = [{SubId, MountedTopic, Ack, SubOpts} | Subs],
|
||||||
NChannel1 = NChannel#channel{subscriptions = NSubs},
|
NChannel1 = NChannel#channel{subscriptions = NSubs},
|
||||||
handle_out(receipt, receipt_id(Headers), NChannel1)
|
handle_out_and_update(receipt, receipt_id(Headers), NChannel1)
|
||||||
end;
|
end;
|
||||||
{error, ErrMsg, NChannel} ->
|
{error, ErrMsg, NChannel} ->
|
||||||
?SLOG(error, #{
|
?SLOG(error, #{
|
||||||
|
@ -541,7 +541,7 @@ handle_in(
|
||||||
false ->
|
false ->
|
||||||
{ok, Channel}
|
{ok, Channel}
|
||||||
end,
|
end,
|
||||||
handle_out(receipt, receipt_id(Headers), NChannel);
|
handle_out_and_update(receipt, receipt_id(Headers), NChannel);
|
||||||
%% XXX: How to ack a frame ???
|
%% XXX: How to ack a frame ???
|
||||||
handle_in(Frame = ?PACKET(?CMD_ACK, Headers), Channel) ->
|
handle_in(Frame = ?PACKET(?CMD_ACK, Headers), Channel) ->
|
||||||
case header(<<"transaction">>, Headers) of
|
case header(<<"transaction">>, Headers) of
|
||||||
|
@ -769,6 +769,12 @@ handle_out(receipt, ReceiptId, Channel) ->
|
||||||
Frame = receipt_frame(ReceiptId),
|
Frame = receipt_frame(ReceiptId),
|
||||||
{ok, {outgoing, Frame}, Channel}.
|
{ok, {outgoing, Frame}, Channel}.
|
||||||
|
|
||||||
|
handle_out_and_update(receipt, undefined, Channel) ->
|
||||||
|
{ok, [{event, updated}], Channel};
|
||||||
|
handle_out_and_update(receipt, ReceiptId, Channel) ->
|
||||||
|
Frame = receipt_frame(ReceiptId),
|
||||||
|
{ok, [{outgoing, Frame}, {event, updated}], Channel}.
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Handle call
|
%% Handle call
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
@ -812,7 +818,7 @@ handle_call(
|
||||||
),
|
),
|
||||||
NSubs = [{SubId, MountedTopic, <<"auto">>, NSubOpts} | Subs],
|
NSubs = [{SubId, MountedTopic, <<"auto">>, NSubOpts} | Subs],
|
||||||
NChannel1 = NChannel#channel{subscriptions = NSubs},
|
NChannel1 = NChannel#channel{subscriptions = NSubs},
|
||||||
reply({ok, {MountedTopic, NSubOpts}}, NChannel1);
|
reply({ok, {MountedTopic, NSubOpts}}, [{event, updated}], NChannel1);
|
||||||
{error, ErrMsg, NChannel} ->
|
{error, ErrMsg, NChannel} ->
|
||||||
?SLOG(error, #{
|
?SLOG(error, #{
|
||||||
msg => "failed_to_subscribe_topic",
|
msg => "failed_to_subscribe_topic",
|
||||||
|
@ -841,6 +847,7 @@ handle_call(
|
||||||
),
|
),
|
||||||
reply(
|
reply(
|
||||||
ok,
|
ok,
|
||||||
|
[{event, updated}],
|
||||||
Channel#channel{
|
Channel#channel{
|
||||||
subscriptions = lists:keydelete(MountedTopic, 2, Subs)
|
subscriptions = lists:keydelete(MountedTopic, 2, Subs)
|
||||||
}
|
}
|
||||||
|
@ -1107,6 +1114,9 @@ terminate(Reason, #channel{
|
||||||
reply(Reply, Channel) ->
|
reply(Reply, Channel) ->
|
||||||
{reply, Reply, Channel}.
|
{reply, Reply, Channel}.
|
||||||
|
|
||||||
|
reply(Reply, Msgs, Channel) ->
|
||||||
|
{reply, Reply, Msgs, Channel}.
|
||||||
|
|
||||||
shutdown(Reason, Channel) ->
|
shutdown(Reason, Channel) ->
|
||||||
{shutdown, Reason, Channel}.
|
{shutdown, Reason, Channel}.
|
||||||
|
|
||||||
|
|
|
@ -256,6 +256,10 @@ t_subscribe(_) ->
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
|
|
||||||
|
%% assert subscription stats
|
||||||
|
[ClientInfo1] = clients(),
|
||||||
|
?assertMatch(#{subscriptions_cnt := 1}, ClientInfo1),
|
||||||
|
|
||||||
%% Unsubscribe
|
%% Unsubscribe
|
||||||
gen_tcp:send(
|
gen_tcp:send(
|
||||||
Sock,
|
Sock,
|
||||||
|
@ -278,6 +282,10 @@ t_subscribe(_) ->
|
||||||
},
|
},
|
||||||
_, _} = parse(Data2),
|
_, _} = parse(Data2),
|
||||||
|
|
||||||
|
%% assert subscription stats
|
||||||
|
[ClientInfo2] = clients(),
|
||||||
|
?assertMatch(#{subscriptions_cnt := 0}, ClientInfo2),
|
||||||
|
|
||||||
gen_tcp:send(
|
gen_tcp:send(
|
||||||
Sock,
|
Sock,
|
||||||
serialize(
|
serialize(
|
||||||
|
@ -802,10 +810,14 @@ t_rest_clienit_info(_) ->
|
||||||
|
|
||||||
{200, Subs1} = request(get, ClientPath ++ "/subscriptions"),
|
{200, Subs1} = request(get, ClientPath ++ "/subscriptions"),
|
||||||
?assertEqual(2, length(Subs1)),
|
?assertEqual(2, length(Subs1)),
|
||||||
|
{200, StompClient2} = request(get, ClientPath),
|
||||||
|
?assertMatch(#{subscriptions_cnt := 2}, StompClient2),
|
||||||
|
|
||||||
{204, _} = request(delete, ClientPath ++ "/subscriptions/t%2Fa"),
|
{204, _} = request(delete, ClientPath ++ "/subscriptions/t%2Fa"),
|
||||||
{200, Subs2} = request(get, ClientPath ++ "/subscriptions"),
|
{200, Subs2} = request(get, ClientPath ++ "/subscriptions"),
|
||||||
?assertEqual(1, length(Subs2)),
|
?assertEqual(1, length(Subs2)),
|
||||||
|
{200, StompClient3} = request(get, ClientPath),
|
||||||
|
?assertMatch(#{subscriptions_cnt := 1}, StompClient3),
|
||||||
|
|
||||||
%% kickout
|
%% kickout
|
||||||
{204, _} = request(delete, ClientPath),
|
{204, _} = request(delete, ClientPath),
|
||||||
|
@ -855,3 +867,7 @@ get_field(command, #stomp_frame{command = Command}) ->
|
||||||
Command;
|
Command;
|
||||||
get_field(body, #stomp_frame{body = Body}) ->
|
get_field(body, #stomp_frame{body = Body}) ->
|
||||||
Body.
|
Body.
|
||||||
|
|
||||||
|
clients() ->
|
||||||
|
{200, Clients} = request(get, "/gateways/stomp/clients"),
|
||||||
|
maps:get(data, Clients).
|
||||||
|
|
Loading…
Reference in New Issue