If Koha::Database->schema gets called before use Test::DBIx::Class The DB connection from $KOHA_CONF is cached. This happens most of the time because when C4::Context and friends are loaded (in compile-time?), they already access the DB. After Test::DBIx::Class is instantiated and hooks put in place to overload Koha::Schema connection, those hooks are never called due to getting the old connection from cache. This feature introduces a test case to replicate the behaviour and shows how flushing the connection cache solves the problem.
Created attachment 61186 [details] [review] Bug 18286 - Test::DBIx::Class connection/schema is shadowed by a cached connection/schema If Koha::Database->schema gets called before use Test::DBIx::Class The DB connection from $KOHA_CONF is cached. This happens most of the time because when C4::Context and friends are loaded (in compile-time?), they already access the DB. After Test::DBIx::Class is instantiated and hooks put in place to overload Koha::Schema connection, those hooks are never called due to getting the old connection from cache. This feature introduces a test case to replicate the behaviour and shows how flushing the connection cache solves the problem.
Prior to this patch, for example t/Koha.t fails due to this caching issue.
comment from qa tools: FAIL t/db_dependent/01-test_dbic.t FAIL critic Code before strictures are enabled at line 4, column 1. See page 429 of PBP. "$schema" is declared but not used at line 18, column 3. Unused variables clutter code and make it harder to read. Expression form of "eval" at line 77, column 3. See page 161 of PBP.
Do we need a t/etc/schema file here?
Created attachment 62963 [details] [review] Bug 18286: Test::DBIx::Class connection/schema is shadowed by a cached connection/schema If Koha::Database->schema gets called before use Test::DBIx::Class The DB connection from $KOHA_CONF is cached. This happens most of the time because when C4::Context and friends are loaded (in compile-time?), they already access the DB. After Test::DBIx::Class is instantiated and hooks put in place to overload Koha::Schema connection, those hooks are never called due to getting the old connection from cache. This feature introduces a test case to replicate the behaviour and shows how flushing the connection cache solves the problem. Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Created attachment 62964 [details] [review] Bug 18286: [Follow-up] Add t/etc/schema.pl We need this file here already. Copied from bug 18226 and adjusted in order to keep qa tools quiet. Test plan: Run t/db_dependent/01-test_dbic.t again. Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Created attachment 62965 [details] [review] Bug 18286: [QA Follow-up] Fix some warnings from qa tools [1] Resolve warning on variable assignment before use strict. [2] Remove unused $schema variable. [3] Remove eval expression construction. Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Created attachment 62966 [details] [review] Bug 18286: [Follow-up] Remove assumption on branch count A test in db_dependent should not make assumptions on the number of branches in the database. If you need one, create one. Removing the assumption of a non-zero count. Removing the library count statement outside the subtest. Replacing C4::Context by Koha::Database. Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Created attachment 64004 [details] [review] Bug 18286: Test::DBIx::Class connection/schema is shadowed by a cached connection/schema If Koha::Database->schema gets called before use Test::DBIx::Class The DB connection from $KOHA_CONF is cached. This happens most of the time because when C4::Context and friends are loaded (in compile-time?), they already access the DB. After Test::DBIx::Class is instantiated and hooks put in place to overload Koha::Schema connection, those hooks are never called due to getting the old connection from cache. This feature introduces a test case to replicate the behaviour and shows how flushing the connection cache solves the problem. Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Created attachment 64005 [details] [review] Bug 18286: [Follow-up] Add t/etc/schema.pl We need this file here already. Copied from bug 18226 and adjusted in order to keep qa tools quiet. Test plan: Run t/db_dependent/01-test_dbic.t again. Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Created attachment 64006 [details] [review] Bug 18286: [QA Follow-up] Fix some warnings from qa tools [1] Resolve warning on variable assignment before use strict. [2] Remove unused $schema variable. [3] Remove eval expression construction. Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Created attachment 64007 [details] [review] Bug 18286: [Follow-up] Remove assumption on branch count A test in db_dependent should not make assumptions on the number of branches in the database. If you need one, create one. Removing the assumption of a non-zero count. Removing the library count statement outside the subtest. Replacing C4::Context by Koha::Database. Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Pushed to master for 17.11, thanks to everybody involved!
Enhancement not pushed to 17.05.x