|
Revision 84, 1.6 kB
(checked in by bradfitz, 3 years ago)
|
|
new test and bug fixes for when a job "die"s when working on multiple
jobs. that is, work_safely does one, succeeds, then works on multiple
coalesced ones, but dies on those. lots of wrong things happened.
|
| Line | |
|---|
| 1 | # -*-perl-*- |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | |
|---|
| 6 | require 't/lib/db-common.pl'; |
|---|
| 7 | |
|---|
| 8 | use TheSchwartz; |
|---|
| 9 | use Test::More tests => 8; |
|---|
| 10 | |
|---|
| 11 | run_tests(4, sub { |
|---|
| 12 | my $client = test_client(dbs => ['ts1']); |
|---|
| 13 | |
|---|
| 14 | my $job2h; |
|---|
| 15 | for (1..2) { |
|---|
| 16 | my $job = TheSchwartz::Job->new( |
|---|
| 17 | funcname => 'Worker::CoalesceTest', |
|---|
| 18 | arg => { n => $_ }, |
|---|
| 19 | coalesce => "a$_", |
|---|
| 20 | ); |
|---|
| 21 | my $h = $client->insert($job); |
|---|
| 22 | $job2h = $h if $_ == 2; |
|---|
| 23 | ok($h, "inserted $h"); |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | $client->reset_abilities; |
|---|
| 27 | $client->can_do("Worker::CoalesceTest"); |
|---|
| 28 | |
|---|
| 29 | my $job = $client->find_job_with_coalescing_prefix("Worker::CoalesceTest", "a1"); |
|---|
| 30 | Worker::CoalesceTest->work_safely($job); |
|---|
| 31 | |
|---|
| 32 | # this one should have succeeded: |
|---|
| 33 | is($job->handle->failures, 0, "no failures on first job"); |
|---|
| 34 | |
|---|
| 35 | # the second one should have failures: |
|---|
| 36 | is($job2h->failures, 1, "1 failure on second job"); |
|---|
| 37 | |
|---|
| 38 | teardown_dbs('ts1'); |
|---|
| 39 | }); |
|---|
| 40 | |
|---|
| 41 | ############################################################################ |
|---|
| 42 | package Worker::CoalesceTest; |
|---|
| 43 | use base 'TheSchwartz::Worker'; |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | sub work { |
|---|
| 47 | my ($class, $job) = @_; |
|---|
| 48 | $job->completed; |
|---|
| 49 | my $arg = $job->arg; |
|---|
| 50 | |
|---|
| 51 | my $job2 = $job->handle->client->find_job_with_coalescing_prefix("Worker::CoalesceTest", "a2"); |
|---|
| 52 | $job2->set_as_current; |
|---|
| 53 | die "Failed working on job2\n"; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | sub keep_exit_status_for { 20 } # keep exit status for 20 seconds after on_complete |
|---|
| 57 | sub grab_for { 10 } |
|---|
| 58 | sub max_retries { 1 } |
|---|
| 59 | sub retry_delay { 10 } |
|---|
| 60 | |
|---|
| 61 | |
|---|