1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#!/usr/bin/perl
# Ensure that we don't prematurely END-time delete due to forking
use strict;
use warnings;
use Test::More tests => 8;
use File::Spec::Functions ':ALL';
use File::Remove ();
# Create a directory
my $parent = catdir( 't', '09_fork_parent' );
my $child = catdir( 't', '09_fork_child' );
File::Remove::clear($parent);
File::Remove::remove($child);
# TEST
ok( !-d $parent, 'Parent directory does not exist' );
# TEST
ok( !-d $child, 'Child directory does not exist' );
# TEST
ok( mkdir( $parent, 0777 ), 'Created directory' );
# TEST
ok( -d $parent, 'Directory exists' );
# Fork the test
my $pid = fork();
unless ($pid)
{
# Create a child-owned directory and flag for deletion
File::Remove::clear($child);
mkdir( $child, 0777 );
sleep(2);
# Exit from the child to stimulate END-time code
exit(0);
}
# In the parent, wait 1 second for process to spawn
# and create the child directory
sleep(1);
# TEST
ok( -d $child, 'Child directory created (by forked child)' );
# Wait for the child to exit
my $caught = wait();
# TEST
is( $pid, $caught, 'The child exited' );
sleep(1); # Give a chance for flakey windows to delete directory
# TEST
ok( -d $parent, 'Parent directory still exists' );
# TEST
ok( !-d $child, 'Child directory is removed' );
|