This patch adds a unit test for the 'enqueue' part of the bug. We check
that the mocked context (and interface) are recorded with the job
enqueue in the new 'context' field.
We do not yet test the 'process' end, where we then read the context out
and set the job Context from it.
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
The goal is to be able to build a database handler (dbh) and to execute
queries without loading unnecessary stuff. This will be useful to reduce
memory usage of daemons that need to check the database
periodically
The patch provides a new method Koha::Database::dbh which returns a
database handler without loading the DBIx::Class schema. This method is
also used by DBIx::Class, so whether you use DBI or DBIx::Class, the
same method is used to initialize the connection.
The patch also moves some code in order to avoid loading C4::Context:
- C4::Context::timezone moves to Koha::Config
- C4::Context::db_scheme2dbi moves to Koha::Database
To measure memory usage I used the following commands:
* before the patch:
perl -MKoha::Database \
-E 'Koha::Database->schema->storage->dbh->do("select 1");' \
-E '$|=1; say $$; sleep 2' \
| while read pid; do ps -p $pid -o rss=; done
* after the patch:
perl -MKoha::Database \
-E 'Koha::Database->dbh->do("select 1");' \
-E '$|=1; say $$; sleep 2' \
| while read pid; do ps -p $pid -o rss=; done
It will give you the RSS (Resident Set Size) of the perl process in kB
What I get:
* before the patch: between 96.9MB and 97.2MB
* after the patch: between 17.8MB and 18.2MB
Note that if a timezone is configured (either from $KOHA_CONF or
TZ environment variable), Koha will load DateTime::Timezone to check if
it's valid, and it increases RSS to 36MB
Another interesting metric is the number of modules loaded:
* before the patch:
perl -MKoha::Database \
-E 'Koha::Database->schema->storage->dbh;' \
-E 'say scalar keys %INC'
Result: 567
* after the patch:
perl -MKoha::Database \
-E 'Koha::Database->dbh;' \
-E 'say scalar keys %INC'
Result: 51
Test plan:
1. Apply the patch & restart starman
2. Make sure Koha is still ok (ie. can access the database, does not
have encoding issues, ...)
3. Run the tests in t/Context.t, t/Koha/Config.t,
t/db_dependent/Koha/Database.t, t/timezones.t
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
On bug 17591 we discovered that there was something weird going on with
the way we export and use subroutines/modules.
This patch tries to standardize our EXPORT to use EXPORT_OK only.
That way we will need to explicitely define the subroutine we want to
use from a module.
This patch is a squashed version of:
Bug 17600: After export.pl
Bug 17600: After perlimport
Bug 17600: Manual changes
Bug 17600: Other manual changes after second perlimports run
Bug 17600: Fix tests
And a lot of other manual changes.
export.pl is a dirty script that can be found on bug 17600.
"perlimport" is:
git clone https://github.com/oalders/App-perlimports.git
cd App-perlimports/
cpanm --installdeps .
export PERL5LIB="$PERL5LIB:/kohadevbox/koha/App-perlimports/lib"
find . \( -name "*.pl" -o -name "*.pm" \) -exec perl App-perlimports/script/perlimports --inplace-edit --no-preserve-unused --filename {} \;
The ideas of this patch are to:
* use EXPORT_OK instead of EXPORT
* perltidy the EXPORT_OK list
* remove '&' before the subroutine names
* remove some uneeded use statements
* explicitely import the subroutines we need within the controllers or
modules
Note that the private subroutines (starting with _) should not be
exported (and not used from outside of the module except from tests).
EXPORT vs EXPORT_OK (from
https://www.thegeekstuff.com/2010/06/perl-exporter-examples/)
"""
Export allows to export the functions and variables of modules to user’s namespace using the standard import method. This way, we don’t need to create the objects for the modules to access it’s members.
@EXPORT and @EXPORT_OK are the two main variables used during export operation.
@EXPORT contains list of symbols (subroutines and variables) of the module to be exported into the caller namespace.
@EXPORT_OK does export of symbols on demand basis.
"""
If this patch caused a conflict with a patch you wrote prior to its
push:
* Make sure you are not reintroducing a "use" statement that has been
removed
* "$subroutine" is not exported by the C4::$MODULE module
means that you need to add the subroutine to the @EXPORT_OK list
* Bareword "$subroutine" not allowed while "strict subs"
means that you didn't imported the subroutine from the module:
- use $MODULE qw( $subroutine list );
You can also use the fully qualified namespace: C4::$MODULE::$subroutine
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
There's no POD. This patch adds it. I wrote it as part of bug 28615 but
then it took another direction, so submitting here.
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
To test:
1. Run the new unit test: t/db_dependent/Koha/Template/Plugin/Registers.t
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Remove a few last references to branchprinter, mostly from tests.
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This patch adds a new method mock_userenv from t::lib::Mocks in order to
simplify the mock of the userenv.
Test plan:
prove all the test files modified by this patch
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Couldn't make the tests pass using Test::DBIx::Class, so reverted to the "usual way" since these tests are
in db_dependent anyway.
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
C4::Context::_new_dbh does not exist anymore.
Koha::Database::_new_schema should be mocked instead.
Will fix:
- t/00-load.t
- t/Breeding.t
- t/ImportBatch.t
- t/Message.t
- t/Overdues.t
- t/Prices.t
- t/RotatingCollections.t
- t/Search.t
- t/SuggestionEngine_AuthorityFile.t
- t/XSLT.t
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This patch suggests to create a routine to mock C4::Context::_new_dbh.
NOTE: Works the same with and without this secondary patch.
koha-qa tests fine. Less cutting and pasting in the future.
Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
t::lib::Mocks::Context tried to deal with preferences but did not manage
to.
This patch removes this module and add 2 routines in t::lib::Mocks in
order to mock C4::context->preference and C4::Context->config.
To test:
===START t/test.pl===
use Modern::Perl;
use t::lib::Mocks;
use C4::Context;
say "initial value for version: " . C4::Context->preference('Version');
say "initial value for language: " . C4::Context->preference('language');
t::lib::Mocks::mock_preference('Version', "new version for testing");
say "version is mocked with: " . C4::Context->preference('Version');
say "language is not yet mocked: " . C4::Context->preference('language');
t::lib::Mocks::mock_preference('language', 'new langage for testing');
t::lib::Mocks::mock_preference('Version', 'another version for testing');
say "version is mocked with another value: " . C4::Context->preference('Version');
say "language is finally mocked: " . C4::Context->preference('language');
===END===
Try to execute this file and check that the output is consistent.
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>