From ec8902ce0fa53ac15955cccd74b6cf118586474a Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Mon, 22 Aug 2022 13:16:33 -0600 Subject: [PATCH] Consolidate PERL_TEST_TIME_OUT_FACTOR to watchdog() This changes test.pl watchdog() to always consider this potential setting of an environment variable, and removes the distributed uses. This means that no code needs to change when tests start failing on a slow platform due to timing out; or when you need to temporarily increase the timeout of a test for debugging. This will correspondingly increase the timeout of all tests, but who cares for debugging purposes. --- dist/threads/t/libc.t | 5 +---- t/re/fold_grind.pl | 4 +--- t/re/pat_advanced.t | 2 +- t/re/pat_psycho.t | 4 +--- t/re/speed.t | 4 +--- t/test.pl | 16 ++++++++++++++-- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/dist/threads/t/libc.t b/dist/threads/t/libc.t index 65958949f6..592b8d350e 100644 --- a/dist/threads/t/libc.t +++ b/dist/threads/t/libc.t @@ -9,11 +9,8 @@ BEGIN { skip_all(q/Perl not compiled with 'useithreads'/); } - my $time_out_factor = $ENV{PERL_TEST_TIME_OUT_FACTOR} || 1; - $time_out_factor = 1 if $time_out_factor < 1; - # Guard against bugs that result in deadlock - watchdog(1 * 60 * $time_out_factor); + watchdog(1 * 60); plan(11); } diff --git a/t/re/fold_grind.pl b/t/re/fold_grind.pl index 9d2ed86ba1..b304d303d3 100644 --- a/t/re/fold_grind.pl +++ b/t/re/fold_grind.pl @@ -17,10 +17,8 @@ BEGIN { if ($^O eq 'dec_osf') { skip_all("$^O cannot handle this test"); } - my $time_out_factor = $ENV{PERL_TEST_TIME_OUT_FACTOR} || 1; - $time_out_factor = 1 if $time_out_factor < 1; - watchdog(5 * 60 * $time_out_factor); + watchdog(5 * 60); require './loc_tools.pl'; } diff --git a/t/re/pat_advanced.t b/t/re/pat_advanced.t index 232dbe5338..284486173f 100644 --- a/t/re/pat_advanced.t +++ b/t/re/pat_advanced.t @@ -2382,7 +2382,7 @@ EOF TODO: { # Was looping todo_skip('Triggers thread clone SEGV. See #86550') if $::running_as_thread && $::running_as_thread; - watchdog(10 * ($ENV{PERL_TEST_TIME_OUT_FACTOR} || 1)); + watchdog(10); like("\x{00DF}", qr/[\x{1E9E}_]*/i, "\"\\x{00DF}\" =~ /[\\x{1E9E}_]*/i was looping"); } diff --git a/t/re/pat_psycho.t b/t/re/pat_psycho.t index fe87ac10e0..336039521d 100644 --- a/t/re/pat_psycho.t +++ b/t/re/pat_psycho.t @@ -24,10 +24,8 @@ BEGIN { if ($^O eq 'dec_osf') { skip_all("$^O cannot handle this test"); } - my $time_out_factor = $ENV{PERL_TEST_TIME_OUT_FACTOR} || 1; - $time_out_factor = 1 if $time_out_factor < 1; - watchdog(5 * 60 * $time_out_factor); + watchdog(5 * 60); } diff --git a/t/re/speed.t b/t/re/speed.t index 26f5ae63ca..bc03fd3b64 100644 --- a/t/re/speed.t +++ b/t/re/speed.t @@ -42,9 +42,7 @@ run_tests() unless caller; sub run_tests { - watchdog(($ENV{PERL_TEST_TIME_OUT_FACTOR} || 1) - * (($::running_as_thread && $::running_as_thread) - ? 150 : 225)); + watchdog((($::running_as_thread && $::running_as_thread) ? 150 : 225)); { # [perl #120446] diff --git a/t/test.pl b/t/test.pl index ae40b15295..7ab0ff0207 100644 --- a/t/test.pl +++ b/t/test.pl @@ -1724,7 +1724,11 @@ sub warning_like { } } -# Set a watchdog to timeout the entire test file +# Set a watchdog to timeout the entire test file. The input seconds is +# multiplied by $ENV{PERL_TEST_TIME_OUT_FACTOR} (default 1; minimum 1). +# Set this in your profile for slow boxes, or use it to override the timeout +# temporarily for debugging. +# # NOTE: If the test file uses 'threads', then call the watchdog() function # _AFTER_ the 'threads' module is loaded. sub watchdog ($;$) @@ -1733,8 +1737,16 @@ sub watchdog ($;$) my $method = shift || ""; my $timeout_msg = 'Test process timed out - terminating'; + # Accept either spelling + my $timeout_factor = $ENV{PERL_TEST_TIME_OUT_FACTOR} + || $ENV{PERL_TEST_TIMEOUT_FACTOR} + || 1; + $timeout_factor = 1 if $timeout_factor < 1; + # Valgrind slows perl way down so give it more time before dying. - $timeout *= 10 if $ENV{PERL_VALGRIND}; + $timeout_factor = 10 if $timeout_factor < 10 && $ENV{PERL_VALGRIND}; + + $timeout *= $timeout_factor; my $pid_to_kill = $$; # PID for this process