From 6fce7ad83fe9f6d46b62380a2daa10ab4b46541c Mon Sep 17 00:00:00 2001 From: Bodo Hugo Barwich Date: Sun, 31 Dec 2023 06:58:43 +0300 Subject: [PATCH 1/3] documentation on Group Wait() method --- lib/Process/SubProcess.pm | 2 +- lib/Process/SubProcess/Group.pm | 84 +++- t/test_group.t | 825 +++++++++++++++++--------------- t/test_runner.t | 2 +- 4 files changed, 514 insertions(+), 399 deletions(-) diff --git a/lib/Process/SubProcess.pm b/lib/Process/SubProcess.pm index 3c49fdd..988a475 100644 --- a/lib/Process/SubProcess.pm +++ b/lib/Process/SubProcess.pm @@ -44,7 +44,7 @@ use IO::Select; use IPC::Open3; use Symbol qw(gensym); -our $VERSION = '2.1.11'; +our $VERSION = '2.1.12'; =head1 DESCRIPTION diff --git a/lib/Process/SubProcess/Group.pm b/lib/Process/SubProcess/Group.pm index 56b1f7d..a7fc264 100644 --- a/lib/Process/SubProcess/Group.pm +++ b/lib/Process/SubProcess/Group.pm @@ -58,7 +58,9 @@ in an object oriented manner. #---------------------------------------------------------------------------- #Constructors -=head1 CONSTRUCTOR +=head1 METHODS + +=head2 Constructor =over 4 @@ -151,7 +153,7 @@ sub DESTROY { #---------------------------------------------------------------------------- #Administration Methods -=head1 Administration Methods +=head2 Administration Methods =over 4 @@ -289,10 +291,10 @@ after 6 seconds. B -C - is an integer that specifies the interval in which each process should -be checked. +C - is an integer that specifies the interval in which all processes should +be checked once. -See L|Process::SubProcess/"setReadTimeout ( TIMEOUT )"> +See L|Process::SubProcess/"setReadTimeout ( TIMEOUT )"> =back @@ -340,9 +342,9 @@ This method set the C for each C object. B C - is an integer that specifies the time in seconds to wait for output -from the command. +from the command for each C object. -See L|Process::SubProcess/"setReadTimeout ( TIMEOUT )"> +See L|Process::SubProcess/"setReadTimeout ( TIMEOUT )"> =back @@ -384,6 +386,30 @@ sub setReadTimeout { } #if(defined $self->{"_array_processes"}) } +=pod + +=over 4 + +=item setTimeout ( TIMEOUT ) + +This method set the C for the C object. + +This enables the B functionality in the C method which +ensures that no process runs longer than required. The C method will call the +C method which will call the C method on each C +that is still running. + +B + +C - is an integer that specifies the maximal execution time in seconds +of the whole B execution. + +See L|/"Wait ( [ CONFIGURATIONS ] )"> + +=back + +=cut + sub setTimeout { my $self = shift; @@ -643,9 +669,9 @@ sub Check { } sub checkiProcess { - my $self = shift; + my $self = $_[0]; my $sbprc = undef; - my $iidx = shift; + my $iidx = $_[1]; my $irs = 0; $sbprc = $self->getiProcess($iidx); @@ -659,6 +685,46 @@ sub checkiProcess { return $irs; } +=pod + +=over 4 + +=item Wait ( [ CONFIGURATIONS ] ) + +This method checks the C objects regularly and continues until +all C objects report that they are not C anymore. + +If the B functionality is enabled the method will call the +C method which then calls the C method on each C +that is still running. + +B + +C - is a list are passed in a hash like fashion, using key and value pairs. + +B + +C - is an integer that specifies the interval in which all processes should +be checked once. + +C - is an integer that specifies the time in seconds to wait for output +from the command for each C object. + +C - is an integer that specifies the maximal execution time in seconds +of the whole B execution. + +See L|Process::SubProcess/"Terminate ()"> + +See L|/"setCheckInterval ( INTERVAL )"> + +See L|/"setReadTimeout ( TIMEOUT )"> + +See L|/"setTimeout ( TIMEOUT )"> + +=back + +=cut + sub Wait { #Take the Method Parameters diff --git a/t/test_group.t b/t/test_group.t index 25e9b71..838fddb 100755 --- a/t/test_group.t +++ b/t/test_group.t @@ -1,7 +1,7 @@ #!/usr/bin/perl # @author Bodo (Hugo) Barwich -# @version 2023-07-06 +# @version 2023-12-30 # @package Test for the Process::SubProcess::Group Module # @subpackage t/test_group.t @@ -12,8 +12,6 @@ # - The Perl Module "Process::SubProcess::Group" must be installed # - - use warnings; use strict; @@ -23,11 +21,10 @@ use Time::HiRes qw(gettimeofday); use Test::More; -BEGIN -{ - use lib "lib"; - use lib "../lib"; -} #BEGIN +BEGIN { + use lib "lib"; + use lib "../lib"; +} #BEGIN require_ok('Process::SubProcess'); require_ok('Process::SubProcess::Group'); @@ -35,589 +32,641 @@ require_ok('Process::SubProcess::Group'); use Process::SubProcess; use Process::SubProcess::Group; - - my $smodule = ""; -my $spath = abs_path($0); +my $spath = abs_path($0); - -($smodule = $spath) =~ s/.*\/([^\/]+)$/$1/; +( $smodule = $spath ) =~ s/.*\/([^\/]+)$/$1/; $spath =~ s/^(.*\/)$smodule$/$1/; - my $stestscript = "test_script.pl"; -my $itestpause = 3; +my $itestpause = 3; my $iteststatus = 4; my $procgroup = undef; -my $proctest = undef; +my $proctest = undef; -my $rscriptlog = undef; -my $rscripterror = undef; +my $rscriptlog = undef; +my $rscripterror = undef; my $iscriptstatus = -1; -my $itm = -1; +my $itm = -1; my $itmstrt = -1; -my $itmend = -1; -my $itmexe = -1; +my $itmend = -1; +my $itmexe = -1; -my $iprc = -1; +my $iprc = -1; my $iprccnt = -1; my $iprctmoutcnt = -1; - subtest 'Process::SubProcess::Group::Run' => sub { - $procgroup = Process::SubProcess::Group::->new; - - $itestpause = 2; + $procgroup = Process::SubProcess::Group::->new; - $proctest = Process::SubProcess::->new(('name' => 'test-script:2s' - , 'command' => $spath . $stestscript . ' ' . $itestpause)); + $itestpause = 2; - $procgroup->add($proctest); + $proctest = Process::SubProcess::->new( + ( + 'name' => 'test-script:2s', + 'command' => $spath . $stestscript . ' ' . $itestpause + ) + ); - $itestpause = 3; + $procgroup->add($proctest); - $proctest = Process::SubProcess::->new(('name' => 'test-script:3s' - , 'command' => $spath . $stestscript . ' ' . $itestpause)); + $itestpause = 3; - $procgroup->add($proctest); + $proctest = Process::SubProcess::->new( + ( + 'name' => 'test-script:3s', + 'command' => $spath . $stestscript . ' ' . $itestpause + ) + ); - $itestpause = 1; + $procgroup->add($proctest); - $proctest = Process::SubProcess::->new(('name' => 'test-script:1s' - , 'command' => $spath . $stestscript . ' ' . $itestpause)); + $itestpause = 1; - $procgroup->add($proctest); + $proctest = Process::SubProcess::->new( + ( + 'name' => 'test-script:1s', + 'command' => $spath . $stestscript . ' ' . $itestpause + ) + ); - $iprccnt = $procgroup->getProcessCount; + $procgroup->add($proctest); - is($iprccnt, 3, "scripts (count: '$iprccnt'): added correctly"); + $iprccnt = $procgroup->getProcessCount; + is( $iprccnt, 3, "scripts (count: '$iprccnt'): added correctly" ); - $itmstrt = gettimeofday(); + $itmstrt = gettimeofday(); - print "Process Group Execution Start - Time Now: '$itmstrt' s\n"; + print "Process Group Execution Start - Time Now: '$itmstrt' s\n"; - is($procgroup->Run, 1, "Process Group Execution: Execution correct"); + is( $procgroup->Run, 1, "Process Group Execution: Execution correct" ); - $itmend = gettimeofday(); + $itmend = gettimeofday(); - $itm = ($itmend - $itmstrt) * 1000; + $itm = ( $itmend - $itmstrt ) * 1000; - print "Process Group Execution End - Time Now: '$itmend' s\n"; + print "Process Group Execution End - Time Now: '$itmend' s\n"; - print "Process Group Execution finished in '$itm' ms\n"; + print "Process Group Execution finished in '$itm' ms\n"; - for($iprc = 0; $iprc < $iprccnt; $iprc++) - { - $proctest = $procgroup->getiProcess($iprc); + for ( $iprc = 0 ; $iprc < $iprccnt ; $iprc++ ) { + $proctest = $procgroup->getiProcess($iprc); - isnt($proctest, undef, "Process No. '$iprc': Listed correctly"); + isnt( $proctest, undef, "Process No. '$iprc': Listed correctly" ); - if(defined $proctest) - { - print("Process ", $proctest->getNameComplete, ":\n"); + if ( defined $proctest ) { + print( "Process ", $proctest->getNameComplete, ":\n" ); - $rscriptlog = $proctest->getReportString; - $rscripterror = $proctest->getErrorString; - $iscriptstatus = $proctest->getProcessStatus; + $rscriptlog = $proctest->getReportString; + $rscripterror = $proctest->getErrorString; + $iscriptstatus = $proctest->getProcessStatus; - print("ERROR CODE: '", $proctest->getErrorCode, "'\n"); - print("EXIT CODE: '$iscriptstatus'\n"); + print( "ERROR CODE: '", $proctest->getErrorCode, "'\n" ); + print("EXIT CODE: '$iscriptstatus'\n"); - if(defined $rscriptlog) - { - print("STDOUT: '$$rscriptlog'\n"); - } - else - { - isnt($rscriptlog, undef, "STDOUT was captured"); - } #if(defined $rscriptlog) + if ( defined $rscriptlog ) { + print("STDOUT: '$$rscriptlog'\n"); + } + else { + isnt( $rscriptlog, undef, "STDOUT was captured" ); + } #if(defined $rscriptlog) - if(defined $rscripterror) - { - print("STDERR: '$$rscripterror'\n"); - } - else - { - isnt($rscripterror, undef, "STDERR was captured"); - } #if(defined $rscripterror) - } #if(defined $proctest) - } #for($iprc = 0; $iprc < $iprccnt; $iprc++) + if ( defined $rscripterror ) { + print("STDERR: '$$rscripterror'\n"); + } + else { + isnt( $rscripterror, undef, "STDERR was captured" ); + } #if(defined $rscripterror) + } #if(defined $proctest) + } #for($iprc = 0; $iprc < $iprccnt; $iprc++) }; subtest 'Process::SubProcess::Group Profiling' => sub { - subtest 'Process::SubProcess::Group Profiling Verbose' => sub { + subtest 'Process::SubProcess::Group Profiling Verbose' => sub { - $procgroup = Process::SubProcess::Group::->new(('check' => 2)); + $procgroup = Process::SubProcess::Group::->new( ( 'check' => 2 ) ); - $itestpause = 3; + $itestpause = 3; - $proctest = Process::SubProcess::->new(('name' => 'test-script:3s' - , 'command' => $spath . $stestscript . ' ' . $itestpause - , 'profiling' => 1)); + $proctest = Process::SubProcess::->new( + ( + 'name' => 'test-script:3s', + 'command' => $spath . $stestscript . ' ' . $itestpause, + 'profiling' => 1 + ) + ); - is($proctest->isProfiling, 1, 'Profiling activated'); + is( $proctest->isProfiling, 1, 'Profiling activated' ); - $procgroup->add($proctest); + $procgroup->add($proctest); - $itestpause = 5; + $itestpause = 5; - $proctest = Process::SubProcess::->new(('name' => 'test-script:5s' - , 'command' => $spath . $stestscript . ' ' . $itestpause - , 'profiling' => 1)); + $proctest = Process::SubProcess::->new( + ( + 'name' => 'test-script:5s', + 'command' => $spath . $stestscript . ' ' . $itestpause, + 'profiling' => 1 + ) + ); - is($proctest->isProfiling, 1, 'Profiling activated'); + is( $proctest->isProfiling, 1, 'Profiling activated' ); - $procgroup->add($proctest); + $procgroup->add($proctest); - $itestpause = 9; + $itestpause = 9; - $proctest = Process::SubProcess::->new(('name' => 'test-script:9s' - , 'command' => $spath . $stestscript . ' ' . $itestpause - , 'profiling' => 1)); + $proctest = Process::SubProcess::->new( + ( + 'name' => 'test-script:9s', + 'command' => $spath . $stestscript . ' ' . $itestpause, + 'profiling' => 1 + ) + ); - is($proctest->isProfiling, 1, 'Profiling activated'); + is( $proctest->isProfiling, 1, 'Profiling activated' ); - $procgroup->add($proctest); + $procgroup->add($proctest); - $iprccnt = $procgroup->getProcessCount; + $iprccnt = $procgroup->getProcessCount; - is($iprccnt, 3, "scripts (count: '$iprccnt'): added correctly"); + is( $iprccnt, 3, "scripts (count: '$iprccnt'): added correctly" ); + $itmstrt = gettimeofday(); - $itmstrt = gettimeofday(); + print "Process Group Execution Start - Time Now: '$itmstrt' s\n"; - print "Process Group Execution Start - Time Now: '$itmstrt' s\n"; + is( $procgroup->Run, 1, "Process Group Execution: Execution correct" ); - is($procgroup->Run, 1, "Process Group Execution: Execution correct"); + $itmend = gettimeofday(); - $itmend = gettimeofday(); + $itm = ( $itmend - $itmstrt ) * 1000; - $itm = ($itmend - $itmstrt) * 1000; + print "Process Group Execution End - Time Now: '$itmend' s\n"; - print "Process Group Execution End - Time Now: '$itmend' s\n"; + print "Process Group Execution finished in '$itm' ms\n"; - print "Process Group Execution finished in '$itm' ms\n"; + for ( $iprc = 0 ; $iprc < $iprccnt ; $iprc++ ) { + $proctest = $procgroup->getiProcess($iprc); + isnt( $proctest, undef, "Process No. '$iprc': Listed correctly" ); - for($iprc = 0; $iprc < $iprccnt; $iprc++) - { - $proctest = $procgroup->getiProcess($iprc); + if ( defined $proctest ) { + print( "Process ", $proctest->getNameComplete, ":\n" ); - isnt($proctest, undef, "Process No. '$iprc': Listed correctly"); + $rscriptlog = $proctest->getReportString; + $rscripterror = $proctest->getErrorString; + $iscriptstatus = $proctest->getProcessStatus; - if(defined $proctest) - { - print("Process ", $proctest->getNameComplete, ":\n"); + isnt( $proctest->getExecutionTime, + -1, "Execution Time was measured" ); - $rscriptlog = $proctest->getReportString; - $rscripterror = $proctest->getErrorString; - $iscriptstatus = $proctest->getProcessStatus; + print( "Read Timeout: '", $proctest->getReadTimeout, "'\n" ); + print( "Execution Time: '", $proctest->getExecutionTime, + "'\n" ); - isnt($proctest->getExecutionTime, -1 , "Execution Time was measured"); + print("EXIT CODE: '$iscriptstatus'\n"); - print("Read Timeout: '", $proctest->getReadTimeout, "'\n"); - print("Execution Time: '", $proctest->getExecutionTime, "'\n"); + if ( defined $rscriptlog ) { + print("STDOUT: '$$rscriptlog'\n"); + } + else { + isnt( $rscriptlog, undef, "STDOUT was captured" ); + } #if(defined $rscriptlog) - print("EXIT CODE: '$iscriptstatus'\n"); + if ( defined $rscripterror ) { + print("STDERR: '$$rscripterror'\n"); + } + else { + isnt( $rscripterror, undef, "STDERR was captured" ); + } #if(defined $rscripterror) + } #if(defined $proctest) + } #for($iprc = 0; $iprc < $iprccnt; $iprc++) + }; + subtest 'Process::SubProcess::Group Profiling Quiet' => sub { - if(defined $rscriptlog) - { - print("STDOUT: '$$rscriptlog'\n"); - } - else - { - isnt($rscriptlog, undef, "STDOUT was captured"); - } #if(defined $rscriptlog) + my $itesttime = -1; - if(defined $rscripterror) - { - print("STDERR: '$$rscripterror'\n"); - } - else - { - isnt($rscripterror, undef, "STDERR was captured"); - } #if(defined $rscripterror) - } #if(defined $proctest) - } #for($iprc = 0; $iprc < $iprccnt; $iprc++) - }; - subtest 'Process::SubProcess::Group Profiling Quiet' => sub { + $procgroup = Process::SubProcess::Group::->new( ( 'check' => 2 ) ); - my $itesttime = -1; + $stestscript = 'quiet_script.pl'; + $itestpause = 3; - $procgroup = Process::SubProcess::Group::->new(('check' => 2)); + $proctest = Process::SubProcess::->new( + ( + 'name' => 'quiet-script:3s', + 'command' => $spath . $stestscript . ' ' . $itestpause, + 'profiling' => 1 + ) + ); - $stestscript = 'quiet_script.pl'; - $itestpause = 3; + is( $proctest->isProfiling, 1, 'Profiling activated' ); - $proctest = Process::SubProcess::->new(('name' => 'quiet-script:3s' - , 'command' => $spath . $stestscript . ' ' . $itestpause - , 'profiling' => 1)); + $procgroup->add($proctest); - is($proctest->isProfiling, 1, 'Profiling activated'); + $itestpause = 5; - $procgroup->add($proctest); + $proctest = Process::SubProcess::->new( + ( + 'name' => 'quiet-script:5s', + 'command' => $spath . $stestscript . ' ' . $itestpause, + 'profiling' => 1 + ) + ); - $itestpause = 5; + is( $proctest->isProfiling, 1, 'Profiling activated' ); - $proctest = Process::SubProcess::->new(('name' => 'quiet-script:5s' - , 'command' => $spath . $stestscript . ' ' . $itestpause - , 'profiling' => 1)); + $procgroup->add($proctest); - is($proctest->isProfiling, 1, 'Profiling activated'); + $itestpause = 9; - $procgroup->add($proctest); + $proctest = Process::SubProcess::->new( + ( + 'name' => 'quiet-script:9s', + 'command' => $spath . $stestscript . ' ' . $itestpause, + 'profiling' => 1 + ) + ); - $itestpause = 9; + is( $proctest->isProfiling, 1, 'Profiling activated' ); - $proctest = Process::SubProcess::->new(('name' => 'quiet-script:9s' - , 'command' => $spath . $stestscript . ' ' . $itestpause - , 'profiling' => 1)); + $procgroup->add($proctest); - is($proctest->isProfiling, 1, 'Profiling activated'); + $iprccnt = $procgroup->getProcessCount; - $procgroup->add($proctest); + is( $iprccnt, 3, "scripts (count: '$iprccnt'): added correctly" ); - $iprccnt = $procgroup->getProcessCount; + $procgroup->setCheckInterval(6); - is($iprccnt, 3, "scripts (count: '$iprccnt'): added correctly"); + isnt( $procgroup->getCheckInterval, -1, "Read Timeout activated" ); - $procgroup->setCheckInterval(6); + $itmstrt = gettimeofday(); - isnt($procgroup->getCheckInterval, -1, "Read Timeout activated"); + print "Process Group Execution Start - Time Now: '$itmstrt' s\n"; + is( $procgroup->Run, 1, "Process Group Execution: Execution correct" ); - $itmstrt = gettimeofday(); + $itmend = gettimeofday(); - print "Process Group Execution Start - Time Now: '$itmstrt' s\n"; + $itm = ( $itmend - $itmstrt ) * 1000; - is($procgroup->Run, 1, "Process Group Execution: Execution correct"); + print "Process Group Execution End - Time Now: '$itmend' s\n"; - $itmend = gettimeofday(); + print "Process Group Execution finished in '$itm' ms\n"; - $itm = ($itmend - $itmstrt) * 1000; + for ( $iprc = 0 ; $iprc < $iprccnt ; $iprc++ ) { + $proctest = $procgroup->getiProcess($iprc); - print "Process Group Execution End - Time Now: '$itmend' s\n"; + isnt( $proctest, undef, "Process No. '$iprc': Listed correctly" ); - print "Process Group Execution finished in '$itm' ms\n"; + if ( defined $proctest ) { + print( + "Process ", + $proctest->getNameComplete, + " finished with [" . $proctest->getErrorCode . "]:\n" + ); + $rscriptlog = $proctest->getReportString; + $rscripterror = $proctest->getErrorString; + $iscriptstatus = $proctest->getProcessStatus; - for($iprc = 0; $iprc < $iprccnt; $iprc++) - { - $proctest = $procgroup->getiProcess($iprc); + isnt( $proctest->getExecutionTime, + -1, "Execution Time was measured" ); - isnt($proctest, undef, "Process No. '$iprc': Listed correctly"); + print( "Read Timeout: '", $proctest->getReadTimeout, "'\n" ); + print( "Execution Time: '", $proctest->getExecutionTime, + "'\n" ); - if(defined $proctest) - { - print("Process ", $proctest->getNameComplete, " finished with [" . $proctest->getErrorCode . "]:\n"); + print( "ERROR CODE: '", $proctest->getErrorCode, "'\n" ); + print("EXIT CODE: '$iscriptstatus'\n"); - $rscriptlog = $proctest->getReportString; - $rscripterror = $proctest->getErrorString; - $iscriptstatus = $proctest->getProcessStatus; + if ( defined $rscriptlog ) { + print("STDOUT: '$$rscriptlog'\n"); + } + else { + isnt( $rscriptlog, undef, "STDOUT was captured" ); + } #if(defined $rscriptlog) - isnt($proctest->getExecutionTime, -1 , "Execution Time was measured"); - - print("Read Timeout: '", $proctest->getReadTimeout, "'\n"); - print("Execution Time: '", $proctest->getExecutionTime, "'\n"); - - print("ERROR CODE: '", $proctest->getErrorCode, "'\n"); - print("EXIT CODE: '$iscriptstatus'\n"); - - if(defined $rscriptlog) - { - print("STDOUT: '$$rscriptlog'\n"); - } - else - { - isnt($rscriptlog, undef, "STDOUT was captured"); - } #if(defined $rscriptlog) - - if(defined $rscripterror) - { - print("STDERR: '$$rscripterror'\n"); - } - else - { - isnt($rscripterror, undef, "STDERR was captured"); - } #if(defined $rscripterror) - } #if(defined $proctest) - } #for($iprc = 0; $iprc < $iprccnt; $iprc++) - }; + if ( defined $rscripterror ) { + print("STDERR: '$$rscripterror'\n"); + } + else { + isnt( $rscripterror, undef, "STDERR was captured" ); + } #if(defined $rscripterror) + } #if(defined $proctest) + } #for($iprc = 0; $iprc < $iprccnt; $iprc++) + }; }; subtest 'Process::SubProcess::Group Runtime Checks' => sub { - subtest 'Process::SubProcess::Group Execution Timeout' => sub { + subtest 'Process::SubProcess::Group Execution Timeout' => sub { - $iprctmoutcnt = -1; + $iprctmoutcnt = -1; - $procgroup = Process::SubProcess::Group::->new(('timeout' => 7)); + $procgroup = + Process::SubProcess::Group::->new( ( 'timeout' => 7, 'debug' => 1 ) ); - $stestscript = "test_script.pl"; - $itestpause = 3; + $stestscript = "test_script.pl"; + $itestpause = 3; - $proctest = Process::SubProcess::->new(('name' => 'test-script:3s' - , 'command' => $spath . $stestscript . ' ' . $itestpause - , 'profiling' => 1)); + $proctest = Process::SubProcess::->new( + ( + 'name' => 'test-script:3s', + 'command' => $spath . $stestscript . ' ' . $itestpause, + 'profiling' => 1 + ) + ); - is($proctest->isProfiling, 1, 'Profiling activated'); + is( $proctest->isProfiling, 1, 'Profiling activated' ); - $procgroup->add($proctest); + $procgroup->add($proctest); - $itestpause = 5; + $itestpause = 5; - $proctest = Process::SubProcess::->new(('name' => 'test-script:5s' - , 'command' => $spath . $stestscript . ' ' . $itestpause - , 'profiling' => 1)); + $proctest = Process::SubProcess::->new( + ( + 'name' => 'test-script:5s', + 'command' => $spath . $stestscript . ' ' . $itestpause, + 'profiling' => 1 + ) + ); - is($proctest->isProfiling, 1, 'Profiling activated'); + is( $proctest->isProfiling, 1, 'Profiling activated' ); - $procgroup->add($proctest); + $procgroup->add($proctest); - $itestpause = 13; + $itestpause = 15; - $proctest = Process::SubProcess::->new(('name' => 'test-script:13s' - , 'command' => $spath . $stestscript . ' ' . $itestpause - , 'profiling' => 1)); + $proctest = Process::SubProcess::->new( + ( + 'name' => 'test-script:15s', + 'command' => $spath . $stestscript . ' ' . $itestpause, + 'profiling' => 1 + ) + ); - is($proctest->isProfiling, 1, 'Profiling activated'); + is( $proctest->isProfiling, 1, 'Profiling activated' ); - $procgroup->add($proctest); + $procgroup->add($proctest); - $iprccnt = $procgroup->getProcessCount; + $iprccnt = $procgroup->getProcessCount; - is($iprccnt, 3, "scripts (count: '$iprccnt'): added correctly"); + is( $iprccnt, 3, "scripts (count: '$iprccnt'): added correctly" ); - $procgroup->setCheckInterval(6); + $procgroup->setCheckInterval(6); - isnt($procgroup->getCheckInterval, -1, "Check Interval activated"); - isnt($procgroup->getTimeout, -1, "Execution Timeout activated"); + isnt( $procgroup->getCheckInterval, -1, "Check Interval activated" ); + isnt( $procgroup->getTimeout, -1, "Execution Timeout activated" ); + $itmstrt = gettimeofday(); - $itmstrt = gettimeofday(); + print "Process Group Execution Start - Time Now: '$itmstrt' s\n"; - print "Process Group Execution Start - Time Now: '$itmstrt' s\n"; + is( $procgroup->Run, 0, + "Process Group Execution: Execution failed as expected" ); - is($procgroup->Run, 0, "Process Group Execution: Execution failed as expected"); + $itmend = gettimeofday(); - $itmend = gettimeofday(); + $itm = ( $itmend - $itmstrt ) * 1000; - $itm = ($itmend - $itmstrt) * 1000; + print "Process Group Execution End - Time Now: '$itmend' s\n"; - print "Process Group Execution End - Time Now: '$itmend' s\n"; + print "Process Group Execution finished in '$itm' ms\n"; - print "Process Group Execution finished in '$itm' ms\n"; + print( + "Process Group ERROR CODE: '" . $procgroup->getErrorCode . "'\n" ); - print("Process Group ERROR CODE: '" . $procgroup->getErrorCode . "'\n"); + is( $procgroup->getErrorCode, 4, + "Process Group Execution: ERROR CODE '4' is correct" ); - is($procgroup->getErrorCode, 4, "Process Group Execution: ERROR CODE is correct"); + print( "Process Group STDOUT: '" + . ${ $procgroup->getReportString } + . "'\n" ); + print( "Process Group STDERR: '" + . ${ $procgroup->getErrorString } + . "'\n" ); - print("Process Group STDOUT: '" . ${$procgroup->getReportString} . "'\n"); - print("Process Group STDERR: '" . ${$procgroup->getErrorString} . "'\n"); + $iprctmoutcnt = 0 if ( $procgroup->getErrorCode == 4 ); - $iprctmoutcnt = 0 if($procgroup->getErrorCode == 4); + for ( $iprc = 0 ; $iprc < $iprccnt ; $iprc++ ) { + $proctest = $procgroup->getiProcess($iprc); - for($iprc = 0; $iprc < $iprccnt; $iprc++) - { - $proctest = $procgroup->getiProcess($iprc); + isnt( $proctest, undef, "Process No. '$iprc': Listed correctly" ); - isnt($proctest, undef, "Process No. '$iprc': Listed correctly"); + if ( defined $proctest ) { + print( + "Process ", + $proctest->getNameComplete, + " finished with [" . $proctest->getErrorCode . "]:\n" + ); - if(defined $proctest) - { - print("Process ", $proctest->getNameComplete, " finished with [" . $proctest->getErrorCode . "]:\n"); + $rscriptlog = $proctest->getReportString; + $rscripterror = $proctest->getErrorString; + $iscriptstatus = $proctest->getProcessStatus; - $rscriptlog = $proctest->getReportString; - $rscripterror = $proctest->getErrorString; - $iscriptstatus = $proctest->getProcessStatus; + print( "ERROR CODE: '", $proctest->getErrorCode, "'\n" ); + print("EXIT CODE: '$iscriptstatus'\n"); - print("ERROR CODE: '", $proctest->getErrorCode, "'\n"); - print("EXIT CODE: '$iscriptstatus'\n"); + if ( $proctest->getErrorCode == 4 ) { + $iprctmoutcnt++; - if($proctest->getErrorCode == 4) - { - $iprctmoutcnt++ ; + is( $proctest->getExecutionTime, + -1, "Execution Time not measured as expected" ); + } + else #Timeout Error + { + isnt( $proctest->getExecutionTime, + -1, "Execution Time was measured" ); + } #if($proctest->getErrorCode == 4) - is($proctest->getExecutionTime, -1, "Execution Time not measured as expected"); - } - else #Timeout Error - { - isnt($proctest->getExecutionTime, -1, "Execution Time was measured"); - } #if($proctest->getErrorCode == 4) + print( "Read Timeout: '", $proctest->getReadTimeout, "'\n" ); + print( "Execution Time: '", $proctest->getExecutionTime, + "'\n" ); - print("Read Timeout: '", $proctest->getReadTimeout, "'\n"); - print("Execution Time: '", $proctest->getExecutionTime, "'\n"); + if ( defined $rscriptlog ) { + print("STDOUT: '$$rscriptlog'\n"); + } + else { + isnt( $rscriptlog, undef, "STDOUT was captured" ); + } #if(defined $rscriptlog) - if(defined $rscriptlog) - { - print("STDOUT: '$$rscriptlog'\n"); - } - else - { - isnt($rscriptlog, undef, "STDOUT was captured"); - } #if(defined $rscriptlog) + if ( defined $rscripterror ) { + print("STDERR: '$$rscripterror'\n"); + } + else { + isnt( $rscripterror, undef, "STDERR was captured" ); + } #if(defined $rscripterror) + } #if(defined $proctest) + } #for($iprc = 0; $iprc < $iprccnt; $iprc++) - if(defined $rscripterror) - { - print("STDERR: '$$rscripterror'\n"); - } - else - { - isnt($rscripterror, undef, "STDERR was captured"); - } #if(defined $rscripterror) - } #if(defined $proctest) - } #for($iprc = 0; $iprc < $iprccnt; $iprc++) + is( $iprctmoutcnt, 1, "'1' Process timed out as expected" ); - is($iprctmoutcnt, 1, "'1' Process timed out as expected"); + print("Process Group Execution Timeout - Count: '$iprctmoutcnt'\n"); + }; + subtest 'Process::SubProcess::Group::Wait() Method' => sub { - print("Process Group Execution Timeout - Count: '$iprctmoutcnt'\n"); - }; - subtest 'Process::SubProcess::Group::Wait() Method' => sub { + $iprctmoutcnt = -1; - $iprctmoutcnt = -1; + $procgroup = Process::SubProcess::Group::->new( ( 'timeout' => 7 ) ); - $procgroup = Process::SubProcess::Group::->new(('timeout' => 7)); + $stestscript = "test_script.pl"; + $itestpause = 3; - $stestscript = "test_script.pl"; - $itestpause = 3; + $proctest = Process::SubProcess::->new( + ( + 'name' => 'test-script:3s', + 'command' => $spath . $stestscript . ' ' . $itestpause, + 'profiling' => 1 + ) + ); - $proctest = Process::SubProcess::->new(('name' => 'test-script:3s' - , 'command' => $spath . $stestscript . ' ' . $itestpause - , 'profiling' => 1)); + is( $proctest->isProfiling, 1, 'Profiling activated' ); - is($proctest->isProfiling, 1, 'Profiling activated'); + $procgroup->add($proctest); - $procgroup->add($proctest); + $itestpause = 5; - $itestpause = 5; + $proctest = Process::SubProcess::->new( + ( + 'name' => 'test-script:5s', + 'command' => $spath . $stestscript . ' ' . $itestpause, + 'profiling' => 1 + ) + ); - $proctest = Process::SubProcess::->new(('name' => 'test-script:5s' - , 'command' => $spath . $stestscript . ' ' . $itestpause - , 'profiling' => 1)); + is( $proctest->isProfiling, 1, 'Profiling activated' ); - is($proctest->isProfiling, 1, 'Profiling activated'); + $procgroup->add($proctest); - $procgroup->add($proctest); + $itestpause = 13; - $itestpause = 13; + $proctest = Process::SubProcess::->new( + ( + 'name' => 'test-script:13s', + 'command' => $spath . $stestscript . ' ' . $itestpause, + 'profiling' => 1 + ) + ); - $proctest = Process::SubProcess::->new(('name' => 'test-script:13s' - , 'command' => $spath . $stestscript . ' ' . $itestpause - , 'profiling' => 1)); + is( $proctest->isProfiling, 1, 'Profiling activated' ); - is($proctest->isProfiling, 1, 'Profiling activated'); + $procgroup->add($proctest); - $procgroup->add($proctest); + $iprccnt = $procgroup->getProcessCount; - $iprccnt = $procgroup->getProcessCount; + is( $iprccnt, 3, "scripts (count: '$iprccnt'): added correctly" ); - is($iprccnt, 3, "scripts (count: '$iprccnt'): added correctly"); + $procgroup->setCheckInterval(6); - $procgroup->setCheckInterval(6); + isnt( $procgroup->getCheckInterval, -1, "Check Interval activated" ); + isnt( $procgroup->getTimeout, -1, "Execution Timeout activated" ); - isnt($procgroup->getCheckInterval, -1, "Check Interval activated"); - isnt($procgroup->getTimeout, -1, "Execution Timeout activated"); + $itmstrt = gettimeofday(); + print "Process Group Execution Start - Time Now: '$itmstrt' s\n"; - $itmstrt = gettimeofday(); + for ( $iprc = 0 ; $iprc < $iprccnt ; $iprc++ ) { + $proctest = $procgroup->getiProcess($iprc); - print "Process Group Execution Start - Time Now: '$itmstrt' s\n"; + isnt( $proctest, undef, "Process No. '$iprc': Listed correctly" ); - for($iprc = 0; $iprc < $iprccnt; $iprc++) - { - $proctest = $procgroup->getiProcess($iprc); + if ( defined $proctest ) { + is( $proctest->Launch, 1, + "Process No. '$iprc': Launch succeeded" ); + } #if(defined $proctest) + } #for($iprc = 0; $iprc < $iprccnt; $iprc++) - isnt($proctest, undef, "Process No. '$iprc': Listed correctly"); + is( $procgroup->getRunningCount, + 3, "Process Group Execution: All Processes are launched" ); - if(defined $proctest) - { - is($proctest->Launch, 1, "Process No. '$iprc': Launch succeeded"); - } #if(defined $proctest) - } #for($iprc = 0; $iprc < $iprccnt; $iprc++) + is( $procgroup->Wait(), 0, + "Process Group Execution: Execution failed as expected" ); - is($procgroup->getRunningCount, 3, "Process Group Execution: All Processes are launched"); + $itmend = gettimeofday(); - is($procgroup->Wait(), 0, "Process Group Execution: Execution failed as expected"); + $itm = ( $itmend - $itmstrt ) * 1000; - $itmend = gettimeofday(); + print "Process Group Execution End - Time Now: '$itmend' s\n"; - $itm = ($itmend - $itmstrt) * 1000; + print "Process Group Execution finished in '$itm' ms\n"; - print "Process Group Execution End - Time Now: '$itmend' s\n"; + print( + "Process Group ERROR CODE: '" . $procgroup->getErrorCode . "'\n" ); - print "Process Group Execution finished in '$itm' ms\n"; + is( $procgroup->getErrorCode, 4, + "Process Group Execution: ERROR CODE is correct" ); - print("Process Group ERROR CODE: '" . $procgroup->getErrorCode . "'\n"); + print( "Process Group STDOUT: '" + . ${ $procgroup->getReportString } + . "'\n" ); + print( "Process Group STDERR: '" + . ${ $procgroup->getErrorString } + . "'\n" ); - is($procgroup->getErrorCode, 4, "Process Group Execution: ERROR CODE is correct"); + $iprctmoutcnt = 0 if ( $procgroup->getErrorCode == 4 ); - print("Process Group STDOUT: '" . ${$procgroup->getReportString} . "'\n"); - print("Process Group STDERR: '" . ${$procgroup->getErrorString} . "'\n"); + for ( $iprc = 0 ; $iprc < $iprccnt ; $iprc++ ) { + $proctest = $procgroup->getiProcess($iprc); - $iprctmoutcnt = 0 if($procgroup->getErrorCode == 4); + isnt( $proctest, undef, "Process No. '$iprc': Listed correctly" ); - for($iprc = 0; $iprc < $iprccnt; $iprc++) - { - $proctest = $procgroup->getiProcess($iprc); + if ( defined $proctest ) { + print( + "Process ", + $proctest->getNameComplete, + " finished with [" . $proctest->getErrorCode . "]:\n" + ); - isnt($proctest, undef, "Process No. '$iprc': Listed correctly"); + $rscriptlog = $proctest->getReportString; + $rscripterror = $proctest->getErrorString; + $iscriptstatus = $proctest->getProcessStatus; - if(defined $proctest) - { - print("Process ", $proctest->getNameComplete, " finished with [" . $proctest->getErrorCode . "]:\n"); + print( "ERROR CODE: '", $proctest->getErrorCode, "'\n" ); + print("EXIT CODE: '$iscriptstatus'\n"); - $rscriptlog = $proctest->getReportString; - $rscripterror = $proctest->getErrorString; - $iscriptstatus = $proctest->getProcessStatus; + if ( $proctest->getErrorCode == 4 ) { + $iprctmoutcnt++; - print("ERROR CODE: '", $proctest->getErrorCode, "'\n"); - print("EXIT CODE: '$iscriptstatus'\n"); + is( $proctest->getExecutionTime, + -1, "Execution Time not measured as expected" ); + } + else #Timeout Error + { + isnt( $proctest->getExecutionTime, + -1, "Execution Time was measured" ); + } #if($proctest->getErrorCode == 4) - if($proctest->getErrorCode == 4) - { - $iprctmoutcnt++ ; + print( "Read Timeout: '", $proctest->getReadTimeout, "'\n" ); + print( "Execution Time: '", $proctest->getExecutionTime, + "'\n" ); - is($proctest->getExecutionTime, -1, "Execution Time not measured as expected"); - } - else #Timeout Error - { - isnt($proctest->getExecutionTime, -1, "Execution Time was measured"); - } #if($proctest->getErrorCode == 4) + if ( defined $rscriptlog ) { + print("STDOUT: '$$rscriptlog'\n"); + } + else { + isnt( $rscriptlog, undef, "STDOUT was captured" ); + } #if(defined $rscriptlog) - print("Read Timeout: '", $proctest->getReadTimeout, "'\n"); - print("Execution Time: '", $proctest->getExecutionTime, "'\n"); + if ( defined $rscripterror ) { + print("STDERR: '$$rscripterror'\n"); + } + else { + isnt( $rscripterror, undef, "STDERR was captured" ); + } #if(defined $rscripterror) + } #if(defined $proctest) + } #for($iprc = 0; $iprc < $iprccnt; $iprc++) - if(defined $rscriptlog) - { - print("STDOUT: '$$rscriptlog'\n"); - } - else - { - isnt($rscriptlog, undef, "STDOUT was captured"); - } #if(defined $rscriptlog) + is( $iprctmoutcnt, 1, "'1' Process timed out as expected" ); - if(defined $rscripterror) - { - print("STDERR: '$$rscripterror'\n"); - } - else - { - isnt($rscripterror, undef, "STDERR was captured"); - } #if(defined $rscripterror) - } #if(defined $proctest) - } #for($iprc = 0; $iprc < $iprccnt; $iprc++) - - is($iprctmoutcnt, 1, "'1' Process timed out as expected"); - - print("Process Group Execution Timeout - Count: '$iprctmoutcnt'\n"); - }; + print("Process Group Execution Timeout - Count: '$iprctmoutcnt'\n"); + }; }; - done_testing(); diff --git a/t/test_runner.t b/t/test_runner.t index a8fa382..c5bf512 100755 --- a/t/test_runner.t +++ b/t/test_runner.t @@ -462,7 +462,7 @@ subtest 'Runner Exit Code' => sub { } #if(defined $rscripterror) }; subtest 'Runner returns Error Code' => sub { - $itestpause = 4; + $itestpause = 10; $srunnerresult = `$Config{perlpath} ${spath}${srunnerscript} -n "script - times out" -c "${spath}${stestscript} $itestpause" -t 1 -x`; From 5e392c3f617c78926b7766a4aefdfed43957e3f7 Mon Sep 17 00:00:00 2001 From: Bodo Hugo Barwich Date: Sun, 31 Dec 2023 08:18:39 +0300 Subject: [PATCH 2/3] check exit code in group test --- t/test_group.t | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/t/test_group.t b/t/test_group.t index 838fddb..083925c 100755 --- a/t/test_group.t +++ b/t/test_group.t @@ -444,7 +444,7 @@ subtest 'Process::SubProcess::Group Runtime Checks' => sub { "Process Group ERROR CODE: '" . $procgroup->getErrorCode . "'\n" ); is( $procgroup->getErrorCode, 4, - "Process Group Execution: ERROR CODE '4' is correct" ); + "Process Group Execution: ERROR CODE '4' as expected" ); print( "Process Group STDOUT: '" . ${ $procgroup->getReportString } @@ -477,11 +477,14 @@ subtest 'Process::SubProcess::Group Runtime Checks' => sub { if ( $proctest->getErrorCode == 4 ) { $iprctmoutcnt++; + is( $iscriptstatus, -1, + "Exit Code not captured as expected" ); is( $proctest->getExecutionTime, -1, "Execution Time not measured as expected" ); } - else #Timeout Error + else # Process finished normally { + isnt( $iscriptstatus, -1, "Exit Code was captured" ); isnt( $proctest->getExecutionTime, -1, "Execution Time was measured" ); } #if($proctest->getErrorCode == 4) @@ -490,19 +493,14 @@ subtest 'Process::SubProcess::Group Runtime Checks' => sub { print( "Execution Time: '", $proctest->getExecutionTime, "'\n" ); - if ( defined $rscriptlog ) { - print("STDOUT: '$$rscriptlog'\n"); - } - else { - isnt( $rscriptlog, undef, "STDOUT was captured" ); - } #if(defined $rscriptlog) + isnt( $rscriptlog, undef, "STDOUT was captured" ); - if ( defined $rscripterror ) { - print("STDERR: '$$rscripterror'\n"); - } - else { - isnt( $rscripterror, undef, "STDERR was captured" ); - } #if(defined $rscripterror) + print("STDOUT: '$$rscriptlog'\n") if ( defined $rscriptlog ); + + isnt( $rscripterror, undef, "STDERR was captured" ); + + print("STDERR: '$$rscripterror'\n") + if ( defined $rscripterror ); } #if(defined $proctest) } #for($iprc = 0; $iprc < $iprccnt; $iprc++) From bd8097a256cf3930b7c355a1fc7cbfc9a4e0901a Mon Sep 17 00:00:00 2001 From: Bodo Hugo Barwich Date: Sun, 31 Dec 2023 09:31:00 +0300 Subject: [PATCH 3/3] document Wait() method parameters --- lib/Process/SubProcess.pm | 32 +++++++++++++++++++++++++++----- lib/Process/SubProcess/Group.pm | 2 +- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/lib/Process/SubProcess.pm b/lib/Process/SubProcess.pm index 988a475..fc2051a 100644 --- a/lib/Process/SubProcess.pm +++ b/lib/Process/SubProcess.pm @@ -1091,16 +1091,27 @@ sub Read { =over 4 -=item Wait () +=item Wait ( [ CONFIGURATIONS ] ) This method calls the C method continuously for a started process which was started with the C method until the C method tells that the process is finished. -If a C is set through the C method the B will -terminate the process after the C is fulfilled. +If a C is set the B will terminate the process with +the C method after the C is fulfilled. When a process times out an B of C< 4 > will be set. +B + +C - is a list are passed in a hash like fashion, using key and value pairs. + +B + +C - is an integer that specifies the interval in which all processes should +be checked once. + +C - is an integer that specifies the maximal execution time in seconds. + B It returns C< 1 > when the process has finished correctly. It returns C< 0 > when the process had to be terminated. @@ -1197,17 +1208,28 @@ sub Wait { =over 4 -=item Run () +=item Run ( [ CONFIGURATIONS ] ) This method starts the process calling the C method and then calls the C method to wait until the process is finished. +B + +C - is a list are passed in a hash like fashion, using key and value pairs. + +B + +C - is an integer that specifies the interval in which all processes should +be checked once. + +C - is an integer that specifies the maximal execution time in seconds. + B It returns C< 1 > when the process was started and finished correctly. It returns C< 0 > when the process could not be started or had to be terminated. See L|/"Launch ()"> -See L|/"Wait ()"> +See L|/"Wait ( [ CONFIGURATIONS ] )"> =back diff --git a/lib/Process/SubProcess/Group.pm b/lib/Process/SubProcess/Group.pm index a7fc264..a0c6210 100644 --- a/lib/Process/SubProcess/Group.pm +++ b/lib/Process/SubProcess/Group.pm @@ -710,7 +710,7 @@ be checked once. C - is an integer that specifies the time in seconds to wait for output from the command for each C object. -C - is an integer that specifies the maximal execution time in seconds +C - is an integer that specifies the maximal execution time in seconds of the whole B execution. See L|Process::SubProcess/"Terminate ()">