aboutsummaryrefslogtreecommitdiffstats
path: root/lib/common_test/src
diff options
context:
space:
mode:
authorPeter Andersson <[email protected]>2014-01-27 14:05:44 +0100
committerPeter Andersson <[email protected]>2014-01-28 19:04:05 +0100
commit95a574b3620ec3d7420c7807b2d84f4602512229 (patch)
treebe7cfa305637082799461fe751cc28456e7c1f91 /lib/common_test/src
parentf40f4686848bbabb9357b33d08d4b4039d9d7c63 (diff)
downloadotp-95a574b3620ec3d7420c7807b2d84f4602512229.tar.gz
otp-95a574b3620ec3d7420c7807b2d84f4602512229.tar.bz2
otp-95a574b3620ec3d7420c7807b2d84f4602512229.zip
Make it possible to use raw telnet logs in parallel test case groups
Diffstat (limited to 'lib/common_test/src')
-rw-r--r--lib/common_test/src/ct_conn_log_h.erl84
-rw-r--r--lib/common_test/src/ct_util.erl11
-rw-r--r--lib/common_test/src/cth_conn_log.erl61
3 files changed, 114 insertions, 42 deletions
diff --git a/lib/common_test/src/ct_conn_log_h.erl b/lib/common_test/src/ct_conn_log_h.erl
index 6e0e0baab2..2b83ff1abb 100644
--- a/lib/common_test/src/ct_conn_log_h.erl
+++ b/lib/common_test/src/ct_conn_log_h.erl
@@ -30,79 +30,90 @@
handle_event/2, handle_call/2, handle_info/2,
terminate/2]).
--record(state, {group_leader,logs=[]}).
+-record(state, {logs=[], default_gl}).
-define(WIDTH,80).
%%%-----------------------------------------------------------------
%%% Callbacks
-init({GL,Logs}) ->
- open_files(Logs,#state{group_leader=GL}).
+init({GL,ConnLogs}) ->
+ open_files(GL,ConnLogs,#state{default_gl=GL}).
-open_files([{ConnMod,{LogType,Logs}}|T],State) ->
- case do_open_files(Logs,[]) of
+open_files(GL,[{ConnMod,{LogType,ConnLogs}}|T],State) ->
+ case do_open_files(GL,ConnLogs,[]) of
{ok,Fds} ->
- open_files(T,State#state{logs=[{ConnMod,{LogType,Fds}} |
- State#state.logs]});
+ open_files(GL,T,State#state{logs=[{GL,[{ConnMod,{LogType,Fds}}]} |
+ State#state.logs]});
Error ->
Error
end;
-open_files([],State) ->
+open_files(_GL,[],State) ->
{ok,State}.
-
-do_open_files([{Tag,File}|Logs],Acc) ->
+do_open_files(GL,[{Tag,File}|ConnLogs],Acc) ->
case file:open(File, [write,append,{encoding,utf8}]) of
{ok,Fd} ->
- do_open_files(Logs,[{Tag,Fd}|Acc]);
+ do_open_files(GL,ConnLogs,[{Tag,Fd}|Acc]);
{error,Reason} ->
{error,{could_not_open_log,File,Reason}}
end;
-do_open_files([],Acc) ->
+do_open_files(_GL,[],Acc) ->
{ok,lists:reverse(Acc)}.
+handle_event({info_report,_,{From,update,{GL,ConnLogs}}},
+ State) when node(GL) == node() ->
+
+ %%! --- Tue Jan 28 12:18:50 2014 --- peppe was here!
+ io:format(user, "!!! ADDING NEW LOGS FOR ~p~n", [GL]),
+
+ open_files(GL,ConnLogs,#state{}),
+ From ! {updated,GL},
+ {ok, State};
handle_event({_Type, GL, _Msg}, State) when node(GL) /= node() ->
{ok, State};
-handle_event({_Type,_GL,{Pid,{ct_connection,Mod,Action,ConnName},Report}},
+handle_event({_Type,GL,{Pid,{ct_connection,Mod,Action,ConnName},Report}},
State) ->
Info = conn_info(Pid,#conn_log{name=ConnName,action=Action,module=Mod}),
- write_report(now(),Info,Report,State),
+ write_report(now(),Info,Report,GL,State),
{ok, State};
-handle_event({_Type,_GL,{Pid,Info=#conn_log{},Report}},State) ->
- write_report(now(),conn_info(Pid,Info),Report,State),
+handle_event({_Type,GL,{Pid,Info=#conn_log{},Report}}, State) ->
+ write_report(now(),conn_info(Pid,Info),Report,GL,State),
{ok, State};
-handle_event({error_report,_,{Pid,_,[{ct_connection,ConnName}|R]}},State) ->
+handle_event({error_report,GL,{Pid,_,[{ct_connection,ConnName}|R]}}, State) ->
%% Error reports from connection
- write_error(now(),conn_info(Pid,#conn_log{name=ConnName}),R,State),
+ write_error(now(),conn_info(Pid,#conn_log{name=ConnName}),R,GL,State),
{ok, State};
-handle_event(_, State) ->
+handle_event(_What, State) ->
{ok, State}.
-handle_info(_, State) ->
+handle_info(_What, State) ->
{ok, State}.
handle_call(_Query, State) ->
{ok, {error, bad_query}, State}.
terminate(_,#state{logs=Logs}) ->
- [file:close(Fd) || {_,{_,Fds}} <- Logs, {_,Fd} <- Fds],
+ lists:foreach(
+ fun({_GL,ConnLogs}) ->
+ [file:close(Fd) || {_,{_,Fds}} <- ConnLogs, {_,Fd} <- Fds]
+ end, Logs),
ok.
%%%-----------------------------------------------------------------
%%% Writing reports
-write_report(_Time,#conn_log{header=false,module=ConnMod}=Info,Data,State) ->
- {LogType,Fd} = get_log(Info,State),
+write_report(_Time,#conn_log{header=false,module=ConnMod}=Info,Data,GL,State) ->
+ {LogType,Fd} = get_log(Info,GL,State),
io:format(Fd,"~n~ts",[format_data(ConnMod,LogType,Data)]);
-write_report(Time,#conn_log{module=ConnMod}=Info,Data,State) ->
- {LogType,Fd} = get_log(Info,State),
+write_report(Time,#conn_log{module=ConnMod}=Info,Data,GL,State) ->
+ {LogType,Fd} = get_log(Info,GL,State),
io:format(Fd,"~n~ts~ts~ts",[format_head(ConnMod,LogType,Time),
format_title(LogType,Info),
format_data(ConnMod,LogType,Data)]).
-write_error(Time,#conn_log{module=ConnMod}=Info,Report,State) ->
- case get_log(Info,State) of
+write_error(Time,#conn_log{module=ConnMod}=Info,Report,GL,State) ->
+ case get_log(Info,GL,State) of
{html,_} ->
%% The error will anyway be written in the html log by the
%% sasl error handler, so don't write it again.
@@ -114,14 +125,19 @@ write_error(Time,#conn_log{module=ConnMod}=Info,Report,State) ->
format_error(LogType,Report)])
end.
-get_log(Info,State) ->
- case proplists:get_value(Info#conn_log.module,State#state.logs) of
- {html,_} ->
- {html,State#state.group_leader};
- {LogType,Fds} ->
- {LogType,get_fd(Info,Fds)};
+get_log(Info,GL,State) ->
+ case proplists:get_value(GL, State#state.logs) of
undefined ->
- {html,State#state.group_leader}
+ {html,State#state.default_gl};
+ ConnLogs ->
+ case proplists:get_value(Info#conn_log.module,ConnLogs) of
+ {html,_} ->
+ {html,GL};
+ {LogType,Fds} ->
+ {LogType,get_fd(Info,Fds)};
+ undefined ->
+ {html,GL}
+ end
end.
get_fd(#conn_log{name=undefined},Fds) ->
diff --git a/lib/common_test/src/ct_util.erl b/lib/common_test/src/ct_util.erl
index bcc4caa62e..1d851f8d2f 100644
--- a/lib/common_test/src/ct_util.erl
+++ b/lib/common_test/src/ct_util.erl
@@ -382,9 +382,14 @@ loop(Mode,TestData,StartDir) ->
TestData1 =
case lists:keysearch(Key,1,TestData) of
{value,{Key,Val}} ->
- NewVal = Fun(Val),
- return(From,NewVal),
- [{Key,NewVal}|lists:keydelete(Key,1,TestData)];
+ case Fun(Val) of
+ '$delete' ->
+ return(From,deleted),
+ lists:keydelete(Key,1,TestData);
+ NewVal ->
+ return(From,NewVal),
+ [{Key,NewVal}|lists:keydelete(Key,1,TestData)]
+ end;
_ ->
case lists:member(create,Opts) of
true ->
diff --git a/lib/common_test/src/cth_conn_log.erl b/lib/common_test/src/cth_conn_log.erl
index d5762bada8..050bda6eda 100644
--- a/lib/common_test/src/cth_conn_log.erl
+++ b/lib/common_test/src/cth_conn_log.erl
@@ -104,7 +104,7 @@ get_log_opts(Opts) ->
pre_init_per_testcase(TestCase,Config,CthState) ->
Logs =
lists:map(
- fun({ConnMod,{LogType,Hosts}}) ->
+ fun({ConnMod,{LogType,Hosts}}) ->
ct_util:set_testdata({{?MODULE,ConnMod},LogType}),
case LogType of
LogType when LogType==raw; LogType==pretty ->
@@ -136,10 +136,61 @@ pre_init_per_testcase(TestCase,Config,CthState) ->
end
end,
CthState),
- error_logger:add_report_handler(ct_conn_log_h,{group_leader(),Logs}),
+
+ GL = group_leader(),
+ Update =
+ fun(Init) when Init == undefined; Init == [] ->
+
+ %%! --- Tue Jan 28 12:13:08 2014 --- peppe was here!
+ io:format(user, "### ~p: ADDING NEW HANDLER FOR ~p~n",
+ [TestCase,GL]),
+
+ error_logger:add_report_handler(ct_conn_log_h,{GL,Logs}),
+ [TestCase];
+ (PrevUsers) ->
+
+ %%! --- Tue Jan 28 12:13:08 2014 --- peppe was here!
+ io:format(user, "### ~p: CONNECTING ~p TO EXISTING HANDLER~n",
+ [TestCase,GL]),
+
+ error_logger:info_report(update,{GL,Logs}),
+ receive
+ {updated,GL} ->
+ [TestCase|PrevUsers]
+ after
+ 5000 ->
+ {error,no_response}
+ end
+ end,
+ ct_util:update_testdata(?MODULE, Update, [create]),
{Config,CthState}.
-post_end_per_testcase(_TestCase,_Config,Return,CthState) ->
- [ct_util:delete_testdata({?MODULE,ConnMod}) || {ConnMod,_} <- CthState],
- error_logger:delete_report_handler(ct_conn_log_h),
+post_end_per_testcase(TestCase,_Config,Return,CthState) ->
+ Update =
+ fun(PrevUsers) ->
+ case lists:delete(TestCase, PrevUsers) of
+ [] ->
+ '$delete';
+ PrevUsers1 ->
+ PrevUsers1
+ end
+ end,
+ case ct_util:update_testdata(?MODULE, Update) of
+ deleted ->
+ [ct_util:delete_testdata({?MODULE,ConnMod}) ||
+ {ConnMod,_} <- CthState],
+
+ %%! --- Tue Jan 28 13:29:37 2014 --- peppe was here!
+ io:format(user, "### ~p: REMOVING ERROR LOGGER~n", [TestCase]),
+
+ error_logger:delete_report_handler(ct_conn_log_h);
+ {error,no_response} ->
+ exit({?MODULE,no_response_from_logger});
+ _PrevUsers ->
+ %%! --- Tue Jan 28 13:29:37 2014 --- peppe was here!
+ io:format(user, "### ~p: *NOT* REMOVING ERROR LOGGER~n", [TestCase]),
+
+ ok
+ end,
{Return,CthState}.
+