Bugzilla – Attachment 39007 Details for
Bug 13532
Unit test for Bug 13261
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 13532 - Unit tests for Bugg 13261
Bug-13532---Unit-tests-for-Bugg-13261.patch (text/plain), 7.65 KB, created by
Mark Tompsett
on 2015-05-09 16:33:07 UTC
(
hide
)
Description:
Bug 13532 - Unit tests for Bugg 13261
Filename:
MIME Type:
Creator:
Mark Tompsett
Created:
2015-05-09 16:33:07 UTC
Size:
7.65 KB
patch
obsolete
>From 9167dc8995b397eabb2e697174e3100db56592ef Mon Sep 17 00:00:00 2001 >From: Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> >Date: Wed, 7 Jan 2015 16:39:52 +0200 >Subject: [PATCH] Bug 13532 - Unit tests for Bugg 13261 > >This patch adds unit tests to check against timeout of: >checking in an Item from a debarred borrower > (a borrower whose koha.borrowers.debarred-column has year 9999) >timeouts the SIP-server. >This is because creating a new DateTime for year 9999 takes forever. >--- > t/db_dependent/SIP_ILS.t | 142 ++++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 140 insertions(+), 2 deletions(-) > >diff --git a/t/db_dependent/SIP_ILS.t b/t/db_dependent/SIP_ILS.t >index c9879dc..c22f651 100755 >--- a/t/db_dependent/SIP_ILS.t >+++ b/t/db_dependent/SIP_ILS.t >@@ -1,17 +1,49 @@ >-#!/usr/bin/perl >+#!/usr/bin/perl -d > # > # This Koha test module is a stub! > # Add more tests here!!! > > use strict; > use warnings; >+use Carp; > >-use Test::More tests => 4; >+use Test::More tests => 7; >+use t::lib::Mocks qw( mock_preference ); >+ >+use MARC::Record; >+use MARC::Field; > > BEGIN { > use_ok('C4::SIP::ILS'); >+ new C4::Context; > }; > >+use C4::Members; >+use Koha::Borrower::Debarments; >+use C4::Circulation; >+use C4::Biblio; >+use C4::Items; >+use Sip; >+ >+#Make the database handle non-autocommitting >+my $dbh = C4::Context->dbh; >+$dbh->{AutoCommit} = 0; >+$dbh->{RaiseError} = 1; >+ >+# Now, set a userenv >+C4::Context->_new_userenv('xxx'); >+C4::Context::set_userenv(0,0,0,'firstname','surname', 'CPL', 'Centerville', '', '', ''); >+t::lib::Mocks::mock_preference('dateformat', 'iso') unless C4::Context->preference('dateformat'); >+t::lib::Mocks::mock_preference('marcformat', 'MARC21') unless C4::Context->preference('marcformat'); >+t::lib::Mocks::mock_preference('DefaultClassificationSource', 'dewey') unless C4::Context->preference('DefaultClassificationSource'); >+t::lib::Mocks::mock_preference('item-level_itypes', '1'); #This forces Sip::ILS::Item to use itype-key to find the Items itype. >+ >+# Undef C4::Biblio::inverted_field_map to avoid problems introduced >+# by caching in TransformMarcToKoha >+undef $C4::Biblio::inverted_field_map; >+ >+testCheckinDebarredBorrower(); >+ > my $transaction = C4::SIP::ILS::Transaction::RenewAll->new(); > > $transaction->patron(my $patron = C4::SIP::ILS::Patron->new(23529000120056)); >@@ -25,3 +57,109 @@ $transaction2->patron(my $patron2 = C4::SIP::ILS::Patron->new("ABCDE12345")); > ok(!defined $patron2, "patron code: ABCDE12345 is invalid"); > > ok($transaction->do_renew_all(), "items renewed correctly"); >+ >+=head testCheckinDebarredBorrower >+ >+There is a nasty bug where checking in Items from a debarred Borrower takes dozens of seconds. >+In this time SIP-connections timeout. >+This test creates two Borrowers, two Items and two Checkouts, the first being a normal case, >+ and the second being the debarred case. >+First test: we check-in the normal Item and time the performance. >+Second test: we check-in the bugged Item and time the performance. >+Third test: we check if we can speedily instantiate a debarred Patron. >+=cut >+sub testCheckinDebarredBorrower { >+ my ($borrowers, $biblios, $items) = _init_testCheckinDebarredBorrower(); >+ >+ my $borrower = $biblios->[0]; >+ my $borrowerDebarred = $biblios->[1]; >+ my $item = $items->[0]; >+ my $ilsItem = new ILS::Item $item->{barcode}; >+ my $itemForDebarred = $items->[1]; >+ my $ilsItemForDebarred = new ILS::Item $itemForDebarred->{barcode}; >+ >+ #Test1 >+ my $startTime = time; >+ my $checkin = new ILS::Transaction::Checkin; >+ # BEGIN TRANSACTION >+ $checkin->item($ilsItem); >+ $checkin->do_checkin( C4::Context->userenv->{'branch'} , Sip::timestamp(DateTime->now(time_zone => C4::Context->tz())->iso8601()) ); >+ my $endTime = time; >+ ok(($endTime-$startTime) < 5, 'Check-in debarred borrower: Normally check-in happens in < 5 seconds.'); >+ >+ #Test2 >+ $startTime = time; >+ my $checkinForDebarred = new ILS::Transaction::Checkin; >+ # BEGIN TRANSACTION >+ $checkinForDebarred->item($ilsItemForDebarred); >+ $checkinForDebarred->do_checkin( C4::Context->userenv->{'branch'} , Sip::timestamp(DateTime->now(time_zone => C4::Context->tz())->iso8601()) ); >+ $endTime = time; >+ ok(($endTime-$startTime) < 5, "Check-in debarred borrower: Check-in for a debarred borrower doesn't take more than 5 seconds."); >+ >+ #Test3 >+ $startTime = time; >+ $checkinForDebarred->patron($patron = new ILS::Patron $ilsItemForDebarred->{patron}); >+ $endTime = time; >+ ok(($endTime-$startTime) < 5, "Check-in debarred borrower: Instantiating a debarred borrower takes less than 5 seconds."); >+} >+sub _init_testCheckinDebarredBorrower { >+ my $borrowernumberDebarred = C4::Members::AddMember( >+ cardnumber => 'asdAasdasdasd', >+ firstname => 'Asd', >+ surname => 'Asdasd', >+ categorycode => 'S', >+ branchcode => 'CPL', >+ dateofbirth => '1985-10-12', >+# dateexpiry => '9999-12-31', #IF we enable dateexpiry for year 9999, we get the same issue for borrowers than we get here for Issues. >+ userid => 'asd123' >+ ); >+ my $borrowernumber = C4::Members::AddMember( >+ cardnumber => 'asdAdebarred', >+ firstname => 'De', >+ surname => 'Barred', >+ categorycode => 'S', >+ branchcode => 'CPL', >+ dateofbirth => '1985-10-12', >+# dateexpiry => '9999-12-31', >+ userid => 'debarred' >+ ); >+ my $borrowerDebarred = C4::Members::GetMember(borrowernumber => $borrowernumberDebarred); >+ my $borrower = C4::Members::GetMember(borrowernumber => $borrowernumber); >+ Koha::Borrower::Debarments::AddDebarment({ >+ borrowernumber => $borrowernumberDebarred, >+# expiration => '', >+# type => '', >+ comment => 'TESTING DEBARRMENT SETTING', >+ }); >+ >+ # Generate a record with just the ISBN >+ my $marc_record = MARC::Record->new; >+ $marc_record->append_fields( MARC::Field->new('020','','','a' => '0590353403') ); >+ $marc_record->append_fields( MARC::Field->new('245','','','a' => 'Debarred test biblio') ); >+ # Add the record to the DB >+ my( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $marc_record, '' ); >+ my $biblio = C4::Biblio::GetBiblioData( $biblionumber ); >+ >+ #Generate Items >+ my $itemBarcodeForDebarred = 'asdNasdasdasd1'; >+ my $itemBarcode2 = 'asdNdebarreda2'; >+ my ($item_bibnum, $item_bibitemnum, $itemnumberForDebarred, $itemnumber2); >+ ($item_bibnum, $item_bibitemnum, $itemnumberForDebarred) = C4::Items::AddItem({ itemtype => 'BK', itype => 'BK', homebranch => 'CPL', holdingbranch => 'CPL', barcode => $itemBarcodeForDebarred } , $biblionumber); >+ ($item_bibnum, $item_bibitemnum, $itemnumber2) = C4::Items::AddItem({ itemtype => 'BK', itype => 'BK', homebranch => 'CPL', holdingbranch => 'CPL', barcode => $itemBarcode2 } , $biblionumber); >+ my $itemForDebarred = C4::Items::GetItem($itemnumberForDebarred); >+ my $item2 = C4::Items::GetItem($itemnumber2); >+ >+ #Checkout Items >+ C4::Circulation::AddIssue($borrowerDebarred, $itemBarcodeForDebarred); >+ C4::Circulation::AddIssue($borrower, $itemBarcode2); >+ >+ #Update borrower references to the DB, since they have been modified. >+ $borrowerDebarred = C4::Members::GetMember(borrowernumber => $borrowernumberDebarred); >+ $borrower = C4::Members::GetMember(borrowernumber => $borrowernumber); >+ >+ return ([$borrower, $borrowerDebarred],[$biblio],[$item2, $itemForDebarred]); >+} >+ >+ >+# End transaction >+$dbh->rollback; >-- >2.1.4
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 13532
:
35018
|
35019
|
35021
|
35036
| 39007