List:Commits« Previous MessageNext Message »
From:John H. Embretsen Date:January 26 2011 1:36pm
Subject:bzr commit into mysql-5.1 branch (john.embretsen:3554) Bug#56817
View as plain text  
#At file:///export/home/tmp/je159969/mysql-dev/bzr-repos/mysql-5.1-bug56895/ based on revid:john.embretsen@stripped

 3554 John H. Embretsen	2011-01-26
      Fix for Bug#56817 - mysqlhotcopy tests fail when DBI and DBD-mysql perl modules are not found
      This patch implements a check for such modules at runtime. If modules are not found or unable to load, the test is skipped with the following message:
      
      [ skipped ]  Test needs Perl modules DBI and DBD::mysql
      
      Checks are done via a helper Perl script which looks for the module in a runtime environment that is as similar to that of the mysqlhotcopy script as possible.
      The helper script tells mysql-test about the result by updating certain values in a test table created for the purpose.
      See comments in added files (have_dbi_dbd-mysql.inc and checkDBI_DBD-mysql.pl) for details.
      The patch also removes the mysqlhotcopy tests from the list of disabled tests.

    added:
      mysql-test/include/have_dbi_dbd-mysql.inc
      mysql-test/std_data/checkDBI_DBD-mysql.pl
    modified:
      mysql-test/include/mysqlhotcopy.inc
      mysql-test/t/disabled.def
=== added file 'mysql-test/include/have_dbi_dbd-mysql.inc'
--- a/mysql-test/include/have_dbi_dbd-mysql.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/include/have_dbi_dbd-mysql.inc	2011-01-26 13:36:30 +0000
@@ -0,0 +1,78 @@
+# Originally created by John Embretsen, 2011-01-26.
+# 
+# Checks for the existence of Perl modules DBI and DBD::mysql as seen from the
+# perl installation used by "external" executable perl scripts.
+# If either module is not found, the test will be skipped.
+#
+# For use in tests that call perl scripts that use these modules.
+#
+# Note that if there are multiple perl installations and not all have the
+# required modules, this check may fail even if the perl in path does have
+# the modules available. This may happen if the perl at mysql-test perl's 
+# shebang (#!/usr/bin/perl) does not have these modules, and the called script
+# is called without specifying the perl interpreter. However, this will be 
+# a correct result in cases where a test calls a script with a similar shebang.
+#
+################################################################################
+
+
+# We jump through some hoops since there is no direct way to check if an 
+# external command went OK or not from a mysql-test file:
+#
+#   - In theory, we could do as simple as "exec perl -MDBI -MDBD::mysql -e 1",
+#     however we cannot check the result (exit code) from within a test script. 
+#     Also, this may not yield the same result as other uses of perl due to the 
+#     shebang issue mentioned above.
+#   - Instead we use a separate helper perl script that checks for the modules.
+#   - If the modules are found, the perl code connects to the test database
+#     and updates a certain value in a certain table ("checkPerl").
+#     This is done because there is apparently no direct way to transfer 
+#     information from perl to the test script itself.
+
+--disable_query_log
+--disable_result_log
+--disable_warnings
+
+DROP TABLE IF EXISTS checkPerl;
+
+# In this table, column foundModules indicates the success of the module check.
+# 0 means success and all other values mean failure.
+CREATE TABLE checkPerl (
+  id INT,
+  foundModules INT 
+);
+
+# Insert a non-zero value into the table to have an easy if-check afterwards.
+# The value will be updated separately if the modules are found.
+INSERT INTO checkPerl VALUES (1, 1);
+
+# We do not use embedded perl in this script because that would not have yielded
+# correct results for a situation where a script is called like "scriptname"
+# (instead of "perl scriptname") and the shebang points to a specific perl that
+# may be different than the perl in PATH.
+#
+# Instead, we call a separate helper script which check for the modules in its
+# own environment. We call it without "perl" in front.
+
+# First, make sure the perl script is executable:
+--chmod 0755 $MYSQLTEST_VARDIR/std_data/checkDBI_DBD-mysql.pl
+
+# Then execute the script:
+--exec $MYSQLTEST_VARDIR/std_data/checkDBI_DBD-mysql.pl
+
+# By now the value of "foundModules" should have been set to 0 if there was 
+# success. Skip test if modules not found, i.e. "foundModules" value was not 0.
+
+if (`SELECT foundModules FROM checkPerl WHERE id != 0`)
+{
+    DROP TABLE checkPerl;
+    skip Test needs Perl modules DBI and DBD::mysql;
+}
+
+
+DROP TABLE checkPerl;
+
+--enable_query_log
+--enable_result_log
+--enable_warnings
+

=== modified file 'mysql-test/include/mysqlhotcopy.inc'
--- a/mysql-test/include/mysqlhotcopy.inc	2011-01-14 13:50:39 +0000
+++ b/mysql-test/include/mysqlhotcopy.inc	2011-01-26 13:36:30 +0000
@@ -4,12 +4,26 @@
 
 --source include/not_windows.inc
 --source include/not_embedded.inc
+--source include/have_dbi_dbd-mysql.inc
 
 if (!$MYSQLHOTCOPY)
 {
+  # Fail the test if the mysqlhotcopy script is missing.
+  # If the tool's location changes, mysql-test-run.pl must be updated to
+  # reflect this (look for "MYSQLHOTCOPY").
   die due to missing mysqlhotcopy tool;
 }
 
+# NOTE (johnemb, 2011-01-26):
+#       In this test mysqlhotcopy (a perl script) is executed as a standalone
+#       executable, i.e. not necessarily using the perl interpreter in PATH,
+#       because that is how the documentation demonstrates it.
+#
+#       We include have_dbi_dbd-mysql.inc above so that the test will
+#       be skipped if Perl modules required by the mysqlhotcopy tool are not
+#       found when the script is run this way.
+
+
 let $MYSQLD_DATADIR= `SELECT @@datadir`;
 --disable_warnings
 DROP DATABASE IF EXISTS hotcopy_test;

=== added file 'mysql-test/std_data/checkDBI_DBD-mysql.pl'
--- a/mysql-test/std_data/checkDBI_DBD-mysql.pl	1970-01-01 00:00:00 +0000
+++ b/mysql-test/std_data/checkDBI_DBD-mysql.pl	2011-01-26 13:36:30 +0000
@@ -0,0 +1,72 @@
+#!/usr/bin/perl
+
+################################################################################
+#
+# This perl script checks for availability of the Perl modules DBI and
+# DBD::mysql using the "current" perl interpreter.
+#
+# Useful for test environment checking before testing executable perl scripts
+# in the MySQL Server distribution.
+#
+# NOTE: The "shebang" on the first line of this script should always point to
+#       /usr/bin/perl, so that we can use this script to check whether or not we
+#       support running perl scripts with such a shebang without specifying the
+#       perl interpreter on the command line. Such a script is mysqlhotcopy.
+#
+#       When run as "checkDBI_DBD-mysql.pl" the shebang line will be evaluated
+#       and used. When run as "perl checkDBI_DBD-mysql.pl" the shebang line is
+#       not used.
+#
+# NOTE: This script will, if modules are found, try to connect to the test
+#       database and update a value in a table called "checkPerl". This table
+#       must be created in advance by scripts calling this script, otherwise
+#       an error will occur:
+#
+#         CREATE TABLE checkPerl (id INT, foundModules INT);
+#         # Insert the value 1 for "foundModules" to indicate no success.
+#         # The value will be updated to 0 in the called perl script if success.
+#         INSERT INTO checkPerl VALUES (1, 1);
+#
+#       The calling script is also responsible for cleaning up after use:
+#
+#         DROP TABLE checkPerl
+#
+# See mysql-test/include/have_dbi_dbd-mysql.inc for example use of this script.
+# This script should be executable for the user running MTR.
+#
+################################################################################
+
+BEGIN {
+    # By using eval inside BEGIN we can suppress warnings and continue after.
+    # We need to catch "Can't locate" as well as "Can't load" errors.
+    eval{
+        $FOUND_DBI=0;
+        $FOUND_DBD_MYSQL=0;
+
+        # Check for DBI module:
+        $FOUND_DBI=1 if require DBI;
+
+        # Check for DBD::mysql module
+        $FOUND_DBD_MYSQL=1 if require DBD::mysql;
+    };
+};
+
+if ($FOUND_DBI && $FOUND_DBD_MYSQL) {
+    # Connect to the test database in order to report success:
+    my $dbh = DBI->connect("dbi:mysql:database=test;mysql_socket=$ENV{'MASTER_MYSOCK'}",
+                         'root', '', 
+       {
+           RaiseError => 1,
+           PrintError => 0,
+           AutoCommit => 1,
+       }
+    );
+
+    # Update the value indicating success (0 means success):
+    my $sth = $dbh->prepare("UPDATE checkPerl SET foundModules = 0 WHERE id = 1");
+    $sth->execute();
+    $dbh->disconnect();
+}
+
+1;
+

=== modified file 'mysql-test/t/disabled.def'
--- a/mysql-test/t/disabled.def	2010-11-18 10:40:57 +0000
+++ b/mysql-test/t/disabled.def	2011-01-26 13:36:30 +0000
@@ -11,7 +11,5 @@
 ##############################################################################
 kill                     : Bug#37780 2008-12-03 HHunger need some changes to be robust enough for pushbuild.
 query_cache_28249        : Bug#43861 2009-03-25 main.query_cache_28249 fails sporadically
-main.mysqlhotcopy_myisam : Bug#56817 2010-10-21 anitha mysqlhotcopy* fails
-main.mysqlhotcopy_archive: Bug#56817 2010-10-21 anitha mysqlhotcopy* fails
 log_tables-big           : Bug#48646 2010-11-15 mattiasj report already exists
 read_many_rows_innodb    : Bug#37635 2010-11-15 mattiasj report already exists


Attachment: [text/bzr-bundle] bzr/john.embretsen@oracle.com-20110126133630-52ravtiyy8ggn44g.bundle
Thread
bzr commit into mysql-5.1 branch (john.embretsen:3554) Bug#56817John H. Embretsen26 Jan