aboutsummaryrefslogtreecommitdiffstats
path: root/lib/common_test
diff options
context:
space:
mode:
authorPeter Andersson <[email protected]>2011-04-19 23:25:12 +0200
committerPeter Andersson <[email protected]>2011-04-28 22:45:58 +0200
commit0197acace48c17dcb500b7bdb10d2cc1cbaa848e (patch)
treedb8cbd8253a578c70eacb1001964b449cc2e9e53 /lib/common_test
parent0634077b636eb0c879e1f71ba78ea1565b6617b2 (diff)
downloadotp-0197acace48c17dcb500b7bdb10d2cc1cbaa848e.tar.gz
otp-0197acace48c17dcb500b7bdb10d2cc1cbaa848e.tar.bz2
otp-0197acace48c17dcb500b7bdb10d2cc1cbaa848e.zip
Fix problems with timetrap handling in common_test:
1. ct:timetrap(infinity) not supported. 2. Previous set timetrap for a test case is not cancelled by new one.
Diffstat (limited to 'lib/common_test')
-rw-r--r--lib/common_test/src/ct.erl1
-rw-r--r--lib/common_test/test/ct_error_SUITE.erl70
-rw-r--r--lib/common_test/test/ct_error_SUITE_data/error/test/timetrap_2_SUITE.erl26
3 files changed, 89 insertions, 8 deletions
diff --git a/lib/common_test/src/ct.erl b/lib/common_test/src/ct.erl
index dfec2b7a67..66da3ef742 100644
--- a/lib/common_test/src/ct.erl
+++ b/lib/common_test/src/ct.erl
@@ -861,6 +861,7 @@ remove_config(Callback, Config) ->
%%%
%%% @doc <p>Use this function to set a new timetrap for the running test case.</p>
timetrap(Time) ->
+ test_server:timetrap_cancel(),
test_server:timetrap(Time).
%%%-----------------------------------------------------------------
diff --git a/lib/common_test/test/ct_error_SUITE.erl b/lib/common_test/test/ct_error_SUITE.erl
index c4ad2934ae..813467aabe 100644
--- a/lib/common_test/test/ct_error_SUITE.erl
+++ b/lib/common_test/test/ct_error_SUITE.erl
@@ -210,6 +210,23 @@ timetrap_extended(Config) when is_list(Config) ->
ok = ct_test_support:verify_events(TestEvents, Events, Config).
%%%-----------------------------------------------------------------
+%%%
+timetrap_parallel(Config) when is_list(Config) ->
+ DataDir = ?config(data_dir, Config),
+ Join = fun(D, S) -> filename:join(D, "error/test/"++S) end,
+ Suite = Join(DataDir, "timetrap_3_SUITE"),
+ {Opts,ERPid} = setup([{suite,Suite}], Config),
+ ok = ct_test_support:run(Opts, Config),
+ Events = ct_test_support:get_events(ERPid, Config),
+
+ ct_test_support:log_events(timetrap_parallel,
+ reformat(Events, ?eh),
+ ?config(priv_dir, Config)),
+
+ TestEvents = events_to_check(timetrap_parallel),
+ ok = ct_test_support:verify_events(TestEvents, Events, Config).
+
+%%%-----------------------------------------------------------------
%%% HELP FUNCTIONS
%%%-----------------------------------------------------------------
@@ -735,7 +752,7 @@ test_events(timetrap_normal) ->
[
{?eh,start_logging,{'DEF','RUNDIR'}},
{?eh,test_start,{'DEF',{'START_TIME','LOGDIR'}}},
- {?eh,start_info,{1,1,3}},
+ {?eh,start_info,{1,1,4}},
{?eh,tc_start,{timetrap_2_SUITE,init_per_suite}},
{?eh,tc_done,{timetrap_2_SUITE,init_per_suite,ok}},
{?eh,tc_start,{timetrap_2_SUITE,tc0}},
@@ -750,6 +767,9 @@ test_events(timetrap_normal) ->
{?eh,tc_done,
{timetrap_2_SUITE,tc2,{failed,{timetrap_timeout,500}}}},
{?eh,test_stats,{0,3,{0,0}}},
+ {?eh,tc_start,{timetrap_2_SUITE,tc3}},
+ {?eh,tc_done,{timetrap_2_SUITE,tc3,ok}},
+ {?eh,test_stats,{1,3,{0,0}}},
{?eh,tc_start,{timetrap_2_SUITE,end_per_suite}},
{?eh,tc_done,{timetrap_2_SUITE,end_per_suite,ok}},
{?eh,test_done,{'DEF','STOP_TIME'}},
@@ -760,7 +780,7 @@ test_events(timetrap_extended) ->
[
{?eh,start_logging,{'DEF','RUNDIR'}},
{?eh,test_start,{'DEF',{'START_TIME','LOGDIR'}}},
- {?eh,start_info,{1,1,3}},
+ {?eh,start_info,{1,1,4}},
{?eh,tc_start,{timetrap_2_SUITE,init_per_suite}},
{?eh,tc_done,{timetrap_2_SUITE,init_per_suite,ok}},
{?eh,tc_start,{timetrap_2_SUITE,tc0}},
@@ -775,8 +795,52 @@ test_events(timetrap_extended) ->
{?eh,tc_done,
{timetrap_2_SUITE,tc2,{failed,{timetrap_timeout,1000}}}},
{?eh,test_stats,{0,3,{0,0}}},
+ {?eh,tc_start,{timetrap_2_SUITE,tc3}},
+ {?eh,tc_done,{timetrap_2_SUITE,tc3,ok}},
+ {?eh,test_stats,{1,3,{0,0}}},
{?eh,tc_start,{timetrap_2_SUITE,end_per_suite}},
{?eh,tc_done,{timetrap_2_SUITE,end_per_suite,ok}},
{?eh,test_done,{'DEF','STOP_TIME'}},
{?eh,stop_logging,[]}
- ].
+ ];
+
+test_events(timetrap_parallel) ->
+ [
+ {?eh,start_logging,{'DEF','RUNDIR'}},
+ {?eh,test_start,{'DEF',{'START_TIME','LOGDIR'}}},
+ {?eh,start_info,{1,1,7}},
+ {?eh,tc_done,{timetrap_3_SUITE,init_per_suite,ok}},
+ {parallel,
+ [{?eh,tc_start,
+ {timetrap_3_SUITE,{init_per_group,g1,[parallel]}}},
+ {?eh,tc_done,
+ {timetrap_3_SUITE,{init_per_group,g1,[parallel]},ok}},
+ {?eh,tc_start,{timetrap_3_SUITE,tc0}},
+ {?eh,tc_start,{timetrap_3_SUITE,tc1}},
+ {?eh,tc_start,{timetrap_3_SUITE,tc2}},
+ {?eh,tc_start,{timetrap_3_SUITE,tc3}},
+ {?eh,tc_start,{timetrap_3_SUITE,tc4}},
+ {?eh,tc_start,{timetrap_3_SUITE,tc6}},
+ {?eh,tc_start,{timetrap_3_SUITE,tc7}},
+ {?eh,tc_done,
+ {timetrap_3_SUITE,tc1,{failed,{timetrap_timeout,500}}}},
+ {?eh,tc_done,
+ {timetrap_3_SUITE,tc2,{failed,{timetrap_timeout,1000}}}},
+ {?eh,tc_done,
+ {timetrap_3_SUITE,tc6,{failed,{timetrap_timeout,1000}}}},
+ {?eh,tc_done,
+ {timetrap_3_SUITE,tc7,{failed,{timetrap_timeout,1500}}}},
+ {?eh,tc_done,
+ {timetrap_3_SUITE,tc0,{failed,{timetrap_timeout,2000}}}},
+ {?eh,tc_done,
+ {timetrap_3_SUITE,tc4,{failed,{timetrap_timeout,2000}}}},
+ {?eh,tc_done,
+ {timetrap_3_SUITE,tc3,{failed,{timetrap_timeout,3000}}}},
+ {?eh,test_stats,{0,7,{0,0}}},
+ {?eh,tc_start,
+ {timetrap_3_SUITE,{end_per_group,g1,[parallel]}}},
+ {?eh,tc_done,
+ {timetrap_3_SUITE,{end_per_group,g1,[parallel]},ok}}]},
+ {?eh,tc_done,{timetrap_3_SUITE,end_per_suite,ok}},
+ {?eh,test_done,{'DEF','STOP_TIME'}},
+ {?eh,stop_logging,[]}].
diff --git a/lib/common_test/test/ct_error_SUITE_data/error/test/timetrap_2_SUITE.erl b/lib/common_test/test/ct_error_SUITE_data/error/test/timetrap_2_SUITE.erl
index 99bb400137..7fcb631d06 100644
--- a/lib/common_test/test/ct_error_SUITE_data/error/test/timetrap_2_SUITE.erl
+++ b/lib/common_test/test/ct_error_SUITE_data/error/test/timetrap_2_SUITE.erl
@@ -77,8 +77,8 @@ init_per_testcase(tc1, Config) ->
ct:timetrap({seconds,1}),
Config;
-init_per_testcase(tc3, Config) ->
- ct:timetrap({seconds,1}),
+init_per_testcase(tc2, Config) ->
+ ct:timetrap(250),
Config;
init_per_testcase(_TestCase, Config) ->
@@ -90,7 +90,7 @@ init_per_testcase(_TestCase, Config) ->
%% TestCase = atom()
%% Config0 = Config1 = [tuple()]
%%--------------------------------------------------------------------
-end_per_testcase(_, Config) ->
+end_per_testcase(_, _Config) ->
ok.
%%--------------------------------------------------------------------
@@ -116,7 +116,7 @@ groups() ->
%% Reason = term()
%%--------------------------------------------------------------------
all() ->
- [tc0,tc1,tc2].
+ [tc0,tc1,tc2,tc3].
tc0(_) ->
N = list_to_integer(ct:get_config(multiply)),
@@ -131,8 +131,24 @@ tc1(_) ->
ok.
tc2(_) ->
+ ct:timetrap(500),
N = list_to_integer(ct:get_config(multiply)),
ct:comment(io_lib:format("TO after ~w sec", [0.5*N])),
- ct:timetrap(500),
ct:sleep(2000),
ok.
+
+tc3() ->
+ [{timetrap,{seconds,2}}].
+
+tc3(_) ->
+ T0 = now(),
+ ct:timetrap(infinity),
+ N = list_to_integer(ct:get_config(multiply)),
+ ct:comment(io_lib:format("Sleeping for ~w sec...", [4*N])),
+ ct:sleep(4000),
+ Diff = timer:now_diff(now(), T0),
+ if ((Diff < (N*4000000)) or (Diff > (N*4500000))) ->
+ exit(not_expected);
+ true ->
+ ok
+ end.