-
Notifications
You must be signed in to change notification settings - Fork 2
/
worker.t
69 lines (51 loc) · 1.54 KB
/
worker.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use t::Utils;
use Test::More;
use Jonk;
my $dbh = t::Utils->setup;
subtest 'grab_job' => sub {
my $client = Jonk->new($dbh, {});
my $job_id = $client->insert('MyWorker', 'arg');
ok $job_id;
my $job = $client->find_job(+{functions => [qw/MyWorker/]});
is $job->arg, 'arg';
is $job->func, 'MyWorker';
is $job->retry_cnt, 0;
is $job->run_after, 0;
is $job->priority, 0;
ok not $client->errstr;
$job->completed;
ok not $client->find_job(+{functions => [qw/MyWorker/]});
};
done_testing;
__END__
subtest 'grab_job / no job' => sub {
my $client = Jonk->new($dbh, {functions => [qw/MyWorker/]});
my $job = $client->grab_job;
ok not $job;
};
subtest 'grab_job / specific job_id' => sub {
my $client = Jonk->new($dbh);
my $job_id = $client->insert('MyWorker', 'grab_job');
ok $job_id;
my $job = $client->grab_job($job_id);
is $job->arg, 'grab_job';
is $job->func, 'MyWorker';
$job->completed;
ok not $client->grab_job;
};
t::Utils->cleanup($dbh);
subtest 'grab_job / flexible job table name' => sub {
my $dbh = t::Utils->setup("my_job");
my $client = Jonk->new($dbh, { table_name => "my_job" });
my $job_id = $client->insert('MyWorker', 'arg');
ok $job_id;
my $jonk = Jonk->new($dbh, { table_name => "my_job", functions => [qw/MyWorker/]});
my $job = $jonk->grab_job;
is $job->arg, 'arg';
is $job->func, 'MyWorker';
ok not $jonk->errstr;
$job->completed;
ok not $client->grab_job;
t::Utils->cleanup($dbh, "my_job");
};
done_testing;