From 1c27c4352e5a100987c22260539f2e7fbc6fa6ea Mon Sep 17 00:00:00 2001 From: Clemens Famulla-Conrad Date: Mon, 13 Dec 2021 10:24:46 +0100 Subject: [PATCH 1/3] Avoid SIGNAL on IO error in 02_parallel.t and add test for it --- t/02_parallel.t | 2 +- t/14_sig_on_io.t | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 t/14_sig_on_io.t diff --git a/t/02_parallel.t b/t/02_parallel.t index 6f3c52c..e845243 100644 --- a/t/02_parallel.t +++ b/t/02_parallel.t @@ -71,8 +71,8 @@ subtest batch => sub { set_pipes => 1 ); $c->start(); - is $c->last->getline, "Hello world 3\n"; $c->wait_stop(); + is $c->last->getline, "Hello world 3\n"; my $result; $c->add(code => sub { return 40 + 2 }, separate_err => 0, set_pipes => 0); diff --git a/t/14_sig_on_io.t b/t/14_sig_on_io.t new file mode 100644 index 0000000..7ce2dd0 --- /dev/null +++ b/t/14_sig_on_io.t @@ -0,0 +1,28 @@ +#!/usr/bin/perl + +use Mojo::Base -strict; +use Test::More; +use Time::HiRes qw(sleep); +use FindBin; +use lib ("$FindBin::Bin/lib", "../lib", "lib"); +use Mojo::IOLoop::ReadWriteProcess qw(process batch); +use Data::Dumper; + +my $sleepduration = 0; + +subtest "Signal on IO" => sub { + my @stack; + + my $p1 = process(sub { sleep 2; print "Hello world\n" }); + for my $i (1 .. 10) { + push (@stack, process(sub { sleep 0.2 * $i; print "Bye Bye"})) + } + my $c = batch @stack; + + $p1->start; + $c->start(); + is ($p1->getline(), "Hello world\n", "P1 can read with signals received!"); + is (!!$!{EINTR}, 1, "EINTR is set"); +}; + +done_testing; From d84d4eed29a25ea82183c90dbd8a44b7da992dbb Mon Sep 17 00:00:00 2001 From: Clemens Famulla-Conrad Date: Mon, 13 Dec 2021 09:35:32 +0100 Subject: [PATCH 2/3] 02_parallel_fast.t reproducer --- Build.PL | 3 ++- run_coverage.sh | 11 +++++++++++ t/02_parallel.t | 15 +++++++++------ 3 files changed, 22 insertions(+), 7 deletions(-) create mode 100755 run_coverage.sh diff --git a/Build.PL b/Build.PL index ad9d29b..92f7a60 100644 --- a/Build.PL +++ b/Build.PL @@ -48,8 +48,9 @@ my %args = ( script_files => [glob('script/*'), glob('bin/*')], PL_files => {}, - test_files => ((-d '.git' || $ENV{RELEASE_TESTING}) && -d 'xt') ? 't/ xt/' : 't/', + test_files => 't/02_parallel.t', recursive_test_files => 1, + verbose => 1, ); diff --git a/run_coverage.sh b/run_coverage.sh new file mode 100755 index 0000000..feaf7f4 --- /dev/null +++ b/run_coverage.sh @@ -0,0 +1,11 @@ +#!/bin/bash -e +count=0; +perl Build.PL + +while true; do + count=$(($count + 1 )); + echo "LOOP $count"; + TEST_SHARED=1 TEST_SUBREAPER=1 cover -test -report codecovbash +# TEST_SHARED=1 TEST_SUBREAPER=1 cover -test -report text +done + diff --git a/t/02_parallel.t b/t/02_parallel.t index e845243..812b44c 100644 --- a/t/02_parallel.t +++ b/t/02_parallel.t @@ -5,17 +5,20 @@ use strict; use Test::More; use POSIX; use FindBin; +use Time::HiRes qw(sleep); use Mojo::File qw(tempfile path); use lib ("$FindBin::Bin/lib", "../lib", "lib"); use Mojo::IOLoop::ReadWriteProcess qw(parallel batch process pool); +my $sleepduration = 0; + subtest parallel => sub { my $n_proc = 4; my $fired; my $c = parallel( - code => sub { sleep 2; print "Hello world\n"; }, - kill_sleeptime => 1, + code => sub { sleep $sleepduration; print "Hello world\n"; }, + kill_sleeptime => 1, sleeptime_during_kill => 1, separate_err => 1, set_pipes => 1, @@ -34,7 +37,7 @@ subtest parallel => sub { $c->once(stop => sub { $fired++ }); my $b = $c->restart(); is $b, $c; - sleep 3; + sleep $sleepduration * 3; $c->wait_stop; is $fired, $n_proc * 2; }; @@ -47,7 +50,7 @@ subtest batch => sub { push( @stack, process( - code => sub { sleep 2; print "Hello world\n" }, + code => sub { sleep $sleepduration; print "Hello world\n" }, separate_err => 0, set_pipes => 1 )) for (1 .. $n_proc); @@ -93,7 +96,7 @@ subtest "Working with pools" => sub { code => sub { my $self = shift; my $number = shift; - sleep 2; + sleep $sleepduration; return 40 + $number; }, args => $number, @@ -138,7 +141,7 @@ subtest stress_test => sub { my $p = pool; $p->maximum_processes($n_proc); $p->add( - code => sub { sleep 3; exit(20) }, + code => sub { sleep $sleepduration * 3; exit(20) }, internal_pipes => 0, set_pipes => 0 ) for 1 .. $n_proc; From cdba6076f51835a21a5767159a1c69cf1d349f5e Mon Sep 17 00:00:00 2001 From: Clemens Famulla-Conrad Date: Mon, 13 Dec 2021 10:10:52 +0100 Subject: [PATCH 3/3] Set emit_from_sigchld to 0 --- t/02_parallel.t | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/t/02_parallel.t b/t/02_parallel.t index 812b44c..fa1963a 100644 --- a/t/02_parallel.t +++ b/t/02_parallel.t @@ -12,6 +12,9 @@ use Mojo::IOLoop::ReadWriteProcess qw(parallel batch process pool); my $sleepduration = 0; +my $session = Mojo::IOLoop::ReadWriteProcess::Session->new(); +$session->emit_from_sigchld(0); + subtest parallel => sub { my $n_proc = 4; my $fired; @@ -25,6 +28,8 @@ subtest parallel => sub { $n_proc ); + is ($session, $c->first->session, "Session is the singleton!"); + isa_ok($c, "Mojo::IOLoop::ReadWriteProcess::Pool"); is $c->size(), $n_proc;