Skip to content

Commit

Permalink
Test all branches
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jun 10, 2021
1 parent 4ea4ba3 commit b8bb86e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/Minion.pm
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,9 @@ sub _perform_jobs {

my $worker = $minion->worker;
while (my $job = $worker->register->dequeue(0, $options)) {
if (!$foreground) { $job->perform }
else {
my $err = $job->execute;
defined $err ? $job->fail($err) : $job->finish;
}
if (!$foreground) { $job->perform }
elsif (defined(my $err = $job->execute)) { $job->fail($err) }
else { $job->finish }
}
$worker->unregister;
}
Expand Down
11 changes: 11 additions & 0 deletions t/pg.t
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,7 @@ subtest 'perform_jobs/perform_jobs_in_foreground' => sub {
$job->finish({pid => $$});
}
);
$minion->add_task(perform_fails => sub { die 'Just a test' });

my $id = $minion->enqueue('record_pid');
$minion->perform_jobs;
Expand All @@ -1342,11 +1343,21 @@ subtest 'perform_jobs/perform_jobs_in_foreground' => sub {
isnt $job->info->{result}{pid}, $$, 'different process id';

my $id2 = $minion->enqueue('record_pid');
my $id3 = $minion->enqueue('perform_fails');
my $id4 = $minion->enqueue('record_pid');
$minion->perform_jobs_in_foreground;
my $job2 = $minion->job($id2);
is $job2->task, 'record_pid', 'right task';
is $job2->info->{state}, 'finished', 'right state';
is $job2->info->{result}{pid}, $$, 'same process id';
my $job3 = $minion->job($id3);
is $job3->task, 'perform_fails', 'right task';
is $job3->info->{state}, 'failed', 'right state';
like $job3->info->{result}, qr/Just a test/, 'right error';
my $job4 = $minion->job($id4);
is $job4->task, 'record_pid', 'right task';
is $job4->info->{state}, 'finished', 'right state';
is $job4->info->{result}{pid}, $$, 'same process id';
};

subtest 'Foreground' => sub {
Expand Down

0 comments on commit b8bb86e

Please sign in to comment.