Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:23
erlang
1301-ct-fix-end_per_testcase-hooks-for-failed-t...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 1301-ct-fix-end_per_testcase-hooks-for-failed-test.patch of Package erlang
From 4f0fbcaa036a15c8cff6092ac0e46e5878351e7e Mon Sep 17 00:00:00 2001 From: Jakub Witczak <kuba@erlang.org> Date: Tue, 16 May 2023 12:57:52 +0200 Subject: [PATCH 1/4] ct: fix end_per_testcase hooks for failed test --- lib/common_test/src/test_server.erl | 25 ++- lib/common_test/test/ct_hooks_SUITE.erl | 192 ++++++++++-------- .../cth/tests/ct_update_config_SUITE.erl | 10 +- 3 files changed, 138 insertions(+), 89 deletions(-) diff --git a/lib/common_test/src/test_server.erl b/lib/common_test/src/test_server.erl index d6a882e315..7b4131aa03 100644 --- a/lib/common_test/src/test_server.erl +++ b/lib/common_test/src/test_server.erl @@ -561,8 +561,16 @@ run_test_case_msgloop(#st{ref=Ref,pid=Pid,end_conf_pid=EndConfPid0}=St0) -> handle_tc_exit(Reason, St0) end, run_test_case_msgloop(St); - {EndConfPid0,{call_end_conf,Data,_Result}} -> - #st{mf={Mod,Func},config=CurrConf} = St0, + {EndConfPid0,{call_end_conf,Data,EndConf,_Result}} -> + #st{mf={Mod,Func},config=CurrConfFromState} = St0, + CurrConf = case EndConf of + [] -> + %% use latest stored Config + CurrConfFromState; + _ -> + %% use latest Config prepared in pre_end_per_testcase + EndConf + end, case CurrConf of _ when is_list(CurrConf) -> {_Mod,_Func,TCPid,TCExitReason,Loc} = Data, @@ -742,7 +750,7 @@ call_end_conf(Mod,Func,TCPid,TCExitReason,Loc,Conf,TVal) -> case erlang:function_exported(Mod,end_per_testcase,2) of false -> spawn_link(fun() -> - Starter ! {self(),{call_end_conf,Data,ok}} + Starter ! {self(),{call_end_conf,Data,[],ok}} end); true -> do_call_end_conf(Starter,Mod,Func,Data,TCExitReason,Conf,TVal) @@ -776,15 +784,18 @@ do_call_end_conf(Starter,Mod,Func,Data,TCExitReason,Conf,TVal) -> print_end_conf_result(Mod,Func,Conf, "crashed",Error) end, - Supervisor ! {self(),end_conf} + Supervisor ! {self(),end_conf, EndConf} end, Pid = spawn_link(EndConfApply), receive - {Pid,end_conf} -> - Starter ! {self(),{call_end_conf,Data,ok}}; + {Pid,end_conf, EndConf} -> + %% Return EndConf to parent process to + %% post_end_per_testcase callback can receive latest + %% Config returned from pre_end_per_testcase + Starter ! {self(),{call_end_conf,Data,EndConf,ok}}; {'EXIT',Pid,Reason} -> print_end_conf_result(Mod,Func,Conf,"failed",Reason), - Starter ! {self(),{call_end_conf,Data,{error,Reason}}}; + Starter ! {self(),{call_end_conf,Data,[],{error,Reason}}}; {'EXIT',_OtherPid,Reason} -> %% Probably the parent - not much to do about that exit(Reason) diff --git a/lib/common_test/test/ct_hooks_SUITE.erl b/lib/common_test/test/ct_hooks_SUITE.erl index 0133d8f371..79960224eb 100644 --- a/lib/common_test/test/ct_hooks_SUITE.erl +++ b/lib/common_test/test/ct_hooks_SUITE.erl @@ -28,7 +28,7 @@ %%%------------------------------------------------------------------- -module(ct_hooks_SUITE). --compile(export_all). +-compile([export_all, nowarn_export_all]). -include_lib("common_test/include/ct.hrl"). -include_lib("common_test/include/ct_event.hrl"). @@ -1193,6 +1193,62 @@ test_events(recover_post_suite_cth) -> ]; test_events(update_config_cth) -> + TestCaseEvents = + fun(Case, Result) -> + [ + {?eh,tc_start,{ct_update_config_SUITE,Case}}, + {?eh,cth,{'_',pre_init_per_testcase, + [ct_update_config_SUITE, + Case,contains( + [post_init_per_group, + init_per_group, + pre_init_per_group, + post_init_per_suite, + init_per_suite, + pre_init_per_suite]), + []]}}, + {?eh,cth,{'_',post_init_per_testcase, + [ct_update_config_SUITE, + Case,contains( + [init_per_testcase, + pre_init_per_testcase, + post_init_per_group, + init_per_group, + pre_init_per_group, + post_init_per_suite, + init_per_suite, + pre_init_per_suite]), + ok,[]]}}, + {?eh,cth,{'_',pre_end_per_testcase, + [ct_update_config_SUITE, + Case,contains( + [post_init_per_testcase, + init_per_testcase, + pre_init_per_testcase, + post_init_per_group, + init_per_group, + pre_init_per_group, + post_init_per_suite, + init_per_suite, + pre_init_per_suite]), + []]}}, + {?eh,cth,{'_',post_end_per_testcase, + [ct_update_config_SUITE, + Case,contains( + [pre_end_per_testcase, + post_init_per_testcase, + init_per_testcase, + pre_init_per_testcase, + post_init_per_group, + init_per_group, + pre_init_per_group, + post_init_per_suite, + init_per_suite, + pre_init_per_suite]), + Result,[]]}}, + {?eh,tc_done,{ct_update_config_SUITE,Case,ok}} + ] + end, [ {?eh,start_logging,{'DEF','RUNDIR'}}, {?eh,test_start,{'DEF',{'START_TIME','LOGDIR'}}}, @@ -1205,8 +1261,8 @@ test_events(update_config_cth) -> [ct_update_config_SUITE, '$proplist', contains( - [init_per_suite, - pre_init_per_suite]), + [init_per_suite, + pre_init_per_suite]), []]}}, {?eh,tc_done,{ct_update_config_SUITE,init_per_suite,ok}}, @@ -1231,83 +1287,59 @@ test_events(update_config_cth) -> post_init_per_suite, init_per_suite, pre_init_per_suite]), - []]}}, - {?eh,tc_done,{ct_update_config_SUITE,{init_per_group,group1,[]},ok}}, - - {?eh,tc_start,{ct_update_config_SUITE,test_case}}, - {?eh,cth,{'_',pre_init_per_testcase, - [ct_update_config_SUITE, - test_case,contains( - [post_init_per_group, - init_per_group, - pre_init_per_group, - post_init_per_suite, - init_per_suite, - pre_init_per_suite]), - []]}}, - {?eh,cth,{'_',post_end_per_testcase, - [ct_update_config_SUITE, - test_case,contains( - [init_per_testcase, - pre_init_per_testcase, - post_init_per_group, - init_per_group, - pre_init_per_group, - post_init_per_suite, - init_per_suite, - pre_init_per_suite]), - ok,[]]}}, - {?eh,tc_done,{ct_update_config_SUITE,test_case,ok}}, - - {?eh,tc_start,{ct_update_config_SUITE, {end_per_group,group1,[]}}}, - {?eh,cth,{'_',pre_end_per_group, - [ct_update_config_SUITE, - group1,contains( - [post_init_per_group, - init_per_group, - pre_init_per_group, - post_init_per_suite, - init_per_suite, - pre_init_per_suite]), - []]}}, - {?eh,cth,{'_',post_end_per_group, - [ct_update_config_SUITE, - group1, - contains( - [pre_end_per_group, - post_init_per_group, - init_per_group, - pre_init_per_group, - post_init_per_suite, - init_per_suite, - pre_init_per_suite]), - ok,[]]}}, - {?eh,tc_done,{ct_update_config_SUITE,{end_per_group,group1,[]},ok}}, - - {?eh,tc_start,{ct_update_config_SUITE,end_per_suite}}, - {?eh,cth,{'_',pre_end_per_suite, - [ct_update_config_SUITE,contains( - [post_init_per_suite, - init_per_suite, - pre_init_per_suite]), - []]}}, - {?eh,cth,{'_',post_end_per_suite, - [ct_update_config_SUITE,contains( - [pre_end_per_suite, - post_init_per_suite, - init_per_suite, - pre_init_per_suite]), - '_',[]]}}, - {?eh,tc_done,{ct_update_config_SUITE,end_per_suite,ok}}, - {?eh,test_done,{'DEF','STOP_TIME'}}, - {?eh,cth,{'_',terminate,[contains( - [post_end_per_suite, - pre_end_per_suite, - post_init_per_suite, - init_per_suite, - pre_init_per_suite])]}}, - {?eh,stop_logging,[]} - ]; + []]}}, + {?eh,tc_done,{ct_update_config_SUITE,{init_per_group,group1,[]},ok}}] ++ + TestCaseEvents(test_case, ok) ++ + TestCaseEvents(test_case_timetrap, {timetrap_timeout,1000}) ++ + [{?eh,tc_start,{ct_update_config_SUITE, {end_per_group,group1,[]}}}, + {?eh,cth,{'_',pre_end_per_group, + [ct_update_config_SUITE, + group1,contains( + [post_init_per_group, + init_per_group, + pre_init_per_group, + post_init_per_suite, + init_per_suite, + pre_init_per_suite]), + []]}}, + {?eh,cth,{'_',post_end_per_group, + [ct_update_config_SUITE, + group1, + contains( + [pre_end_per_group, + post_init_per_group, + init_per_group, + pre_init_per_group, + post_init_per_suite, + init_per_suite, + pre_init_per_suite]), + ok,[]]}}, + {?eh,tc_done,{ct_update_config_SUITE,{end_per_group,group1,[]},ok}}, + + {?eh,tc_start,{ct_update_config_SUITE,end_per_suite}}, + {?eh,cth,{'_',pre_end_per_suite, + [ct_update_config_SUITE,contains( + [post_init_per_suite, + init_per_suite, + pre_init_per_suite]), + []]}}, + {?eh,cth,{'_',post_end_per_suite, + [ct_update_config_SUITE,contains( + [pre_end_per_suite, + post_init_per_suite, + init_per_suite, + pre_init_per_suite]), + '_',[]]}}, + {?eh,tc_done,{ct_update_config_SUITE,end_per_suite,ok}}, + {?eh,test_done,{'DEF','STOP_TIME'}}, + {?eh,cth,{'_',terminate,[contains( + [post_end_per_suite, + pre_end_per_suite, + post_init_per_suite, + init_per_suite, + pre_init_per_suite])]}}, + {?eh,stop_logging,[]} + ]; test_events(state_update_cth) -> [ diff --git a/lib/common_test/test/ct_hooks_SUITE_data/cth/tests/ct_update_config_SUITE.erl b/lib/common_test/test/ct_hooks_SUITE_data/cth/tests/ct_update_config_SUITE.erl index 20f139bcc8..61fd1a329d 100644 --- a/lib/common_test/test/ct_hooks_SUITE_data/cth/tests/ct_update_config_SUITE.erl +++ b/lib/common_test/test/ct_hooks_SUITE_data/cth/tests/ct_update_config_SUITE.erl @@ -52,8 +52,14 @@ all() -> [{group,group1}]. groups() -> - [{group1,[],[test_case]}]. - + [{group1,[],[test_case, test_case_timetrap]}]. + %% Test cases starts here. test_case(Config) when is_list(Config) -> ok. + +test_case_timetrap() -> + [{timetrap, {seconds, 1}}]. + +test_case_timetrap(_) -> + ct:sleep(infinity). -- 2.35.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor