Hello community,
here is the log from the commit of package perl-Mojo-IOLoop-ReadWriteProcess
for openSUSE:Factory checked in at 2018-02-26 23:26:28
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/perl-Mojo-IOLoop-ReadWriteProcess (Old)
and /work/SRC/openSUSE:Factory/.perl-Mojo-IOLoop-ReadWriteProcess.new
(New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "perl-Mojo-IOLoop-ReadWriteProcess"
Mon Feb 26 23:26:28 2018 rev:3 rq:580200 version:0.19
Changes:
--------
---
/work/SRC/openSUSE:Factory/perl-Mojo-IOLoop-ReadWriteProcess/perl-Mojo-IOLoop-ReadWriteProcess.changes
2018-02-20 17:55:33.637415858 +0100
+++
/work/SRC/openSUSE:Factory/.perl-Mojo-IOLoop-ReadWriteProcess.new/perl-Mojo-IOLoop-ReadWriteProcess.changes
2018-02-26 23:26:31.647365981 +0100
@@ -1,0 +2,20 @@
+Mon Feb 26 09:20:31 UTC 2018 - [email protected]
+
+- updated to 0.19
+
+ 0.19 2018-02-22T13:41:50Z
+
+ - Minor bugfixes to Session
+ - Make session constructor fixed
+
+ 0.18 2018-02-21T12:01:07Z
+
+ - Guard stop() from possible race conditions
+ - Fix typo in Session, it caused orphan processes to not be resolved
correctly
+
+ 0.17 2018-02-20T14:01:59Z
+
+ - Fix minor issue in tests, stabilize serialize test and events
+ - Reset session and subreaper bit on forked child process
+
+-------------------------------------------------------------------
Old:
----
Mojo-IOLoop-ReadWriteProcess-0.16.tar.gz
New:
----
Mojo-IOLoop-ReadWriteProcess-0.19.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ perl-Mojo-IOLoop-ReadWriteProcess.spec ++++++
--- /var/tmp/diff_new_pack.vYPwMt/_old 2018-02-26 23:26:32.511334909 +0100
+++ /var/tmp/diff_new_pack.vYPwMt/_new 2018-02-26 23:26:32.515334764 +0100
@@ -17,7 +17,7 @@
Name: perl-Mojo-IOLoop-ReadWriteProcess
-Version: 0.16
+Version: 0.19
Release: 0
%define cpan_name Mojo-IOLoop-ReadWriteProcess
Summary: Execute external programs or internal code blocks as separate
process
++++++ Mojo-IOLoop-ReadWriteProcess-0.16.tar.gz ->
Mojo-IOLoop-ReadWriteProcess-0.19.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Mojo-IOLoop-ReadWriteProcess-0.16/Changes
new/Mojo-IOLoop-ReadWriteProcess-0.19/Changes
--- old/Mojo-IOLoop-ReadWriteProcess-0.16/Changes 2018-02-19
14:36:01.000000000 +0100
+++ new/Mojo-IOLoop-ReadWriteProcess-0.19/Changes 2018-02-22
14:44:36.000000000 +0100
@@ -1,5 +1,20 @@
Revision history for Perl extension Mojo-IOLoop-ReadWriteProcess
+0.19 2018-02-22T13:41:50Z
+
+ - Minor bugfixes to Session
+ - Make session constructor fixed
+
+0.18 2018-02-21T12:01:07Z
+
+ - Guard stop() from possible race conditions
+ - Fix typo in Session, it caused orphan processes to not be resolved
correctly
+
+0.17 2018-02-20T14:01:59Z
+
+ - Fix minor issue in tests, stabilize serialize test and events
+ - Reset session and subreaper bit on forked child process
+
0.16 2018-02-19T13:32:54Z
- Fix minor issue in event test that made them unstable
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Mojo-IOLoop-ReadWriteProcess-0.16/META.json
new/Mojo-IOLoop-ReadWriteProcess-0.19/META.json
--- old/Mojo-IOLoop-ReadWriteProcess-0.16/META.json 2018-02-19
14:36:01.000000000 +0100
+++ new/Mojo-IOLoop-ReadWriteProcess-0.19/META.json 2018-02-22
14:44:36.000000000 +0100
@@ -55,7 +55,7 @@
"provides" : {
"Mojo::IOLoop::ReadWriteProcess" : {
"file" : "lib/Mojo/IOLoop/ReadWriteProcess.pm",
- "version" : "0.16"
+ "version" : "0.19"
},
"Mojo::IOLoop::ReadWriteProcess::Exception" : {
"file" : "lib/Mojo/IOLoop/ReadWriteProcess/Exception.pm"
@@ -81,7 +81,7 @@
"web" : "https://github.com/mudler/Mojo-IOLoop-ReadWriteProcess"
}
},
- "version" : "0.16",
+ "version" : "0.19",
"x_contributors" : [
"Ettore Di Giacinto <[email protected]>",
"Ettore Di Giacinto <[email protected]>"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Mojo-IOLoop-ReadWriteProcess-0.16/META.yml
new/Mojo-IOLoop-ReadWriteProcess-0.19/META.yml
--- old/Mojo-IOLoop-ReadWriteProcess-0.16/META.yml 2018-02-19
14:36:01.000000000 +0100
+++ new/Mojo-IOLoop-ReadWriteProcess-0.19/META.yml 2018-02-22
14:44:36.000000000 +0100
@@ -27,7 +27,7 @@
provides:
Mojo::IOLoop::ReadWriteProcess:
file: lib/Mojo/IOLoop/ReadWriteProcess.pm
- version: '0.16'
+ version: '0.19'
Mojo::IOLoop::ReadWriteProcess::Exception:
file: lib/Mojo/IOLoop/ReadWriteProcess/Exception.pm
Mojo::IOLoop::ReadWriteProcess::Pool:
@@ -42,7 +42,7 @@
bugtracker: https://github.com/mudler/Mojo-IOLoop-ReadWriteProcess/issues
homepage: https://github.com/mudler/Mojo-IOLoop-ReadWriteProcess
repository: git://github.com/mudler/Mojo-IOLoop-ReadWriteProcess.git
-version: '0.16'
+version: '0.19'
x_contributors:
- 'Ettore Di Giacinto <[email protected]>'
- 'Ettore Di Giacinto <[email protected]>'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/Mojo-IOLoop-ReadWriteProcess-0.16/lib/Mojo/IOLoop/ReadWriteProcess/Session.pm
new/Mojo-IOLoop-ReadWriteProcess-0.19/lib/Mojo/IOLoop/ReadWriteProcess/Session.pm
---
old/Mojo-IOLoop-ReadWriteProcess-0.16/lib/Mojo/IOLoop/ReadWriteProcess/Session.pm
2018-02-19 14:36:01.000000000 +0100
+++
new/Mojo-IOLoop-ReadWriteProcess-0.19/lib/Mojo/IOLoop/ReadWriteProcess/Session.pm
2018-02-22 14:44:36.000000000 +0100
@@ -24,7 +24,8 @@
has 'handler';
my $singleton;
-sub new { $singleton ||= shift->SUPER::new(@_); }
+
+sub new { $singleton ||= __PACKAGE__->SUPER::new }
sub disable {
$singleton->_protect(sub { $SIG{CHLD} = $singleton->handler() });
@@ -91,12 +92,12 @@
my ($el, $w) = (pop, pop);
return
exists $singleton->{$w}->{$el} ?
- $el eq 'orphan'
+ $w eq 'orphans'
? $singleton->{$w}->{$el}
: ${$singleton->{$w}->{$el}}
: undef;
}
-sub orphan { _resolve(orphan => pop()) }
+sub orphan { _resolve(orphans => pop()) }
sub resolve { _resolve(process_table => pop()) }
sub clean {
@@ -119,22 +120,17 @@
$singleton->all->grep(sub { $_->pid eq $pid })->size == 1;
}
-sub reset {
- $_[0]->{events} = {};
- $_[0]->orphans({});
- shift->process_table({});
-}
+sub reset { @{+shift}{qw(events orphans process_table)} = ({}, {}, {}) }
+# XXX: This should be replaced by PR_GET_CHILD_SUBREAPER
sub disable_subreaper {
- $singleton->subreaper(1)
- unless $singleton->_prctl(PR_SET_CHILD_SUBREAPER, 0) == 0;
- $singleton;
+ $singleton->subreaper(
+ $singleton->_prctl(PR_SET_CHILD_SUBREAPER, 0) == 0 ? 0 : 1);
}
sub enable_subreaper {
- $singleton->subreaper(0)
- unless $singleton->_prctl(PR_SET_CHILD_SUBREAPER, 1) == 0;
- $singleton;
+ $singleton->subreaper(
+ $singleton->_prctl(PR_SET_CHILD_SUBREAPER, 1) == 0 ? 1 : 0);
}
sub _get_prctl_syscall {
@@ -449,7 +445,7 @@
=head2 register()
use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
- my $process = session->register(Mojo::IOLoop::ReadWriteProcess->new);
+ my $process = session->register('pid' =>
Mojo::IOLoop::ReadWriteProcess->new);
Register the L<Mojo::IOLoop::ReadWriteProcess> process to the session.
@@ -463,7 +459,7 @@
=head2 collect()
use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
- my $process = session->collect(123342, 0, undef);
+ my $process = session->collect(123342 => 0 => undef);
Collect the status for the given pid.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/Mojo-IOLoop-ReadWriteProcess-0.16/lib/Mojo/IOLoop/ReadWriteProcess.pm
new/Mojo-IOLoop-ReadWriteProcess-0.19/lib/Mojo/IOLoop/ReadWriteProcess.pm
--- old/Mojo-IOLoop-ReadWriteProcess-0.16/lib/Mojo/IOLoop/ReadWriteProcess.pm
2018-02-19 14:36:01.000000000 +0100
+++ new/Mojo-IOLoop-ReadWriteProcess-0.19/lib/Mojo/IOLoop/ReadWriteProcess.pm
2018-02-22 14:44:36.000000000 +0100
@@ -1,6 +1,6 @@
package Mojo::IOLoop::ReadWriteProcess;
-our $VERSION = '0.16';
+our $VERSION = '0.19';
use Mojo::Base 'Mojo::EventEmitter';
use Mojo::File 'path';
@@ -97,7 +97,7 @@
return unless $self;
- $self->_status($? // $e);
+ $self->_status($e // $?) unless defined $self->_status;
$self->_diag("Forked code Process Exit status: " . $self->exit_status)
if DEBUG;
@@ -139,9 +139,16 @@
sub _collect {
my ($self, $pid) = @_;
$pid //= $self->pid;
- waitpid $pid, 0;
- return $self->_open_collect_status($pid) if $self->execute;
- return $self->_fork_collect_status($pid) if $self->code;
+
+ $self->session->_protect(
+ sub {
+ local $?;
+ waitpid $pid, 0 unless defined $self->_status;
+ return $self->_open_collect_status($pid) if $self->execute;
+ return $self->_fork_collect_status($pid) if $self->code;
+ });
+
+ $self;
}
sub _fork_collect_status {
@@ -154,7 +161,7 @@
my $rt;
my @result_error;
- $self->_status($? // $e);
+ $self->_status($e // $?) unless defined $self->_status;
$self->_diag("Forked code Process Exit status: " . $self->exit_status)
if DEBUG;
@@ -295,6 +302,8 @@
for qw(read_stream error_stream write_stream channel_in channel_out);
}
$self->session->reset;
+ $self->session->subreaper(0); # Subreaper bit does not persist in fork
+
$! = 0;
my $rt;
eval { $rt = [$code->($self, @args)]; };
@@ -353,8 +362,12 @@
sub wait_stop { shift->wait->stop }
sub errored { !!@{shift->error} ? 1 : 0 }
sub exit_status { defined $_[0]->_status ? shift->_status >> 8 : undef }
-sub restart { $_[0]->is_running ? $_[0]->stop->start : $_[0]->start; }
-sub is_running { $_[0]->process_id ? kill 0 => $_[0]->process_id : 0; }
+
+sub restart {
+ $_[0]->{_status} = undef;
+ $_[0]->is_running ? $_[0]->stop->start : $_[0]->start;
+}
+sub is_running { $_[0]->process_id ? kill 0 => $_[0]->process_id : 0; }
sub write_pidfile {
my ($self, $pidfile) = @_;
@@ -444,7 +457,7 @@
}
sub send_signal {
- my $self = shift;
+ my $self = shift;
my $signal = shift // $self->_default_kill_signal;
return unless $self->is_running;
$self->_diag("Sending signal '$signal' to " . $self->process_id) if DEBUG;
@@ -454,6 +467,11 @@
sub stop {
my $self = shift;
+
+ return $self unless defined $self->pid;
+
+ $self->_diag("Stopping " . $self->pid) if DEBUG;
+
return $self->_shutdown(1) unless $self->is_running;
my $ret;
@@ -468,9 +486,13 @@
. $self->pid)
if DEBUG;
sleep $self->sleeptime_during_kill if $self->sleeptime_during_kill;
- $self->send_signal();
- $ret = waitpid($self->process_id, WNOHANG);
- $self->_status($?);
+ $self->session->_protect(
+ sub {
+ local $?;
+ $self->send_signal();
+ $ret = waitpid($self->process_id, WNOHANG);
+ $self->_status($?) if $ret == $self->process_id;
+ });
$attempt++;
}
@@ -480,9 +502,12 @@
$self->_diag(
"Could not kill process id: " . $self->process_id . ", blocking attempt")
if DEBUG;
- $self->emit('process_stuck')->send_signal($self->_default_blocking_signal);
- waitpid($self->process_id, 0);
- $self->_status($?);
+ $self->emit('process_stuck');
+
+ ### XXX: avoid to protect on blocking.
+ $self->send_signal($self->_default_blocking_signal);
+ $ret = waitpid($self->process_id, 0);
+ $self->_status($?) if $ret == $self->process_id;
}
elsif ($self->is_running) {
$self->_diag("Could not kill process id: " . $self->process_id) if DEBUG;
@@ -493,13 +518,23 @@
}
sub _shutdown {
- my $self = shift;
- waitpid $self->pid, 0 if pop && $self->pid;
- $self->emit('collect_status') if !defined $self->_status;
+ my ($self, $wait) = @_;
+ return $self unless $self->pid;
+
+ $self->_diag("Shutdown " . $self->pid) if DEBUG;
+ $self->session->_protect(
+ sub {
+ local $?;
+ waitpid $self->pid, 0;
+ $self->emit('collect_status');
+ }) if $wait && !defined $self->_status;
+
+ $self->emit('collect_status') unless defined $self->_status;
$self->_clean_pidfile;
$self->emit('process_error', $self->error)
if $self->error && $self->error->size > 0;
$self->unsubscribe('collect_status');
+
return $self->emit('stop');
}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Mojo-IOLoop-ReadWriteProcess-0.16/t/02_parallel.t
new/Mojo-IOLoop-ReadWriteProcess-0.19/t/02_parallel.t
--- old/Mojo-IOLoop-ReadWriteProcess-0.16/t/02_parallel.t 2018-02-19
14:36:01.000000000 +0100
+++ new/Mojo-IOLoop-ReadWriteProcess-0.19/t/02_parallel.t 2018-02-22
14:44:36.000000000 +0100
@@ -133,16 +133,19 @@
plan skip_all => "set STRESS_TEST=1 (be careful)" unless $ENV{STRESS_TEST};
# Push the maximum_processes boundaries and let's see events are fired.
- my $n_proc = 100;
+ my $n_proc = 2000;
my $fired;
my $p = pool;
$p->maximum_processes($n_proc);
- $p->add(code => sub { sleep 3; exit(20) }, internal_pipes => 0, set_pipes =>
0)
- for 1 .. $n_proc;
+ $p->add(
+ code => sub { sleep 3; exit(20) },
+ internal_pipes => 0,
+ set_pipes => 0
+ ) for 1 .. $n_proc;
$p->once(stop => sub { $fired++ });
$p->start->wait;
is $fired, $n_proc;
- $p->each(sub {is $_->exit_status,"20"});
+ $p->each(sub { is $_->exit_status, "20" });
};
done_testing;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Mojo-IOLoop-ReadWriteProcess-0.16/t/04_queues.t
new/Mojo-IOLoop-ReadWriteProcess-0.19/t/04_queues.t
--- old/Mojo-IOLoop-ReadWriteProcess-0.16/t/04_queues.t 2018-02-19
14:36:01.000000000 +0100
+++ new/Mojo-IOLoop-ReadWriteProcess-0.19/t/04_queues.t 2018-02-22
14:44:36.000000000 +0100
@@ -157,4 +157,44 @@
is(Mojo::IOLoop::ReadWriteProcess::Session->singleton->all->size, 40);
is(Mojo::IOLoop::ReadWriteProcess::Session->singleton->all_orphans->size, 0);
+subtest stress_test => sub {
+ plan skip_all => "set STRESS_TEST=1 (be careful)" unless $ENV{STRESS_TEST};
+ Mojo::IOLoop::ReadWriteProcess::Session->singleton->reset;
+
+ my $q = queue();
+ $q->pool->maximum_processes(50);
+ $q->queue->maximum_processes(100000);
+ my $proc = 200;
+ my $fired;
+ my %output;
+ my $i = 1;
+
+# Started as long as resources allows (maximum_processes of the main pool)
+# That requires then to subscribe for each process event's separately
(manually)
+ for (1 .. $proc) {
+ my $p = process(sub { shift; sleep 4; exit shift() })->set_pipes(0)
+ ->internal_pipes(0)->args($i);
+ $p->once(
+ stop => sub {
+ $fired++;
+ $output{shift->exit_status}++;
+ });
+ $q->add($p);
+ $i++;
+ }
+
+ is $q->pool->maximum_processes, 50;
+ $q->consume;
+ is $q->queue->size, 0;
+ is $q->pool->size, 0;
+ is $q->done->size, $proc;
+ is $fired, $proc;
+ $i = 1;
+ for (1 .. $proc) {
+ is $output{$i}, 1 or diag explain \%output;
+ $i++;
+ }
+ is(Mojo::IOLoop::ReadWriteProcess::Session->singleton->all->size, 200);
+};
+
done_testing;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Mojo-IOLoop-ReadWriteProcess-0.16/t/05_serialize.t
new/Mojo-IOLoop-ReadWriteProcess-0.19/t/05_serialize.t
--- old/Mojo-IOLoop-ReadWriteProcess-0.16/t/05_serialize.t 2018-02-19
14:36:01.000000000 +0100
+++ new/Mojo-IOLoop-ReadWriteProcess-0.19/t/05_serialize.t 2018-02-22
14:44:36.000000000 +0100
@@ -21,44 +21,4 @@
is_deeply $p->return_status, [qw(12 13 14)] or diag explain $p->return_status;
-my $q = queue;
-$q->pool->maximum_processes(2);
-$q->queue->maximum_processes(800);
-
-my $proc = 10;
-my $fired;
-
-my $i = 1;
-for (1 .. $proc) {
- $q->add(
- process(
- serialize => 1,
- code => sub {
- shift;
- return {$_[0] => $_[0]};
- }
- )->args($i));
- $i++;
-}
-
-my @output;
-$q->once(
- stop => sub {
- $fired++;
- push @output, shift->return_status;
- });
-is $q->queue->size, $proc - $q->pool->maximum_processes;
-is $q->pool->size, 2;
-is $q->pool->maximum_processes, 2;
-$q->consume;
-is $fired, $proc;
-is $q->queue->size, 0;
-is $q->pool->size, 0;
-
-$i = 0;
-for ($proc .. 1) {
- is_deeply $output[$i], [{$i => $i}] or diag explain $output[$i];
- $i++;
-}
-
done_testing;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Mojo-IOLoop-ReadWriteProcess-0.16/t/06_events.t
new/Mojo-IOLoop-ReadWriteProcess-0.19/t/06_events.t
--- old/Mojo-IOLoop-ReadWriteProcess-0.16/t/06_events.t 2018-02-19
14:36:01.000000000 +0100
+++ new/Mojo-IOLoop-ReadWriteProcess-0.19/t/06_events.t 2018-02-22
14:44:36.000000000 +0100
@@ -20,7 +20,7 @@
"You do not seem to have $test_script. The script is required to run the test"
unless -e $test_script;
my $reached;
- my $collect;
+ my $collect = 0;
my $p = process(sub { print "Hello\n" });
$p->session->collect_status(0);
@@ -33,17 +33,14 @@
});
$p->start;
-
attempt {
- attempts => 10,
+ attempts => 20,
condition => sub { defined $reached && $reached == 1 },
- cb => sub { sleep 1 }
+ cb => sub { $p->signal(POSIX::SIGTERM); sleep 1; }
};
- $p->stop;
-
is $reached, 1, 'SIG_CHLD fired';
- is $collect, 1, 'collect_status fired once';
+ is $collect, 0, 'collect_status not fired';
is(Mojo::IOLoop::ReadWriteProcess::Session->singleton->all_orphans->size, 0);
is(Mojo::IOLoop::ReadWriteProcess::Session->singleton->all->size, 1);
@@ -52,6 +49,8 @@
my $p2 = process(execute => $test_script);
$p2->session->collect_status(1);
+ $reached = 0;
+
$p2->on(
SIG_CHLD => sub {
my $self = shift;
@@ -61,14 +60,13 @@
$p2->start;
attempt {
- attempts => 10,
- condition => sub { defined $reached && $reached == 2 },
- cb => sub { sleep 1 }
+ attempts => 20,
+ condition => sub { defined $reached && $reached == 1 },
+ cb => sub { $p2->signal(POSIX::SIGTERM); sleep 1; }
};
- $p2->stop;
-
- is $reached, 2, 'SIG_CHLD fired';
+ is $reached, 1, 'SIG_CHLD fired';
+ ok defined($p2->exit_status), 'SIG_CHLD fired';
is(Mojo::IOLoop::ReadWriteProcess::Session->singleton->all_orphans->size, 0);
is(Mojo::IOLoop::ReadWriteProcess::Session->singleton->all->size, 1);
@@ -77,11 +75,9 @@
subtest collect_status => sub {
session->reset;
- my $collect;
my $sigcld;
my $p = process(sub { print "Hello\n" });
$p->session->collect_status(0);
- $p->session->on(collect_status => sub { $collect++ });
$p->session->on(
SIG_CHLD => sub {
$sigcld++;
@@ -92,12 +88,10 @@
attempt {
attempts => 10,
condition => sub { defined $sigcld && $sigcld == 1 },
- cb => sub { sleep 1 }
+ cb => sub { $p->signal(POSIX::SIGTERM); sleep 1 }
};
- $p->stop();
- is $collect, undef, 'No collect_status fired';
- is $sigcld, 1, 'SIG_CHLD fired';
+ is $sigcld, 1, 'SIG_CHLD fired';
is(Mojo::IOLoop::ReadWriteProcess::Session->singleton->all_orphans->size, 0);
is(Mojo::IOLoop::ReadWriteProcess::Session->singleton->all->size, 1);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Mojo-IOLoop-ReadWriteProcess-0.16/t/09_session.t
new/Mojo-IOLoop-ReadWriteProcess-0.19/t/09_session.t
--- old/Mojo-IOLoop-ReadWriteProcess-0.16/t/09_session.t 2018-02-19
14:36:01.000000000 +0100
+++ new/Mojo-IOLoop-ReadWriteProcess-0.19/t/09_session.t 2018-02-22
14:44:36.000000000 +0100
@@ -6,7 +6,7 @@
use POSIX;
use FindBin;
use Mojo::File qw(tempfile path);
-use lib ("$FindBin::Bin/lib", "../lib", "lib");
+use lib ( "$FindBin::Bin/lib", "../lib", "lib" );
use Mojo::IOLoop::ReadWriteProcess qw(process);
use Mojo::IOLoop::ReadWriteProcess::Test::Utils qw(attempt);
@@ -15,51 +15,71 @@
use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
subtest register => sub {
- my $s = Mojo::IOLoop::ReadWriteProcess::Session->singleton;
- my $p = process(sub { });
- $s->register(1 => $p);
+ my $s = session;
+ my $p = process( sub { } );
+ $s->register( 1 => $p );
- is_deeply ${$s->process_table()->{1}}, $p, 'Equal' or die diag explain $s;
+ is_deeply ${ $s->process_table()->{1} }, $p, 'Equal' or die diag explain
$s;
- ${$s->process_table()->{1}}->{foo} = 'bar';
+ ${ $s->process_table()->{1} }->{foo} = 'bar';
- is $p->{foo}, 'bar';
+ is $p->{foo}, 'bar';
- session->resolve(1)->{foo} = 'kaboom';
+ session->resolve(1)->{foo} = 'kaboom';
- is $p->{foo}, 'kaboom';
+ is $p->{foo}, 'kaboom';
};
-
subtest unregister => sub {
- session->clean();
+ session->clean();
- my $p = process(sub { });
- session->register(1 => $p);
+ my $p = process( sub { } );
+ session->register( 1 => $p );
- is_deeply ${session->process_table()->{1}}, $p, 'Equal'
- or die diag explain session();
+ is_deeply ${ session->process_table()->{1} }, $p, 'Equal'
+ or die diag explain session();
- session->unregister(1);
- is session->all()->size, 0;
- is session->resolve(1), undef;
+ session->unregister(1);
+ is session->all()->size, 0;
+ is session->resolve(1), undef;
- session->register(1 => $p);
- is session->all()->size, 1;
+ session->register( 1 => $p );
+ is session->all()->size, 1;
- session->clean();
- is session->all()->size, 0;
+ session->clean();
+ is session->all()->size, 0;
};
subtest disable => sub {
- local $SIG{CHLD} = 'DEFAULT';
+ local $SIG{CHLD} = 'DEFAULT';
+
+ session->enable();
+ is session->handler, 'DEFAULT', 'previous handler saved';
+
+ isnt $SIG{CHLD}, 'DEFAULT', 'Handler has changed';
+ session->disable();
+ is $SIG{CHLD}, 'DEFAULT', 'handler restored';
+};
+
+subtest reset => sub {
+ session->reset;
+
+ session->register( 1 => process( sub { } ) );
+ session->register( 2 => process( sub { } ) );
+ session->register( 3 => process( sub { } ) );
+ session->orphans->{5} = 1;
+
+ is session->all->size, 4, 'There are 4 processes';
+ session->reset();
+
+ is session->all->size, 0, 'Reset cleaned up processes';
+
+ session->on( foo => sub { 'bar' } );
- session->enable();
- is session->handler, 'DEFAULT', 'previous handler saved';
+ is( ( values %{ session->{events} } ), 1, '1 event is present' );
+ session->reset();
+ is( ( values %{ session->{events} } ), 0, '0 events are present' );
- isnt $SIG{CHLD}, 'DEFAULT', 'Handler has changed';
- session->disable();
- is $SIG{CHLD}, 'DEFAULT', 'handler restored';
};
done_testing();