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
This commit is contained in:
parent
6e12a8f78a
commit
ee212a16f3
2 changed files with 14 additions and 9 deletions
|
|
@ -884,21 +884,21 @@ sub cleanup {
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 waitForAllForks( )
|
=head2 C<< waitForAllForks( [ $wait_time ] ) >>
|
||||||
|
|
||||||
Will block until all WebGUI::Fork processes are completed.
|
Will block until all WebGUI::Fork processes are completed.
|
||||||
|
Optional argument C<< $wait_time >> gives a maxmimum wait time before turning in failure.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub waitForAllForks {
|
sub waitForAllForks {
|
||||||
my ( $class ) = @_;
|
my ( $class, $wait_time ) = @_;
|
||||||
my $session = session;
|
my $session = session;
|
||||||
my @forkIds = $session->db->quickArray( "SELECT id FROM Fork WHERE finished != 1" );
|
my @forkIds = $session->db->quickArray( "SELECT id FROM Fork WHERE finished != 1" );
|
||||||
my $wait = 1;
|
my $start_time = time;
|
||||||
while ( $wait ) {
|
while ( 1 ) {
|
||||||
$wait = 0;
|
return 1 if ! grep { !$_->isFinished } map { WebGUI::Fork->new( $session, $_ ) } @forkIds;
|
||||||
$wait = 1 if grep { !$_->isFinished } map { WebGUI::Fork->new( $session, $_ ) } @forkIds;
|
return if $wait_time and $start_time + $wait_time < time;
|
||||||
return unless $wait;
|
|
||||||
sleep 1;
|
sleep 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,8 @@ use WebGUI::Asset;
|
||||||
use WebGUI::AssetHelper::Copy;
|
use WebGUI::AssetHelper::Copy;
|
||||||
use WebGUI::Test::Mechanize;
|
use WebGUI::Test::Mechanize;
|
||||||
|
|
||||||
|
$SIG{HUP} = sub { use Carp; confess "hup"; };
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Init
|
# Init
|
||||||
my $session = WebGUI::Test->session;
|
my $session = WebGUI::Test->session;
|
||||||
|
|
@ -30,7 +32,7 @@ my $session = WebGUI::Test->session;
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Tests
|
# 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
|
# put your tests here
|
||||||
|
|
@ -51,9 +53,12 @@ my $root = WebGUI::Asset->getRoot($session);
|
||||||
},
|
},
|
||||||
'AssetHelper/Copy forks a process'
|
'AssetHelper/Copy forks a process'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
addToCleanup( 'WebGUI::Fork' => $output->{forkId} );
|
||||||
}
|
}
|
||||||
|
|
||||||
WebGUI::Test->waitForAllForks;
|
ok(WebGUI::Test->waitForAllForks(10), "Forks finished");
|
||||||
|
|
||||||
$session->cache->clear;
|
$session->cache->clear;
|
||||||
my $clippies = $root->getLineage(["descendants"], {statesToInclude => [qw{clipboard clipboard-limbo}], returnObjects => 1,});
|
my $clippies = $root->getLineage(["descendants"], {statesToInclude => [qw{clipboard clipboard-limbo}], returnObjects => 1,});
|
||||||
is @{ $clippies }, 1, '... only copied 1 asset to the clipboard, no children';
|
is @{ $clippies }, 1, '... only copied 1 asset to the clipboard, no children';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue