📄 megaco_pending_limit_test.erl
字号:
fun(M) -> otp_4956_mg_verify_pending_limit_msg(M) end.-endif.otp_4956_mg_verify_pending_limit_msg(#'MegacoMessage'{mess = Mess} = M) -> print("otp_4956_mg_verify_pending_limit_msg -> entry with" "~n~p", [M]), #'Message'{messageBody = Body} = Mess, {transactions, [Trans]} = Body, {transactionReply, TR} = Trans, case element(4, TR) of {transactionError, ED} -> EC = ?megaco_number_of_transactionpending_exceeded, EC = ED#'ErrorDescriptor'.errorCode, print("otp_4956_mg_verify_pending_limit_msg -> done~n", []), {ok, M}; _ -> {error, {invalid_transactionReply, TR}} end;otp_4956_mg_verify_pending_limit_msg(M) -> print("otp_4956_mg_verify_pending_limit_msg -> entry with invalid message" "~n~p", [M]), {error, {invalid_message, M}}.otp_4956_mg_service_change_request_ar(_Mid, Cid) -> Prof = cre_serviceChangeProf("resgw", 1), SCP = cre_serviceChangeParm(restart, ["901 mg col boot"], Prof), Root = #megaco_term_id{id = ["root"]}, SCR = cre_serviceChangeReq([Root], SCP), CMD = cre_command(SCR), CR = cre_cmdReq(CMD), cre_actionReq(Cid, [CR]).otp_4956_mg_service_change_request_msg(Mid, TransId, Cid) -> AR = otp_4956_mg_service_change_request_ar(Mid, Cid), TR = cre_transReq(TransId, [AR]), Trans = cre_transaction(TR), Mess = cre_message(?VERSION, Mid, cre_transactions([Trans])), cre_megacoMessage(Mess).otp_4956_mg_notify_request_ar(Rid, Tid, Cid) -> TT = cre_timeNotation("19990729", "22000000"), Ev = cre_obsEvent("al/of", TT), EvsDesc = cre_obsEvsDesc(Rid, [Ev]), NR = cre_notifyReq([Tid], EvsDesc), CMD = cre_command(NR), CR = cre_cmdReq(CMD), cre_actionReq(Cid, [CR]).otp_4956_mg_notify_request_msg(Mid, TransId, Rid, TermId, Cid) -> AR = otp_4956_mg_notify_request_ar(Rid, TermId, Cid), TR = cre_transReq(TransId, [AR]), Trans = cre_transaction(TR), Mess = cre_message(?VERSION, Mid, cre_transactions([Trans])), cre_megacoMessage(Mess).otp_4956_err_desc(T) -> EC = ?megaco_internal_gateway_error, ET = lists:flatten(io_lib:format("~w",[T])), #'ErrorDescriptor'{errorCode = EC, errorText = ET}.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%otp_5310(suite) -> [];otp_5310(doc) -> "...";otp_5310(Config) when list(Config) -> put(verbosity, ?TEST_VERBOSITY), put(sname, "TEST"), put(tc, otp_5310), i("starting"), MgcNode = make_node_name(mgc), MgNode = make_node_name(mg), d("start nodes: " "~n MgcNode: ~p" "~n MgNode: ~p", [MgcNode, MgNode]), ok = megaco_test_lib:start_nodes([MgcNode, MgNode], ?FILE, ?LINE), %% Start the MGC and MGs i("[MGC] start"), ET = [{text,tcp}, {text,udp}, {binary,tcp}, {binary,udp}], {ok, Mgc} = ?MGC_START(MgcNode, {deviceName, "ctrl"}, ET, [], ?MGC_VERBOSITY), i("[MG] start"), MgMid = {deviceName, "mg"}, MgConfig = [], {ok, Mg} = ?MG_START(MgNode, MgMid, text, tcp, MgConfig, ?MG_VERBOSITY), d("MG user info: ~p", [?MG_USER_INFO(Mg, all)]), i("[MG] connect to the MGC (service change)"), ServChRes = ?MG_SERV_CHANGE(Mg), d("service change result: ~p", [ServChRes]), d("MG conn info: ~p", [?MG_CONN_INFO(Mg, all)]), d("[MGC] update connection info pending timer"), PendingTimer = #megaco_incr_timer{wait_for = timer:seconds(1), factor = 1}, ?MGC_UPDATE_CI(Mgc, pending_timer, PendingTimer), d("[MGC] update connection info originating pending limit"), PendingLimit = 3, ?MGC_UPDATE_CI(Mgc, orig_pending_limit, PendingLimit), ConnReps1 = ?MGC_CONN_INFO(Mgc, replies), d("[MGC] ConnReps1: ~p", [ConnReps1]), case filter_aborted1(ConnReps1, []) of [{_, []}] -> ok; ConnFlt1 -> ?ERROR({unexpected_reply_state, conn_info, ConnReps1, ConnFlt1}) end, UserReps1 = ?MGC_USER_INFO(Mgc, replies), d("[MGC] UserReps1: ~p", [UserReps1]), case filter_aborted1(UserReps1, []) of [{_, []}] -> ok; UserFlt1 -> ?ERROR({unexpected_reply_state, user_info, UserReps1, UserFlt1}) end, %% Instruct the MGC to never reply to requests d("[MGC] don't reply to requests"), ?MGC_REQ_IGNORE(Mgc), %% We want to know when the abort comes... d("[MGC] request abort inform"), ?MGC_ABORT_INFO(Mgc, self()), %% Make MG send a request d("[MG] send the notify"), {ok, {_ProtocolVersion, {error, ED}}} = ?MG_NOTIF_RAR(Mg), d("[MG] ED: ~p", [ED]), ErrorCode = ?megaco_number_of_transactionpending_exceeded, ErrorCode = ED#'ErrorDescriptor'.errorCode, %% Wait for the MGC to get aborted d("[MGC] await the abort callback"), {ok, TransId} = await_aborted(Mgc), d("[MGC] aborted transaction: ~p", [TransId]), %% Make sure we have one in aborted state d("[MGC] how many is aborted (should be == 1)?"), ConnReps2 = ?MGC_CONN_INFO(Mgc, replies), case filter_aborted1(ConnReps2, []) of [{_, [TransId]}] -> ok; [{_, []}] -> ok; % has already been cleaned up... ConnFlt2 -> ?ERROR({unexpected_reply_state, conn_info, ConnReps2, ConnFlt2}) end, d("[MGC] ConnReps2: ~p", [ConnReps2]), UserReps2 = ?MGC_USER_INFO(Mgc, replies), d("[MGC] UserReps2: ~p", [UserReps2]), case filter_aborted1(UserReps2, []) of [{_, [TransId]}] -> ok; [{_, []}] -> ok; % has already been cleaned up... UserFlt2 -> ?ERROR({unexpected_reply_state, user_info, UserReps2, UserFlt2}) end, %% do disconnect and the do cancel in the handle function d("[MGC] disconnect"), DiscoRes = ?MGC_DISCO(Mgc, cancel), d("[MGC] DiscoRes: ~p", [DiscoRes]), %% check number of reply records (should be no in aborted). d("[MGC] check number of replies in aborted state (should be == 1)"), ConnReps3 = ?MGC_CONN_INFO(Mgc, replies), d("[MGC] ConnReps3: ~p", [ConnReps3]), UserReps3 = ?MGC_USER_INFO(Mgc, replies), d("[MGC] UserReps3: ~p", [UserReps3]), %% Tell MG to stop i("[MG] stop"), ?MG_STOP(Mg), %% Tell Mgc to stop i("[MGC] stop"), ?MGC_STOP(Mgc), i("done", []), ok.await_aborted(Mgc) -> d("await_aborted"), receive {abort_received, Mgc, TransId} -> {ok, TransId} after 10000 -> d("await_aborted - timeout"), {error, timeout} end.filter_aborted1([], Acc) -> lists:reverse(Acc);filter_aborted1([{CH, Ab}|T], Acc) -> filter_aborted1(T, [{CH, filter_aborted2(Ab, [])}|Acc]).filter_aborted2([], Aborted) -> lists:reverse(Aborted);filter_aborted2([{TransId, aborted, _}|T], Aborted) -> filter_aborted2(T, [TransId|Aborted]);filter_aborted2([{TransId, State, _}|T], Aborted) -> d("Transaction ~w actually in state ~w", [TransId, State]), filter_aborted2(T, Aborted);filter_aborted2([_|T], Aborted) -> filter_aborted2(T, Aborted).%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% The timeout times is a little odd in this test case. The (short)%% request timer is longer then the (long) request timer. This is%% simply to produce the effect that we want regarding max_retries =%% infinity_restartable. Also the pending timeout has to be shorter%% then "short" + "long" and longer then "long"otp_5619(suite) -> [];otp_5619(doc) -> "...";otp_5619(Config) when list(Config) -> put(verbosity, ?TEST_VERBOSITY), put(sname, "TEST"), put(tc, otp_5619), i("starting"), MgcNode = make_node_name(mgc), MgNode = make_node_name(mg), d("start nodes: " "~n MgcNode: ~p" "~n MgNode: ~p", [MgcNode, MgNode]), ok = megaco_test_lib:start_nodes([MgcNode, MgNode], ?FILE, ?LINE), %% Start the MGC and MGs i("[MGC] start"), MgcMid = {deviceName, "ctrl"}, ET = [{text, tcp}, {text, udp}, {binary, tcp}, {binary, udp}], {ok, Mgc} = ?MGC_START(MgcNode, MgcMid, ET, [], ?MGC_VERBOSITY), i("[MG] start"), MgMid = {deviceName, "mg"}, MgConfig = [], {ok, Mg} = ?MG_START(MgNode, MgMid, text, tcp, MgConfig, ?MG_VERBOSITY), d("MG user info: ~p", [?MG_USER_INFO(Mg, all)]), d("MG conn info: ~p", [?MG_CONN_INFO(Mg, all)]), i("[MG] connect to the MGC (service change)"), ServChRes = ?MG_SERV_CHANGE(Mg), d("service change result: ~p", [ServChRes]), d("[MG] update connection info long request timer"), LongReqTmr = #megaco_incr_timer{wait_for = timer:seconds(1), factor = 1, max_retries = infinity_restartable}, ?MG_UPDATE_CI(Mg, long_request_timer, LongReqTmr), d("MG conn info: ~p", [?MG_CONN_INFO(Mg, all)]), d("MGC conn info: ~p", [?MGC_CONN_INFO(Mgc, all)]), d("[MGC] update connection info pending timer"), PendingTimer = #megaco_incr_timer{wait_for = timer:seconds(3), factor = 1}, ?MGC_UPDATE_CI(Mgc, pending_timer, PendingTimer), d("[MGC] update connection info sent pending limit"), PendingLimit = 5, ?MGC_UPDATE_CI(Mgc, sent_pending_limit, PendingLimit), d("MGC conn info: ~p", [?MG_CONN_INFO(Mgc, all)]), d("[MGC] late reply to requests " "(simulate that the request takes a long time)"), {ok, _} = ?MGC_REQ_DISC(Mgc, 11000), d("[MG] send the notify and await the timeout"), {ok, Reply} = ?MG_NOTIF_RAR(Mg), case Reply of {_Version, {error, timeout}} -> d("[MG] expected reply (timeout) received~n", []); _ -> ?ERROR({unexpected_reply, Reply}) end, %% Tell MG to stop i("[MG] stop~n"), ?MG_STOP(Mg), %% Tell Mgc to stop i("[MGC] stop~n"), ?MGC_STOP(Mgc), i("done", []), ok.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Common message creation functions%%cre_serviceChangeParm(M,R,P) -> #'ServiceChangeParm'{serviceChangeMethod = M, serviceChangeReason = R, serviceChangeProfile = P}.cre_serviceChangeReq(Tid, Parms) -> #'ServiceChangeRequest'{terminationID = Tid, serviceChangeParms = Parms}.cre_timeNotation(D,T) -> #'TimeNotation'{date = D, time = T}.cre_obsEvent(Name, Not) -> #'ObservedEvent'{eventName = Name, timeNotation = Not}.%% cre_obsEvent(Name, Not, Par) ->%% #'ObservedEvent'{eventName = Name, %% timeNotation = Not, %% eventParList = Par}.cre_obsEvsDesc(Id, EvList) -> #'ObservedEventsDescriptor'{requestId = Id, observedEventLst = EvList}.cre_notifyReq(Tid, EvsDesc) -> #'NotifyRequest'{terminationID = Tid, observedEventsDescriptor = EvsDesc}.cre_command(R) when record(R, 'NotifyRequest') -> {notifyReq, R};cre_command(R) when record(R, 'ServiceChangeRequest') -> {serviceChangeReq, R}.cre_cmdReq(Cmd) -> #'CommandRequest'{command = Cmd}.cre_actionReq(CtxId, CmdReqs) when list(CmdReqs) -> #'ActionRequest'{contextId = CtxId, commandRequests = CmdReqs}.cre_transReq(TransId, ARs) when list(ARs) -> #'TransactionRequest'{transactionId = TransId, actions = ARs}.%% --cre_serviceChangeResParm(Mid) -> cre_serviceChangeResParm(Mid, ?VERSION).cre_serviceChangeResParm(Mid, V) -> #'ServiceChangeResParm'{serviceChangeMgcId = Mid, serviceChangeVersion = V}.cre_serviceChangeResult(SCRP) when record(SCRP, 'ServiceChangeResParm') -> {serviceChangeResParms, SCRP};cre_serviceChangeResult(ED) when record(ED, 'ErrorDescriptor') -> {errorDescriptor, ED}.cre_serviceChangeReply(Tid, Res) -> #'ServiceChangeReply'{terminationID = Tid, serviceChangeResult = Res}.cre_cmdReply(R) when record(R, 'NotifyReply') -> {notifyReply, R};cre_cmdReply(R) when record(R, 'ServiceChangeReply') -> {serviceChangeReply, R}.cre_notifyReply(Tid) -> #'NotifyReply'{terminationID = Tid}.cre_actionReply(CtxId, CmdRep) -> #'ActionReply'{contextId = CtxId, commandReply = CmdRep}.%% cre_transResult(ED) when record(ED, 'ErrorDescriptor') ->%% {transactionError, ED};%% cre_transResult([AR|_] = ARs) when record(AR, 'ActionReply') ->%% {actionReplies, ARs}.%% cre_transReply(TransId, Res) ->%% #'TransactionReply'{transactionId = TransId,%% tra
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -