Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 14; |
22 |
use Test::More tests => 15; |
23 |
use Test::MockModule; |
23 |
use Test::MockModule; |
24 |
|
24 |
|
25 |
use List::MoreUtils qw(any); |
25 |
use List::MoreUtils qw(any); |
Lines 140-142
subtest 'search_limited' => sub {
Link Here
|
140 |
|
140 |
|
141 |
$schema->storage->txn_rollback; |
141 |
$schema->storage->txn_rollback; |
142 |
}; |
142 |
}; |
143 |
- |
143 |
|
|
|
144 |
subtest 'purge' => sub { |
145 |
plan tests => 9; |
146 |
$schema->storage->txn_begin; |
147 |
|
148 |
my $recent_date = dt_from_string; |
149 |
my $old_date = dt_from_string->subtract({ days => 3 }); |
150 |
my $job_recent_t1_new = $builder->build_object( { class => 'Koha::BackgroundJobs', value => { status => 'new', ended_on => $old_date, type => 'type1' } } ); |
151 |
my $job_recent_t2_fin = $builder->build_object( { class => 'Koha::BackgroundJobs', value => { status => 'finished', ended_on => $recent_date, type => 'type2' } } ); |
152 |
my $job_old_t1_fin = $builder->build_object( { class => 'Koha::BackgroundJobs', value => { status => 'finished', ended_on => $old_date, type => 'type1' } } ); |
153 |
my $job_old_t2_fin = $builder->build_object( { class => 'Koha::BackgroundJobs', value => { status => 'finished', ended_on => $old_date, type => 'type2' } } ); |
154 |
|
155 |
my $params = { job_types => ['type1'] , # Arrayref of jobtypes to be purged |
156 |
days => 1, # Age in days of jobs to be purged |
157 |
confirm => 0, # Confirm deletion |
158 |
}; |
159 |
is( Koha::BackgroundJobs->purge($params), 1, 'Only the old finished type1 job would be purged' ); |
160 |
|
161 |
$params->{'job_types'} = ['all']; |
162 |
is( Koha::BackgroundJobs->purge($params), 2, 'All finished old jobs would be purged with job_types = all' ); |
163 |
|
164 |
my $rs = Koha::BackgroundJobs->search( |
165 |
{ |
166 |
id => [ $job_recent_t1_new->id, $job_recent_t2_fin->id, $job_old_t1_fin->id, $job_old_t2_fin->id ] |
167 |
} |
168 |
); |
169 |
is( $rs->count, 4, 'All jobs still left in queue'); |
170 |
|
171 |
$params->{'job_types'} = ['type1']; |
172 |
$params->{'confirm'} = 1; |
173 |
is( Koha::BackgroundJobs->purge($params), 1, 'Only the old finished type1 job is purged' ); |
174 |
|
175 |
$rs = Koha::BackgroundJobs->search( |
176 |
{ |
177 |
id => [ $job_recent_t1_new->id, $job_recent_t2_fin->id, $job_old_t1_fin->id, $job_old_t2_fin->id ] |
178 |
} |
179 |
); |
180 |
is( $rs->count, 3, '3 jobs still left in queue'); |
181 |
|
182 |
$params->{'job_types'} = ['all']; |
183 |
is( Koha::BackgroundJobs->purge($params), 1, 'The remaining old finished jobs is purged' ); |
184 |
$rs = Koha::BackgroundJobs->search( |
185 |
{ |
186 |
id => [ $job_recent_t1_new->id, $job_recent_t2_fin->id, $job_old_t1_fin->id, $job_old_t2_fin->id ] |
187 |
} |
188 |
); |
189 |
is( $rs->count, 2, '2 jobs still left in queue'); |
190 |
|
191 |
$rs = Koha::BackgroundJobs->search( |
192 |
{ |
193 |
id => [ $job_recent_t1_new->id ] |
194 |
} |
195 |
); |
196 |
is( $rs->count, 1, 'Unfinished job still left in queue'); |
197 |
|
198 |
$rs = Koha::BackgroundJobs->search( |
199 |
{ |
200 |
id => [ $job_recent_t2_fin->id ] |
201 |
} |
202 |
); |
203 |
is( $rs->count, 1, 'Recent finished job still left in queue'); |
204 |
|
205 |
$schema->storage->txn_rollback; |
206 |
|
207 |
}; |