[DRE-commits] [SCM] ruby-moneta.git branch, master, updated. debian/0.6.0-4-16-g741fce5

Jérémy Bobbio lunar at debian.org
Wed Mar 27 15:23:40 UTC 2013


The following commit has been merged in the master branch:
commit bc626b949bf29748655039eca97d81966ed84dc8
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Mon Mar 25 17:48:59 2013 +0000

    Use a test MySQL server to run the tests
    
    `debian/setup-mysql.sh` was borrowed from the php5 package.

diff --git a/debian/ruby-tests.rb b/debian/ruby-tests.rb
index f8c48f9..67df620 100644
--- a/debian/ruby-tests.rb
+++ b/debian/ruby-tests.rb
@@ -1,3 +1,38 @@
+require 'tmpdir'
+require 'socket'
+
+mysql_port = nil
+(1025..3600).to_a.shuffle.each do |port|
+  begin
+    s = TCPSocket.new 'localhost', port
+    s.close
+  rescue Errno::ECONNREFUSED
+    mysql_port = port
+    break
+  end
+end
+unless mysql_port
+  $stderr.puts "Unable to find a free TCP port to start the MySQL server."
+  exit 1
+end
+
+mysql_datadir = Dir.mktmpdir('moneta')
+
+started = system(File.expand_path('../setup-mysql.sh', __FILE__),
+                 mysql_port.to_s, mysql_datadir, 'start')
+unless started
+  $stderr.puts "Unable to start the test MySQL server."
+  exit 1
+end
+
+at_exit do
+  system File.expand_path('../setup-mysql.sh', __FILE__),
+         mysql_port.to_s, mysql_datadir, 'stop'
+  FileUtils.remove_entry_secure mysql_datadir
+end
+
+ENV['MYSQL_TEST_SOCKET'] = File.join(mysql_datadir, 'mysql.sock')
+
 require 'rake'
 app = Rake.application
 app.init
diff --git a/debian/setup-mysql.sh b/debian/setup-mysql.sh
new file mode 100755
index 0000000..491af10
--- /dev/null
+++ b/debian/setup-mysql.sh
@@ -0,0 +1,81 @@
+#!/bin/sh
+
+set -eu
+
+[ $# -ge 2 ] || {
+    echo "Usage: debian/setup-mysql.sh port data-dir" >&2
+    exit 1
+}
+
+# CLI arguments #
+port=$1
+datadir=$2
+action=${3:-start}
+if [ "$(id -u)" -eq 0 ]; then
+    user="mysql"
+else
+    user="$(whoami)"
+fi
+
+# Some vars #
+
+socket=$datadir/mysql.sock
+# Commands:
+mysqladmin="mysqladmin --no-defaults --user root --port $port --host 127.0.0.1 --socket=$socket --no-beep"
+mysqld="/usr/sbin/mysqld --no-defaults --user=$user --bind-address=127.0.0.1 --port=$port --socket=$socket --datadir=$datadir"
+
+# Main code #
+
+if [ "$action" = "stop" ]; then
+    $mysqladmin shutdown
+    exit
+fi
+
+rm -rf $datadir
+mkdir -p $datadir
+chmod go-rx $datadir
+chown $user: $datadir
+
+mysql_install_db --no-defaults --user=$user --datadir=$datadir --rpm --force
+
+tmpf=$(mktemp)
+cat > "$tmpf" <<EOF
+USE mysql;
+UPDATE user SET password=PASSWORD('') WHERE user='root';
+FLUSH PRIVILEGES;
+EOF
+
+$mysqld --bootstrap --skip-grant-tables < "$tmpf"
+
+unlink "$tmpf"
+
+# Start the daemon
+$mysqld &
+
+pid=$!
+
+# Wait for the server to be actually available
+c=0;
+while ! nc -z 127.0.0.1 $port; do
+    c=$(($c+1));
+    sleep 3;
+    if [ $c -gt 20 ]; then
+	echo "Timed out waiting for mysql server to be available" >&2
+	if [ "$pid" ]; then
+	    kill $pid || :
+	    sleep 2
+	    kill -s KILL $pid || :
+	fi
+	exit 1
+    fi
+done
+
+# Check if the server is running
+$mysqladmin status
+
+for db in moneta moneta_activerecord1 moneta_activerecord2; do
+    # Drop the database if it exists
+    $mysqladmin --force --silent drop $db || true
+    # Create new empty databases
+    $mysqladmin create $db
+done

-- 
ruby-moneta.git



More information about the Pkg-ruby-extras-commits mailing list