From ee212a16f34b4873ccd534e674885c8134c7d70b Mon Sep 17 00:00:00 2001 From: Scott Walters Date: Mon, 2 May 2011 18:25:21 -0400 Subject: [PATCH] WebGUI::Test::waitForAllForks optionally taking a number of seconds to wait; t/AssetHelper/Copy.t using this as one of its tests; this creates a test failure out of a test suite deadlock for me --- lib/WebGUI/Test.pm | 14 +++++++------- t/AssetHelper/Copy.t | 9 +++++++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/WebGUI/Test.pm b/lib/WebGUI/Test.pm index ea78275eb..2fd561098 100644 --- a/lib/WebGUI/Test.pm +++ b/lib/WebGUI/Test.pm @@ -884,21 +884,21 @@ sub cleanup { #---------------------------------------------------------------------------- -=head2 waitForAllForks( ) +=head2 C<< waitForAllForks( [ $wait_time ] ) >> Will block until all WebGUI::Fork processes are completed. +Optional argument C<< $wait_time >> gives a maxmimum wait time before turning in failure. =cut sub waitForAllForks { - my ( $class ) = @_; + my ( $class, $wait_time ) = @_; my $session = session; my @forkIds = $session->db->quickArray( "SELECT id FROM Fork WHERE finished != 1" ); - my $wait = 1; - while ( $wait ) { - $wait = 0; - $wait = 1 if grep { !$_->isFinished } map { WebGUI::Fork->new( $session, $_ ) } @forkIds; - return unless $wait; + my $start_time = time; + while ( 1 ) { + return 1 if ! grep { !$_->isFinished } map { WebGUI::Fork->new( $session, $_ ) } @forkIds; + return if $wait_time and $start_time + $wait_time < time; sleep 1; } } diff --git a/t/AssetHelper/Copy.t b/t/AssetHelper/Copy.t index d5f731066..f2764a310 100644 --- a/t/AssetHelper/Copy.t +++ b/t/AssetHelper/Copy.t @@ -22,6 +22,8 @@ use WebGUI::Asset; use WebGUI::AssetHelper::Copy; use WebGUI::Test::Mechanize; +$SIG{HUP} = sub { use Carp; confess "hup"; }; + #---------------------------------------------------------------------------- # Init my $session = WebGUI::Test->session; @@ -30,7 +32,7 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -plan tests => 2; # Increment this number for each test you create +plan tests => 3; # Increment this number for each test you create #---------------------------------------------------------------------------- # put your tests here @@ -51,9 +53,12 @@ my $root = WebGUI::Asset->getRoot($session); }, 'AssetHelper/Copy forks a process' ); + + addToCleanup( 'WebGUI::Fork' => $output->{forkId} ); } -WebGUI::Test->waitForAllForks; +ok(WebGUI::Test->waitForAllForks(10), "Forks finished"); + $session->cache->clear; my $clippies = $root->getLineage(["descendants"], {statesToInclude => [qw{clipboard clipboard-limbo}], returnObjects => 1,}); is @{ $clippies }, 1, '... only copied 1 asset to the clipboard, no children';