Use createrepo_c instead of createrepo
[Fedora-Rebuild.git] / t / 10scheduler.t
blobb2438682581855c76d2df703a3825ee3c38859cd
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use Test::Simple tests => 3;
6 use Fedora::Rebuild::Scheduler;
8 sub eqwithundef {
9 my ($a, $b) = @_;
10 if (defined $a and defined $b and $a eq $b) {
11 return 1;
13 if (!defined $a and !defined $b) {
14 return 1;
16 return 0;
19 sub teststatus {
20 my ($message, $expected_exception, $expected_retval, $status) = @_;
22 ok(
24 eqwithundef($expected_exception, $$status[1]) and
25 eqwithundef($expected_retval, $$status[0])
27 $message . ', got: exception=' . ($$status[1]//'<undef>') .
28 ' retval=' . ($$status[0]//'<undef>')
32 my $scheduler = Fedora::Rebuild::Scheduler->new(1);
34 sub worker {
35 my $arg = shift;
36 if ($arg < 0) {
37 die("Dying worker as requested\n");
39 return $arg;
42 my $job_to_die = $scheduler->schedule(\&worker, -1);
43 my $job_to_succeed = $scheduler->schedule(\&worker, 1);
44 my $job_to_fail = $scheduler->schedule(\&worker, 0);
46 my %finished = $scheduler->finish();
48 teststatus('First job should die', "Dying worker as requested\n", undef,
49 $finished{$job_to_die});
50 teststatus('Second job should succeed', "", 1,
51 $finished{$job_to_succeed});
52 teststatus('Third job should fail', "", 0,
53 $finished{$job_to_fail});