From 66b42a13f22a9ccd86b99f4fb7900815d8710c87 Mon Sep 17 00:00:00 2001 From: Magnus Svensson Date: Sat, 9 Aug 2008 11:16:12 +0200 Subject: [PATCH] Make events_restart more stable by waiting for the server to be stopped before starting it again --- client/mysqltest.cc | 2 +- mysql-test/include/restart_mysqld.inc | 12 ++++++++++-- mysql-test/lib/mtr_io.pl | 14 +++++++++++++- mysql-test/mysql-test-run.pl | 27 +++++++++++++++++++++++---- 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 87557d46053..3176e764515 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -4174,7 +4174,7 @@ void do_shutdown_server(struct st_command *command) /* Check that server dies */ while(timeout--){ if (my_kill(0, pid) < 0){ - DBUG_PRINT("info", ("Sleeping, timeout: %d", timeout)); + DBUG_PRINT("info", ("Process %d does not exist anymore", pid)); break; } DBUG_PRINT("info", ("Sleeping, timeout: %d", timeout)); diff --git a/mysql-test/include/restart_mysqld.inc b/mysql-test/include/restart_mysqld.inc index 049827c7a81..30b6c7ce70f 100644 --- a/mysql-test/include/restart_mysqld.inc +++ b/mysql-test/include/restart_mysqld.inc @@ -1,13 +1,21 @@ -# Write file to make mysql-test-run.pl expect crash and restart +# Write file to make mysql-test-run.pl expect the "crash", but don't start +# it until it's told to --write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect -restart +wait EOF # Send shutdown to the connected server and give # it 10 seconds to die before zapping it shutdown_server 10; +# Check server is gone +--source include/wait_until_disconnected.inc + +# Write file to make mysql-test-run.pl start up the server again +--append_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +restart +EOF # Turn on reconnect --enable_reconnect diff --git a/mysql-test/lib/mtr_io.pl b/mysql-test/lib/mtr_io.pl index 6712c19b829..31c2e8ffb06 100644 --- a/mysql-test/lib/mtr_io.pl +++ b/mysql-test/lib/mtr_io.pl @@ -26,7 +26,7 @@ sub mtr_tonewfile($@); sub mtr_appendfile_to_file ($$); sub mtr_grab_file($); sub mtr_printfile($); - +sub mtr_lastlinefromfile ($); # Read a whole file, stripping leading and trailing whitespace. sub mtr_fromfile ($) { @@ -94,5 +94,17 @@ sub mtr_printfile($) { return; } +sub mtr_lastlinefromfile ($) { + my $file= shift; + my $text; + + open(FILE,"<",$file) or mtr_error("can't open file \"$file\": $!"); + while (my $line= ) + { + $text= $line; + } + close FILE; + return $text; +} 1; diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 4d9e44fe922..212cf07ef0e 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -3320,10 +3320,29 @@ sub check_expected_crash_and_restart { my $expect_file= "$opt_vardir/tmp/".$mysqld->name().".expect"; if ( -f $expect_file ) { - mtr_report("Crash was expected, file '$expect_file' exists"); - # Start server with same settings as last time - mysqld_start($mysqld, $mysqld->{'started_opts'}); - unlink($expect_file); + mtr_verbose("Crash was expected, file '$expect_file' exists"); + + while (1){ + + # If last line in expect file starts with "wait" + # sleep a little and try again, thus allowing the + # test script to control when the server should start + # up again + my $last_line= mtr_lastlinefromfile($expect_file); + if ($last_line =~ /^wait/ ) + { + mtr_verbose("Test says wait before restart"); + mtr_milli_sleep(100); + next; + } + + unlink($expect_file); + + # Start server with same settings as last time + mysqld_start($mysqld, $mysqld->{'started_opts'}); + + last; + } } return 1;