|
Lines 17-28
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 2; |
20 |
use Test::More tests => 3; |
|
|
21 |
use Test::Exception; |
| 21 |
|
22 |
|
| 22 |
use Koha::Database; |
23 |
use Koha::Database; |
| 23 |
use Koha::BackgroundJobs; |
24 |
use Koha::BackgroundJobs; |
| 24 |
use Koha::BackgroundJob::BatchUpdateItem; |
25 |
use Koha::BackgroundJob::BatchUpdateItem; |
| 25 |
|
26 |
|
|
|
27 |
use JSON qw( decode_json ); |
| 28 |
|
| 26 |
use t::lib::Mocks; |
29 |
use t::lib::Mocks; |
| 27 |
use t::lib::TestBuilder; |
30 |
use t::lib::TestBuilder; |
| 28 |
|
31 |
|
|
Lines 85-87
subtest 'enqueue() tests' => sub {
Link Here
|
| 85 |
|
88 |
|
| 86 |
$schema->storage->txn_rollback; |
89 |
$schema->storage->txn_rollback; |
| 87 |
}; |
90 |
}; |
| 88 |
- |
91 |
|
|
|
92 |
subtest 'start(), step() and finish() tests' => sub { |
| 93 |
|
| 94 |
plan tests => 16; |
| 95 |
|
| 96 |
$schema->storage->txn_begin; |
| 97 |
|
| 98 |
# FIXME: This all feels we need to do it better... |
| 99 |
my $job_id = Koha::BackgroundJob::BatchUpdateItem->new->enqueue( { record_ids => [ 1, 2 ] } ); |
| 100 |
my $job = Koha::BackgroundJobs->find($job_id)->_derived_class; |
| 101 |
|
| 102 |
is( $job->started_on, undef, 'started_on not set yet' ); |
| 103 |
is( $job->size, 2, 'Two steps' ); |
| 104 |
|
| 105 |
$job->start; |
| 106 |
|
| 107 |
isnt( $job->started_on, undef, 'started_on set' ); |
| 108 |
is( $job->status, 'started' ); |
| 109 |
is( $job->progress, 0, 'No progress yet' ); |
| 110 |
|
| 111 |
$job->step; |
| 112 |
is( $job->progress, 1, 'First step' ); |
| 113 |
$job->step; |
| 114 |
is( $job->progress, 2, 'Second step' ); |
| 115 |
throws_ok |
| 116 |
{ $job->step; } |
| 117 |
'Koha::Exceptions::BackgroundJob::StepOutOfBounds', |
| 118 |
'Tried to make a forbidden extra step'; |
| 119 |
|
| 120 |
is( $job->progress, 2, 'progress remains unchanged' ); |
| 121 |
|
| 122 |
my $data = { some => 'data' }; |
| 123 |
|
| 124 |
$job->finish( $data ); |
| 125 |
|
| 126 |
is( $job->status, 'finished' ); |
| 127 |
isnt( $job->ended_on, undef, 'ended_on set' ); |
| 128 |
is_deeply( decode_json( $job->data ), $data ); |
| 129 |
|
| 130 |
throws_ok |
| 131 |
{ $job->start; } |
| 132 |
'Koha::Exceptions::BackgroundJob::InconsistentStatus', |
| 133 |
'Exception thrown trying to start a finished job'; |
| 134 |
|
| 135 |
is( $@->expected_status, 'new' ); |
| 136 |
|
| 137 |
throws_ok |
| 138 |
{ $job->step; } |
| 139 |
'Koha::Exceptions::BackgroundJob::InconsistentStatus', |
| 140 |
'Exception thrown trying to start a finished job'; |
| 141 |
|
| 142 |
is( $@->expected_status, 'started' ); |
| 143 |
|
| 144 |
$schema->storage->txn_rollback; |
| 145 |
}; |