<commit_before>use strict;
use warnings;
use Test2::Bundle::Extended;
use Coro;
use Guard qw(scope_guard);
use List::Util qw(shuffle);
use Coro::ProcessPool::Process;

die 'MSWin32 is not supported' if $^O eq 'MSWin32';

my $timeout = 3;

sub test_sub {
  my ($x) = @_;
  return $x * 2;
}

my @range = (1 .. 20);

subtest 'shutdown' => sub{
  my $proc = Coro::ProcessPool::Process->new;
  ok(my $pid = $proc->pid, 'spawned correctly');

  scope_guard { $proc->join(30); };

  ok(my $id = $proc->send(\&test_sub, [21]), 'final send');
  ok($proc->shutdown($timeout), 'shutdown with pending task');

  my $reply = eval { $proc->recv($id) };
  my $error = $@;

  ok(!$reply, 'no reply received after termination');
  ok($error, 'error thrown in recv after termination');
  like($error, qr/process killed while waiting on this task to complete/, 'expected error');
};

subtest 'in order' => sub{
  my $proc = Coro::ProcessPool::Process->new;
  ok(my $pid = $proc->pid, 'spawned correctly');

  scope_guard { $proc->shutdown($timeout); $proc->join(30); };

  my $count = 0;
  foreach my $i (@range) {
    ok(my $id = $proc->send(\&test_sub, [$i]), "send ($i)");
    ok(my $reply = $proc->recv($id), "recv ($i)");
    is($reply, $i * 2, "receives expected result ($i)");
    is($proc->messages_sent, ++$count, "message count tracking ($i)");
  }
};

=cut
subtest 'out of order' => sub{
  my $proc = Coro::ProcessPool::Process->new;
  ok(my $pid = $proc->pid, 'spawned correctly');

  scope_guard { $proc->shutdown($timeout); $proc->join(30); };

  my %pending;
  foreach my $i (shuffle @range) {
    ok(my $id = $proc->send(\&test_sub, [$i]), "ooo send ($i)");
    $pending{$i} = $id;
  }

  foreach my $i (shuffle keys %pending) {
    my $id = $pending{$i};
    ok(my $reply = $proc->recv($id), "ooo recv ($i)");
    is($reply, $i * 2, "ooo receives expected result ($i)");
  }
};

subtest 'include path' => sub{
  my $proc = Coro::ProcessPool::Process->new(include => ['t/']);
  ok(my $pid = $proc->pid, 'spawned correctly');

  scope_guard { $proc->shutdown($timeout); $proc->join(30); };

  my $rs;
  ok lives{ $rs = $proc->recv($proc->send('TestTaskNoNS', [])) }, 'recv';
  is $rs, 42, 'expected result';
};
=cut

done_testing;
<commit_msg>Attempt to fix test failures in perl 5.24+: narrow it test by test<commit_after>use strict;
use warnings;
use Test2::Bundle::Extended;
use Coro;
use Guard qw(scope_guard);
use List::Util qw(shuffle);
use Coro::ProcessPool::Process;

die 'MSWin32 is not supported' if $^O eq 'MSWin32';

my $timeout = 3;

sub test_sub {
  my ($x) = @_;
  return $x * 2;
}

my @range = (1 .. 20);

subtest 'shutdown' => sub{
  my $proc = Coro::ProcessPool::Process->new;
  ok(my $pid = $proc->pid, 'spawned correctly');

  scope_guard { $proc->join(30); };

  ok(my $id = $proc->send(\&test_sub, [21]), 'final send');
  ok($proc->shutdown($timeout), 'shutdown with pending task');

  my $reply = eval { $proc->recv($id) };
  my $error = $@;

  ok(!$reply, 'no reply received after termination');
  ok($error, 'error thrown in recv after termination');
  like($error, qr/process killed while waiting on this task to complete/, 'expected error');
};

subtest 'in order' => sub{
  my $proc = Coro::ProcessPool::Process->new;
  ok(my $pid = $proc->pid, 'spawned correctly');

  scope_guard { $proc->shutdown($timeout); $proc->join(30); };

  my $count = 0;
  foreach my $i (@range) {
    ok(my $id = $proc->send(\&test_sub, [$i]), "send ($i)");
    ok(my $reply = $proc->recv($id), "recv ($i)");
    is($reply, $i * 2, "receives expected result ($i)");
    is($proc->messages_sent, ++$count, "message count tracking ($i)");
  }
};

subtest 'out of order' => sub{
  my $proc = Coro::ProcessPool::Process->new;
  ok(my $pid = $proc->pid, 'spawned correctly');

  scope_guard { $proc->shutdown($timeout); $proc->join(30); };

  my %pending;
  foreach my $i (shuffle @range) {
    ok(my $id = $proc->send(\&test_sub, [$i]), "ooo send ($i)");
    $pending{$i} = $id;
  }

  foreach my $i (shuffle keys %pending) {
    my $id = $pending{$i};
    ok(my $reply = $proc->recv($id), "ooo recv ($i)");
    is($reply, $i * 2, "ooo receives expected result ($i)");
  }
};

=cut
subtest 'include path' => sub{
  my $proc = Coro::ProcessPool::Process->new(include => ['t/']);
  ok(my $pid = $proc->pid, 'spawned correctly');

  scope_guard { $proc->shutdown($timeout); $proc->join(30); };

  my $rs;
  ok lives{ $rs = $proc->recv($proc->send('TestTaskNoNS', [])) }, 'recv';
  is $rs, 42, 'expected result';
};
=cut

done_testing;

{'fraction_non_alphanumeric': 0.21606709335687485, 'fraction_numerical': 0.01169719708673582, 'mean_word_length': 4.115124153498871, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3080634', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1669, 'n_words': 464}