📄 megaco_pending_limit_test.erl
字号:
%% ``The contents of this file are subject to the Erlang Public License,%% Version 1.1, (the "License"); you may not use this file except in%% compliance with the License. You should have received a copy of the%% Erlang Public License along with this software. If not, it can be%% retrieved via the world wide web at http://www.erlang.org/.%% %% Software distributed under the License is distributed on an "AS IS"%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See%% the License for the specific language governing rights and limitations%% under the License.%% %% The Initial Developer of the Original Code is Ericsson Utvecklings AB.%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings%% AB. All Rights Reserved.''%% %% $Id$%%%%----------------------------------------------------------------------%% Purpose: Verify the application specifics of the Megaco application%% Testing the xxxOriginatingPendingLimit property of the %% root package%%-----------------------------------------------------------------------module(megaco_pending_limit_test).-export([t/0, t/1]).-export([init_per_testcase/2, fin_per_testcase/2]).-export([all/1, sent/1, sent_timer_late_reply/1, sent_timer_exceeded/1, sent_timer_exceeded_long/1, sent_resend_late_reply/1, sent_resend_exceeded/1, sent_resend_exceeded_long/1, recv/1, recv_limit_exceeded1/1, recv_limit_exceeded2/1, tickets/1, otp_4956/1, otp_5310/1, otp_5619/1 ]).-ifdef(megaco_hipe_special).-export([ %% Case: recv_limit_exceeded1 rle1_mgc_verify_service_change_req_msg/2, rle1_mgc_verify_notify_req_msg/1, rle1_mg_verify_handle_connect/1, rle1_mg_verify_service_change_rep/1, rle1_mg_verify_trans_rep/1, %% Case: otp_4956 otp_4956_mgc_verify_handle_connect/1, otp_4956_mgc_verify_service_change_req/2, otp_4956_mgc_verify_notify_req1/1, otp_4956_mgc_verify_notify_req2/1, otp_4956_mgc_verify_handle_trans_req_abort/1, otp_4956_mgc_verify_handle_disconnect/1, otp_4956_mg_verify_service_change_rep_msg/1, otp_4956_mg_verify_pending_msg/1, otp_4956_mg_verify_pending_limit_msg/1, %% Utility encode_msg/3, decode_msg/3 ]).-endif.-include("megaco_test_lib.hrl").-include_lib("megaco/include/megaco.hrl").-include_lib("megaco/include/megaco_message_v1.hrl").-define(TEST_VERBOSITY, debug).-define(MGC_VERBOSITY, debug).-define(MG_VERBOSITY, debug).-define(VERSION, 1).-define(A4444, ["11111111", "00000000", "00000000"]).-define(A4445, ["11111111", "00000000", "11111111"]).-define(A5555, ["11111111", "11111111", "00000000"]).-define(A5556, ["11111111", "11111111", "11111111"]).-define(MGC_START(Pid, Mid, ET, Conf, Verb), megaco_test_mgc:start(Pid, Mid, ET, Conf, Verb)).-define(MGC_STOP(Pid), megaco_test_mgc:stop(Pid)).-define(MGC_GET_STATS(Pid, No), megaco_test_mgc:get_stats(Pid, No)).-define(MGC_RESET_STATS(Pid), megaco_test_mgc:reset_stats(Pid)).-define(MGC_REQ_IGNORE(Pid), megaco_test_mgc:request_ignore(Pid)).-define(MGC_REQ_PIGNORE(Pid), megaco_test_mgc:request_pending_ignore(Pid)).-define(MGC_REQ_DISC(Pid,To), megaco_test_mgc:request_discard(Pid,To)).-define(MGC_REQ_PEND(Pid,To), megaco_test_mgc:request_pending(Pid,To)).-define(MGC_REQ_HAND(Pid, To), megaco_test_mgc:request_handle(Pid, To)).-define(MGC_REQ_HANDS(Pid), megaco_test_mgc:request_handle_sloppy(Pid)).-define(MGC_UPDATE_UI(Pid,Tag,Val), megaco_test_mgc:update_user_info(Pid,Tag,Val)).-define(MGC_UPDATE_CI(Pid,Tag,Val), megaco_test_mgc:update_conn_info(Pid,Tag,Val)).-define(MGC_USER_INFO(Pid,Tag), megaco_test_mgc:user_info(Pid,Tag)).-define(MGC_CONN_INFO(Pid,Tag), megaco_test_mgc:conn_info(Pid,Tag)).-define(MGC_ACK_INFO(Pid,To), megaco_test_mgc:ack_info(Pid,To)).-define(MGC_ABORT_INFO(Pid,To), megaco_test_mgc:abort_info(Pid,To)).-define(MGC_DISCO(Pid,Reason), megaco_test_mgc:disconnect(Pid,Reason)).-define(MG_START(Pid, Mid, Enc, Transp, Conf, Verb), megaco_test_mg:start(Pid, Mid, Enc, Transp, Conf, Verb)).-define(MG_STOP(Pid), megaco_test_mg:stop(Pid)).-define(MG_GET_STATS(Pid, No), megaco_test_mg:get_stats(Pid, No)).-define(MG_RESET_STATS(Pid), megaco_test_mg:reset_stats(Pid)).-define(MG_SERV_CHANGE(Pid), megaco_test_mg:service_change(Pid)).-define(MG_NOTIF_RAR(Pid), megaco_test_mg:notify_request_and_reply(Pid)).-define(MG_NOTIF_REQ(Pid), megaco_test_mg:notify_request(Pid)).-define(MG_NOTIF_AR(Pid), megaco_test_mg:await_notify_reply(Pid)).-define(MG_CANCEL(Pid,R), megaco_test_mg:cancel_request(Pid,R)).-define(MG_APPLY_LOAD(Pid,CntStart), megaco_test_mg:apply_load(Pid,CntStart)).-define(MG_UPDATE_UI(Pid,Tag,Val), megaco_test_mg:update_user_info(Pid,Tag,Val)).-define(MG_UPDATE_CI(Pid,Tag,Val), megaco_test_mg:update_conn_info(Pid,Tag,Val)).-define(MG_USER_INFO(Pid,Tag), megaco_test_mg:user_info(Pid,Tag)).-define(MG_CONN_INFO(Pid,Tag), megaco_test_mg:conn_info(Pid,Tag)).-define(MG_GRP_REQ(Pid,N), megaco_test_mg:group_requests(Pid,N)).-define(MG_ECC(Pid, M, T, F), megaco_test_mg:enable_test_code(Pid,M,T,F)).t() -> megaco_test_lib:t(?MODULE).t(Case) -> megaco_test_lib:t({?MODULE, Case}).%% Test server callbacksinit_per_testcase(Case, Config) -> process_flag(trap_exit, true), megaco_test_lib:init_per_testcase(Case, Config).fin_per_testcase(Case, Config) -> process_flag(trap_exit, false), megaco_test_lib:fin_per_testcase(Case, Config).%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%all(suite) -> [ sent, recv, %% Tickets last tickets ].sent(suite) -> [ sent_timer_late_reply, sent_timer_exceeded, sent_timer_exceeded_long, sent_resend_late_reply, sent_resend_exceeded, sent_resend_exceeded_long ].recv(suite) -> [ recv_limit_exceeded1, recv_limit_exceeded2 ].tickets(suite) -> [ otp_4956%,%% otp_5310,%% otp_5619 ].%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%% Sent pending test cases %%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%sent_timer_late_reply(suite) -> [];sent_timer_late_reply(doc) -> "...";sent_timer_late_reply(Config) when list(Config) -> put(verbosity, ?TEST_VERBOSITY), put(sname, "TEST"), put(tc, sent_timer_late_reply), 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}], MgcConf = [{megaco_trace, false}], {ok, Mgc} = ?MGC_START(MgcNode, {deviceName, "ctrl"}, ET, MgcConf, ?MGC_VERBOSITY), i("[MG] start"), MgMid = {deviceName, "mg"}, MgConf = [{megaco_trace, io}], {ok, Mg} = ?MG_START(MgNode, MgMid, text, tcp, MgConf, ?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(5), 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] late reply to requests " "(simulate that the request takes a long time)"), {ok, _} = ?MGC_REQ_DISC(Mgc, 11000), d("[MG] send the notify"), {ok, Reply} = ?MG_NOTIF_RAR(Mg), d("[MG] Reply: ~p", [Reply]), case Reply of {_Version, {ok, [_ActionReply]}} -> ok; _ -> ?ERROR({unexpected_reply, Reply}) end, %% Tell MG to stop i("[MG] stop"), ?MG_STOP(Mg), %% Tell Mgc to stop i("[MGC] stop"), ?MGC_STOP(Mgc), i("done", []), ok.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%sent_timer_exceeded(suite) -> [];sent_timer_exceeded(doc) -> "...";sent_timer_exceeded(Config) when list(Config) -> put(verbosity, ?TEST_VERBOSITY), put(sname, "TEST"), put(tc, sent_timer_exceeded), 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(5), 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] no reply to requests " "(simulate that the request takes a __long__ time)"), ?MGC_REQ_IGNORE(Mgc), 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, %% Tell MG to stop i("[MG] stop"), ?MG_STOP(Mg), %% Tell Mgc to stop i("[MGC] stop"), ?MGC_STOP(Mgc), i("done", []), ok.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%sent_timer_exceeded_long(suite) -> [];sent_timer_exceeded_long(doc) -> "...";sent_timer_exceeded_long(Config) when list(Config) -> put(verbosity, ?TEST_VERBOSITY), put(sname, "TEST"), put(tc, sent_timer_exceeded_long), 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(5), 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] long request with no reply ~n" " (simulate that we know that this will " "take a while, but takes even longer...)"), ?MGC_REQ_PIGNORE(Mgc), 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, %% Tell MG to stop i("[MG] stop"), ?MG_STOP(Mg), %% Tell Mgc to stop i("[MGC] stop"), ?MGC_STOP(Mgc), i("done", []), ok.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% This test case can only be run with the stack compiled with%% the MEGACO_TEST_CODE flag. Therefor there is no point in %% including this test case in the usual test suite
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -