Skip to content

Commit

Permalink
better subprocess tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 15, 2017
1 parent 2d2eb4f commit 15be7c7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
2 changes: 2 additions & 0 deletions Changes
@@ -1,5 +1,7 @@

7.26 2017-02-15
- Fixed bug in Mojo::IOLoop::Subprocess where starting multiple subprocesses
at once could cause expcetions. (jberger)

7.25 2017-02-09
- Fixed cleanup bugs in Mojo::IOLoop::Stream.
Expand Down
35 changes: 22 additions & 13 deletions t/mojo/subprocess.t
Expand Up @@ -107,6 +107,28 @@ Mojo::IOLoop->start;
ok !$fail, 'no error';
is_deeply $result, [], 'right structure';

# Stream inherited from previous subprocesses
($fail, $result) = ();
my $delay = Mojo::IOLoop->delay;
my $me = $$;
for (0 .. 2) {
my $end = $delay->begin;
my $subprocess = Mojo::IOLoop::Subprocess->new;
$subprocess->run(
sub { 1 + 1 },
sub {
my ($subprocess, $err, $two) = @_;
$fail ||= $err;
push @$result, $two;
is $me, $$, 'we are the parent';
$end->();
}
);
}
$delay->wait;
ok !$fail, 'no error';
is_deeply $result, [2, 2, 2], 'right structure';

# Exception
$fail = undef;
Mojo::IOLoop::Subprocess->new->run(
Expand Down Expand Up @@ -145,17 +167,4 @@ $subprocess->run(
Mojo::IOLoop->start;
like $fail, qr/Whatever/, 'right error';

# Stream inherited by previous subprocesses, #1054
my $me = $$;
for (0 .. 2) {
my $subprocess = Mojo::IOLoop::Subprocess->new;
$subprocess->run(
sub { 1 + 1 },
sub {
my ($subprocess, $err) = @_;
is $me, $$, 'correct parent';
}
);
}

done_testing();

0 comments on commit 15be7c7

Please sign in to comment.