diff --git a/lib/Test/Class/Moose/Executor/Parallel.pm b/lib/Test/Class/Moose/Executor/Parallel.pm index b5c5fce..61ef902 100755 --- a/lib/Test/Class/Moose/Executor/Parallel.pm +++ b/lib/Test/Class/Moose/Executor/Parallel.pm @@ -96,8 +96,9 @@ sub _test_class_is_parallelizable { $_, 'noparallel' ); - } - $self->_test_methods_for($test_class); + } + + $self->_test_methods_for($test_class); } sub _run_test_classes_in_parallel { @@ -116,6 +117,8 @@ sub _run_test_classes_in_parallel { } # This chunk of code only runs in child processes + my $child_pid = $$; + my $class_report; $subtest->attach($id); $subtest->run( @@ -123,8 +126,19 @@ sub _run_test_classes_in_parallel { $class_report = $self->run_test_class($test_class); } ); - $subtest->detach; - $self->_fork_manager->finish( 0, \$class_report ); + + # if the test class also creates forks, and one of those forks dies, + # the dead child ends up running here, and causes subsequent problems + # with Test2::AsyncSubtest::detach, and can potentially cascade into + # all kinds of other problems during global destruction. i have no + # idea how a grandchild death can end up running this code... + if ( $$ == $child_pid ) { + $subtest->detach; + $self->_fork_manager->finish( 0, \$class_report ); + } + else { + warn "Ignoring unknown child pid $$, did a grandchild pid die?"; + } } $self->_fork_manager->wait_all_children;