File 3505-snmp-agent-test-agent-test-manager-improvements.patch of Package erlang
From d2130aa71830a91476d345deafc693d6d2f0fb08 Mon Sep 17 00:00:00 2001
From: Micael Karlberg <bmk@erlang.org>
Date: Mon, 19 Oct 2020 22:01:53 +0200
Subject: [PATCH 5/7] [snmp|agent|test] (agent) test manager improvements
When an request, or any message, does not arrive in time,
an error message is written. Now it also includes the
current message queue (the expeected message did not arrive,
but what did).
---
lib/snmp/test/snmp_test_mgr.erl | 71 ++++++++++++++++++++++++++-------
1 file changed, 56 insertions(+), 15 deletions(-)
diff --git a/lib/snmp/test/snmp_test_mgr.erl b/lib/snmp/test/snmp_test_mgr.erl
index 4ac1b8fbac..306379808f 100644
--- a/lib/snmp/test/snmp_test_mgr.erl
+++ b/lib/snmp/test/snmp_test_mgr.erl
@@ -702,13 +702,13 @@ echo_pdu(PDU, MiniMIB) ->
%% Test Sequence
%%----------------------------------------------------------------------
echo_errors({error, Id, {ExpectedFormat, ExpectedData}, {Format, Data}})->
- ?IPRINT("*** Unexpected Behaviour *** Id: ~w.~n"
+ ?EPRINT("*** Unexpected Behaviour *** Id: ~w.~n"
" Expected: " ++ ExpectedFormat ++ "~n"
" Got: " ++ Format ++ "~n",
[Id] ++ ExpectedData ++ Data),
{error, Id, {ExpectedFormat, ExpectedData}, {Format, Data}};
echo_errors(ok) -> ok;
-echo_errors({ok, Val}) -> {ok, Val}.
+echo_errors({ok, _} = OK) -> OK.
get_response_impl(Id, ExpVars) ->
?IPRINT("await response ~w with"
@@ -741,14 +741,22 @@ get_response_impl(Id, ExpVars) ->
{"Type: ~w, ErrStat: ~w, Idx: ~w",
[Type2, Err2, Index2]}};
- {error, Reason} ->
+ {error, Reason} ->
+ %% We did not get the message we wanted,
+ %% but what did we get?
?EPRINT("unexpected receive pdu error: ~w"
- "~n ~p", [Id, Reason]),
+ "~n Reason: ~p"
+ "~n Msg Que: ~p", [Id, Reason, msgs()]),
format_reason(Id, Reason)
end.
+msgs() ->
+ {messages, Msgs} = process_info(self(), messages),
+ Msgs.
+
+
%%----------------------------------------------------------------------
%% Returns: ok | {error, Id, {ExpectedFormat, ExpectedData}, {Format, Data}}
%%----------------------------------------------------------------------
@@ -759,8 +767,11 @@ expect_impl(Id, any) ->
?IPRINT("received expected pdu (~w)", [Id]),
ok;
{error, Reason} ->
+ %% We did not get the message we wanted,
+ %% but what did we get?
?EPRINT("unexpected receive error: ~w"
- "~n ~p", [Id, Reason]),
+ "~n Reason: ~p"
+ "~n Msg Que: ~p", [Id, Reason, msgs()]),
format_reason(Id, Reason)
end;
@@ -771,8 +782,11 @@ expect_impl(Id, return) ->
?IPRINT("received expected pdu (~w)", [Id]),
{ok, PDU};
{error, Reason} ->
+ %% We did not get the message we wanted,
+ %% but what did we get?
?EPRINT("unexpected receive error: ~w"
- "~n ~p", [Id, Reason]),
+ "~n Reason: ~p"
+ "~n Msg Que: ~p", [Id, Reason, msgs()]),
format_reason(Id, Reason)
end;
@@ -783,8 +797,11 @@ expect_impl(Id, trap) ->
?IPRINT("received expected trap (~w)", [Id]),
ok;
{error, Reason} ->
+ %% We did not get the message we wanted,
+ %% but what did we get?
?EPRINT("unexpected receive error: ~w"
- "~n ~p", [Id, Reason]),
+ "~n Reason: ~p"
+ "~n Msg Que: ~p", [Id, Reason, msgs()]),
format_reason(Id, Reason)
end;
@@ -821,8 +838,11 @@ expect_impl(Id, Err) when is_atom(Err) ->
{"ErrorStatus: ~w", [Err2]}};
{error, Reason} ->
+ %% We did not get the message we wanted,
+ %% but what did we get?
?EPRINT("unexpected receive error: ~w"
- "~n ~p", [Id, Reason]),
+ "~n Reason: ~p"
+ "~n Msg Que: ~p", [Id, Reason, msgs()]),
format_reason(Id, Reason)
end;
@@ -855,8 +875,11 @@ expect_impl(Id, ExpectedVarbinds) when is_list(ExpectedVarbinds) ->
{"Type: ~w, ErrStat: ~w, Idx: ~w", [Type2, Err2, Index2]}};
{error, Reason} ->
+ %% We did not get the message we wanted,
+ %% but what did we get?
?EPRINT("unexpected receive error: ~w"
- "~n ~p", [Id, Reason]),
+ "~n Reason: ~p"
+ "~n Msg Que: ~p", [Id, Reason, msgs()]),
format_reason(Id, Reason)
end.
@@ -889,8 +912,11 @@ expect_impl(Id, v2trap, ExpectedVarbinds) when is_list(ExpectedVarbinds) ->
{"Type: ~w, ErrStat: ~w, Idx: ~w", [Type2, Err2, Index2]}};
{error, Reason} ->
+ %% We did not get the message we wanted,
+ %% but what did we get?
?EPRINT("unexpected receive error: ~w"
- "~n ~p", [Id, Reason]),
+ "~n Reason: ~p"
+ "~n Msg Que: ~p", [Id, Reason, msgs()]),
format_reason(Id, Reason)
end;
@@ -923,8 +949,11 @@ expect_impl(Id, report, ExpectedVarbinds) when is_list(ExpectedVarbinds) ->
{"Type: ~w, ErrStat: ~w, Idx: ~w", [Type2, Err2, Index2]}};
{error, Reason} ->
+ %% We did not get the message we wanted,
+ %% but what did we get?
?EPRINT("unexpected receive error: ~w"
- "~n ~p", [Id, Reason]),
+ "~n Reason: ~p"
+ "~n Msg Que: ~p", [Id, Reason, msgs()]),
format_reason(Id, Reason)
end;
@@ -984,8 +1013,11 @@ expect_impl(Id, {inform, Reply}, ExpectedVarbinds)
{"Type: ~w, ErrStat: ~w, Idx: ~w", [Type2, Err2, Index2]}};
{error, Reason} ->
+ %% We did not get the message we wanted,
+ %% but what did we get?
?EPRINT("unexpected receive error: ~w"
- "~n ~p", [Id, Reason]),
+ "~n Reason: ~p"
+ "~n Msg Que: ~p", [Id, Reason, msgs()]),
format_reason(Id, Reason)
end.
@@ -1043,8 +1075,11 @@ expect_impl(Id, Err, Index, any = _ExpectedVarbinds) ->
{"Type: ~w, ErrStat: ~w, Idx: ~w", [Type2, Err2, Index2]}};
{error, Reason} ->
+ %% We did not get the message we wanted,
+ %% but what did we get?
?EPRINT("unexpected (receive) response: "
- "~n ~p", [Reason]),
+ "~n Reason: ~p"
+ "~n Msg Que: ~p", [Id, Reason, msgs()]),
format_reason(Id, Reason)
end;
@@ -1122,8 +1157,11 @@ expect_impl(Id, Err, Index, ExpectedVarbinds) ->
[Type2,Err2,Index2,VBs]}};
{error, Reason} ->
+ %% We did not get the message we wanted,
+ %% but what did we get?
?EPRINT("unexpected receive pdu error: ~w"
- "~n ~p", [Id, Reason]),
+ "~n Reason: ~p"
+ "~n Msg Que: ~p", [Id, Reason, msgs()]),
format_reason(Id, Reason)
end.
@@ -1172,8 +1210,11 @@ expect_impl(Id, trap, Enterp, Generic, Specific, ExpectedVarbinds) ->
[Ent2, G2, Spec2, VBs]}};
{error, Reason} ->
+ %% We did not get the message we wanted,
+ %% but what did we get?
?EPRINT("unexpected receive trap pdu error: ~w"
- "~n ~p", [Id, Reason]),
+ "~n Reason: ~p"
+ "~n Msg Que: ~p", [Id, Reason, msgs()]),
format_reason(Id, Reason)
end.
--
2.26.2