[Melbourne-pm] Testing fork

David Dick david_dick at iprimus.com.au
Fri Nov 12 16:13:59 CST 2004

ok, following on from previous attempts, this sort of works.  Basically 
so long as BSD::Resource is supported on the platform ( 
http://testers.cpan.org/show/BSD-Resource.html#BSD-Resource-1.24 )
at least the EAGAIN stuff will be tested (hopefully?).  Of course, this 
test might actually limit the portability of the code base too.

Another interesting point was the use of $test->no_ending(1) to stop the 
two processes (if they accidentally got created) from both outputing 
their opinion on the final result and hence stuffing up the output.

I don't even want to get started on the horrific possibilities created 
by now needing to do coverage analysis on the test suite. :)

However i think this is a case where this sort of test is required, as 
distinct from Leif's excellent example of overriding functions, simply 
because of the difficulty in knowing exactly what the OS will return in 
this case.

         use BSD::Resource();
         use POSIX();
         ok(BSD::Resource::setrlimit(BSD::Resource::RLIMIT_NPROC(), 1, 
1), "Can set the number of allowed children to 1");
         my ($success) = 0;
         my ($pid);
         if ($pid = fork()) {
                 waitpid($pid, 0); # Should never get here either.
         } elsif (defined $pid) {
                 my ($test) = Test::Builder->new();
                 exit(1); # Just a Guarantee. Should never get here
         } elsif ($! == POSIX::EAGAIN()) {
                 $success = 1;
         ok($success == 1, "Successfully received an EAGAIN");

Hopefully this was interesting. :)

More information about the Melbourne-pm mailing list