Skip to content

Commit

Permalink
Proxy: do not raise error on cancel transaction finish
Browse files Browse the repository at this point in the history
  • Loading branch information
poroh committed Aug 5, 2019
1 parent c240716 commit 4ca6922
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/proxy/ersip_proxy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ trans_result(BranchKey, Resp, #stateful{phase = collect} = Stateful) ->
-spec trans_finished(internal_trans_id(), stateful()) -> stateful_result().
trans_finished(?SERVER_TRANS_ID, #stateful{} = Stateful) ->
{Stateful, []};
trans_finished({cancel, _}, #stateful{} = Stateful) ->
{Stateful, []};
trans_finished(BranchKey, #stateful{req_map = ReqCtxMap} = Stateful) ->
case ReqCtxMap of
#{BranchKey := #request_context{} = ReqCtx} ->
Expand Down
23 changes: 23 additions & 0 deletions test/proxy/ersip_proxy_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,29 @@ server_transaction_finish_is_ignored_test() ->
?assertMatch({_, []}, ersip_proxy:trans_finished(ServerTransId, StateProcessReq)),
ok.

cancel_transaction_finish_is_ignored_test() ->
InviteSipMsg = invite_request(),
%% 1. Create new stateful proxy request state.
%% 2. Process server transaction result.
{SelectTargetState, _} = create_stateful(InviteSipMsg, #{}),

%% 3. Choose one target to forward:
Target = ersip_uri:make(<<"sip:contact@192.168.1.1">>),
{Forward_State, Forward_SE} = ersip_proxy:forward_to(Target, SelectTargetState),
{create_trans, {client, ClientTransId, Req}} = se_event(create_trans, Forward_SE),

%% 4. Pass 180 provisional response:
{_, Resp180} = create_client_trans_result(180, Req),
{Provisional_State, _} = ersip_proxy:trans_result(ClientTransId, Resp180, Forward_State),

%% 5. Cancel request:
{Cancel_State, Cancel_SE} = ersip_proxy:cancel(Provisional_State),
%% - CANCEL transaction is created:
?assertMatch({create_trans, {client, _, _}}, se_event(create_trans, Cancel_SE)),
{create_trans, {client, CancelClientTransId, _CancelReq}} = se_event(create_trans, Cancel_SE),
?assertMatch({_, []}, ersip_proxy:trans_finished(CancelClientTransId, Cancel_State)),
ok.


%%%===================================================================
%%% Helpers
Expand Down

0 comments on commit 4ca6922

Please sign in to comment.