Skip to content

Commit

Permalink
Merge branch 'bmk/megaco/20241212/27/improving_tests' into maint
Browse files Browse the repository at this point in the history
  • Loading branch information
bmk committed Jan 17, 2025
2 parents e1ef86c + 59050f2 commit 8fd8649
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 58 deletions.
5 changes: 4 additions & 1 deletion lib/megaco/test/megaco_test_lib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,8 @@ linux_distro_str_to_distro_id("Fedora" ++ _) ->
fedora;
linux_distro_str_to_distro_id("Linux Mint" ++ _) ->
linux_mint;
linux_distro_str_to_distro_id("LMDE" ++ _) ->
linux_mint;
linux_distro_str_to_distro_id("MontaVista" ++ _) ->
montavista;
linux_distro_str_to_distro_id("openSUSE" ++ _) ->
Expand Down Expand Up @@ -1196,7 +1198,8 @@ analyze_and_print_linux_host_info(Version) ->
"~n Num Online Schedulers: ~s"
"~n", [CPU, str_num_schedulers()]),
num_schedulers_to_factor();
_ ->
_X ->
io:format("CPU: ~p~n", [_X]),
5
end,
AddLabelFactor = label2factor(Label),
Expand Down
30 changes: 20 additions & 10 deletions lib/megaco/test/megaco_test_mgc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -471,32 +471,36 @@ loop(S) ->


%%
{request_action, {Action, To}, Parent} when S#mgc.parent == Parent ->
{request_action, {Action, To}, Parent} when S#mgc.parent =:= Parent ->
i("loop -> got new request_action: ~p:~w", [Action,To]),
{Reply, S1} =
case lists:member(Action, ?valid_actions) of
true when To >= 0; To == infinity ->
case is_valid_action(Action) of
true when (is_integer(To) andalso (To >= 0)) orelse
(To =:= infinity) ->
%% Valid and on time!
{{ok, S#mgc.req_action},
S#mgc{req_action = Action, req_timeout = To}};
true ->
%% Valid but too late
{{error, {invalid_action_timeout, To}}, S};
false ->
%% Invalid
{{error, {invalid_action, Action}}, S}
end,
server_reply(Parent, request_action_ack, Reply),
loop(evs(S1, {req_act, {Action, To}}));


%% Reset stats
{reset_stats, Parent} when S#mgc.parent == Parent ->
{reset_stats, Parent} when S#mgc.parent =:= Parent ->
i("loop -> got request to reset stats counters"),
do_reset_stats(S#mgc.mid),
server_reply(Parent, reset_stats_ack, ok),
loop(evs(S, rst_stats));


%% Give me statistics
{{statistics, 1}, Parent} when S#mgc.parent == Parent ->
{{statistics, 1}, Parent} when S#mgc.parent =:= Parent ->
i("loop(stats1) -> got request for statistics 1"),
{ok, Gen} = megaco:get_stats(),
i("loop(stats1) -> gen stats: "
Expand Down Expand Up @@ -533,7 +537,7 @@ loop(S) ->
loop(evs(S, {stats, 1}));


{{statistics, 2}, Parent} when S#mgc.parent == Parent ->
{{statistics, 2}, Parent} when S#mgc.parent =:= Parent ->
i("loop(stats2) -> got request for statistics 2"),
{ok, Gen} = megaco:get_stats(),
#mgc{tcp_sup = TcpSup, udp_sup = UdpSup} = S,
Expand All @@ -557,22 +561,22 @@ loop(S) ->
loop(evs(S1, {req, Request}));


{ack_info, To, Parent} when S#mgc.parent == Parent ->
{ack_info, To, Parent} when S#mgc.parent =:= Parent ->
i("loop -> received request to inform about received ack's "),
loop(evs(S#mgc{ack_info = To}, {acki, To}));


{abort_info, To, Parent} when S#mgc.parent == Parent ->
{abort_info, To, Parent} when S#mgc.parent =:= Parent ->
i("loop -> received request to inform about received aborts "),
loop(evs(S#mgc{abort_info = To}, {abi, To}));


{req_info, To, Parent} when S#mgc.parent == Parent ->
{req_info, To, Parent} when S#mgc.parent =:= Parent ->
i("loop -> received request to inform about received req's "),
loop(evs(S#mgc{req_info = To}, {reqi, To}));


{verbosity, V, Parent} when S#mgc.parent == Parent ->
{verbosity, V, Parent} when S#mgc.parent =:= Parent ->
i("loop -> received new verbosity: ~p", [V]),
put(verbosity,V),
loop(evs(S, {verb, V}));
Expand Down Expand Up @@ -1273,6 +1277,12 @@ cancel_timer(Ref) ->
erlang:cancel_timer(Ref).


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

is_valid_action(Action) ->
lists:member(Action, ?valid_actions).


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

e(F, A) ->
Expand Down
Loading

0 comments on commit 8fd8649

Please sign in to comment.