From 9816e240aa5d629bca98d9f0cb3e327bf2bc5a77 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 30 Mar 2020 10:16:23 +0200 Subject: [PATCH] Bug 25018: Use new KOHA_TESTING envvar to detect environment testing In some tests we want to know if we are in a testing environment. When run the usual way, our trick works, the perl interpreter matches 'prove': $ENV{_} eq 'prove' In other situations, we have the KOHA_NO_TABLE_LOCKS environment variables, for the SendCirculationAlert race conditions (see bug 15854 and bug 18364). For unknown reasons, Jenkins runs the tests with /usr/bin/perl. This patch suggests to rename KOHA_NO_TABLE_LOCKS and use KOHA_TESTING instead, when prove is not used (or not correctly detected as it it the case for Jenkins) Signed-off-by: Martin Renvoize --- C4/Circulation.pm | 2 +- Koha/Database.pm | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index c6f3cf9d75..3374ebef79 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3498,7 +3498,7 @@ sub SendCirculationAlert { # LOCK TABLES is not transaction-safe and implicitly commits any active transaction before attempting to lock the tables. # If the LOCK/UNLOCK statements are executed from tests, the current transaction will be committed. # To avoid that we need to guess if this code is execute from tests or not (yes it is a bit hacky) - my $do_not_lock = ( exists $ENV{_} && $ENV{_} =~ m|prove| ) || $ENV{KOHA_NO_TABLE_LOCKS}; + my $do_not_lock = ( exists $ENV{_} && $ENV{_} =~ m|prove| ) || $ENV{KOHA_TESTING}; for my $mtt (@transports) { my $letter = C4::Letters::GetPreparedLetter ( diff --git a/Koha/Database.pm b/Koha/Database.pm index ab325cc513..6d8a1e2556 100644 --- a/Koha/Database.pm +++ b/Koha/Database.pm @@ -76,7 +76,10 @@ sub _new_schema { %encoding_attr = ( mysql_enable_utf8 => 1 ); $encoding_query = "set NAMES 'utf8mb4'"; $tz_query = qq(SET time_zone = "$tz") if $tz; - if ( ( exists $ENV{_} && $ENV{_} =~ m|prove| ) or C4::Context->config('strict_sql_modes') ) { + if ( C4::Context->config('strict_sql_modes') + || ( exists $ENV{_} && $ENV{_} =~ m|prove| ) + || $ENV{KOHA_TESTING} + ) { $sql_mode_query = q{SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'}; } else { $sql_mode_query = q{SET sql_mode = 'IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'}; @@ -87,7 +90,11 @@ sub _new_schema { $tz_query = qq(SET TIME ZONE = "$tz") if $tz; } - my $RaiseError = ( $ENV{DEBUG} || exists $ENV{_} && $ENV{_} =~ m|prove| ) ? 1 : 0; + my $RaiseError = ( + $ENV{DEBUG} + || $ENV{KOHA_TESTING} + || exists $ENV{_} && $ENV{_} =~ m|prove| + ) ? 1 : 0; my $schema = Koha::Schema->connect( { dsn => "dbi:$db_driver:database=$db_name;host=$db_host;port=$db_port".($tls_options? $tls_options : ""), -- 2.39.5