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 <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Jonathan Druart 2020-03-30 10:16:23 +02:00 committed by Martin Renvoize
parent 624a24b820
commit 9816e240aa
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
2 changed files with 10 additions and 3 deletions

View File

@ -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 (

View File

@ -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 : ""),