Bugzilla – Attachment 136790 Details for
Bug 30889
Background jobs lead to wrong/missing info in logs
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30889: Unit tests - process
Bug-30889-Unit-tests---process.patch (text/plain), 3.18 KB, created by
Tomás Cohen Arazi (tcohen)
on 2022-06-30 14:57:27 UTC
(
hide
)
Description:
Bug 30889: Unit tests - process
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2022-06-30 14:57:27 UTC
Size:
3.18 KB
patch
obsolete
>From d209b5dbd172b1a85519daede62062bb2c60c09a Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Mon, 20 Jun 2022 16:27:51 +0100 >Subject: [PATCH] Bug 30889: Unit tests - process > >This patch adds corresponding unit tests for the 'process' side of this >patchset. We check that the Context for the job to run in as set from >the Job context recorded at enqueue time. > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > t/db_dependent/Koha/BackgroundJob.t | 54 ++++++++++++++++++++++++++++- > 1 file changed, 53 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Koha/BackgroundJob.t b/t/db_dependent/Koha/BackgroundJob.t >index 68bea92fe1..06b425bad1 100755 >--- a/t/db_dependent/Koha/BackgroundJob.t >+++ b/t/db_dependent/Koha/BackgroundJob.t >@@ -17,7 +17,8 @@ > > use Modern::Perl; > >-use Test::More tests => 4; >+use Test::More tests => 5; >+use Test::MockModule; > use Test::Exception; > > use Koha::Database; >@@ -28,6 +29,7 @@ use JSON qw( decode_json encode_json ); > > use t::lib::Mocks; > use t::lib::TestBuilder; >+use t::lib::Koha::BackgroundJob::BatchTest; > > my $schema = Koha::Database->new->schema; > my $builder = t::lib::TestBuilder->new; >@@ -172,6 +174,56 @@ subtest 'start(), step() and finish() tests' => sub { > $schema->storage->txn_rollback; > }; > >+subtest 'process tests' => sub { >+ >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ C4::Context->interface('intranet'); >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ t::lib::Mocks::mock_userenv( { patron => $patron } ); >+ my $job_context = { >+ number => $patron->borrowernumber, >+ id => $patron->userid, >+ cardnumber => $patron->cardnumber, >+ firstname => $patron->firstname, >+ surname => $patron->surname, >+ branch => $patron->library->branchcode, >+ branchname => $patron->library->branchname, >+ flags => $patron->flags, >+ emailaddress => $patron->email, >+ register_id => undef, >+ register_name => undef, >+ shibboleth => undef, >+ desk_id => undef, >+ desk_name => undef, >+ }; >+ >+ my $background_job_module = Test::MockModule->new('Koha::BackgroundJob'); >+ $background_job_module->mock( >+ 'type_to_class_mapping', >+ sub { >+ return { batch_test => 't::lib::Koha::BackgroundJob::BatchTest' }; >+ } >+ ); >+ >+ my $job_id = t::lib::Koha::BackgroundJob::BatchTest->new->enqueue( >+ { size => 10, a => 'aaa', b => 'bbb' } ); >+ my $job = Koha::BackgroundJobs->find($job_id); >+ >+ C4::Context->_new_userenv(-1); >+ C4::Context->interface('opac'); >+ is( C4::Context->userenv, undef, "Userenv unset prior to calling process"); >+ is( C4::Context->interface, 'opac', "Interface set to opac prior to calling process"); >+ >+ $job->process(); >+ is_deeply( C4::Context->userenv, $job_context, "Userenv set from job context on process" ); >+ is_deeply( C4::Context->interface, 'intranet', "Interface set from job context on process" ); >+ >+ $schema->storage->txn_rollback; >+}; >+ > subtest 'decoded_data() and set_encoded_data() tests' => sub { > > plan tests => 3; >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 30889
:
135759
|
135760
|
135932
|
135933
|
135934
|
135935
|
135936
|
136294
|
136295
|
136296
|
136297
|
136298
|
136299
|
136375
|
136376
|
136784
|
136785
|
136786
|
136787
|
136788
|
136789
| 136790 |
136791
|
136792
|
136904
|
136948