Bugzilla – Attachment 35018 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 test for Bugg 13261
Bug-13532---Unit-test-for-Bugg-13261.patch (text/plain), 6.69 KB, created by
Olli-Antti Kivilahti
on 2015-01-07 15:02:28 UTC
(
hide
)
Description:
Bug 13532 - Unit test for Bugg 13261
Filename:
MIME Type:
Creator:
Olli-Antti Kivilahti
Created:
2015-01-07 15:02:28 UTC
Size:
6.69 KB
patch
obsolete
>From fd2b0a7ef09e4960085f8c13f3c63a56d8ad20cf 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 test for Bugg 13261 > >This patch adds a unit test 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 | 125 +++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 123 insertions(+), 2 deletions(-) > >diff --git a/t/db_dependent/SIP_ILS.t b/t/db_dependent/SIP_ILS.t >index daf1c29..1026251 100755 >--- a/t/db_dependent/SIP_ILS.t >+++ b/t/db_dependent/SIP_ILS.t >@@ -1,4 +1,4 @@ >-#!/usr/bin/perl >+#!/usr/bin/perl -d > # > # This Koha test module is a stub! > # Add more tests here!!! >@@ -6,14 +6,36 @@ > use strict; > use warnings; > >-use Test::More tests => 4; >+use Test::More tests => 7; >+ >+use MARC::Record; >+use MARC::Field; > > BEGIN { > use FindBin; > use lib "$FindBin::Bin/../../C4/SIP"; > 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', 'Joensuun pääkirjasto', '', '', ''); >+ >+testCheckinDebarredBorrower(); >+ > my $transaction = ILS::Transaction::RenewAll->new(); > > $transaction->patron(my $patron = ILS::Patron->new(23529000120056)); >@@ -27,3 +49,102 @@ $transaction2->patron(my $patron2 = 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. >+=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 >+ $checkin->item($ilsItemForDebarred); >+ $checkin->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."); >+} >+sub _init_testCheckinDebarredBorrower { >+ my $borrowernumberDebarred = C4::Members::AddMember( >+ cardnumber => 'asdAasdasdasd', >+ firstname => 'Asd', >+ surname => 'Asdasd', >+ categorycode => 'PT', >+ 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 => 'PT', >+ 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({ itype => 'BK', homebranch => 'CPL', holdingbranch => 'CPL', barcode => $itemBarcodeForDebarred } , $biblionumber); >+ ($item_bibnum, $item_bibitemnum, $itemnumber2) = C4::Items::AddItem({ 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; >\ No newline at end of file >-- >1.7.9.5
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