From 3254b9a860b0607f5cee942f84cbe2f6ee1b7db7 Mon Sep 17 00:00:00 2001 From: Fariha Shaikh Date: Fri, 12 Jun 2026 22:37:09 +0000 Subject: [PATCH] MDEV-40023 Error on unknown commands in check_expected_crash_and_restart Anchor the wait/restart regexes in mariadb-test-run.pl and call mtr_error() on anything else, so typos in expect files no longer fall through to a default restart. Chomp $last_line before matching and skip empty last lines to tolerate partial writes. restart_bindir is kept; it is used during development to test upgrades between two build trees. All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc. --- mysql-test/mariadb-test-run.pl | 37 +++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/mysql-test/mariadb-test-run.pl b/mysql-test/mariadb-test-run.pl index 6762086571f55..652852688c5f0 100755 --- a/mysql-test/mariadb-test-run.pl +++ b/mysql-test/mariadb-test-run.pl @@ -4852,30 +4852,47 @@ sub check_expected_crash_and_restart { # test script to control when the server should start # up again. Keep trying for up to 5s at a time. my $last_line= mtr_lastlinesfromfile($expect_file, 1); - if ($last_line =~ /^wait/ ) + chomp $last_line; + # Skip empty lines: partial writes to the expect file can be observed + # before the intended command is fully written. + next if $last_line =~ /^\s*$/; + # "wait" or "wait-" (tag is a diagnostic marker, usually the + # name of the test that wrote the file). + if ($last_line =~ /^wait(-\S+)?\s*$/) { mtr_verbose("Test says wait before restart") if $waits == 0; next; } delete $ENV{MTR_BINDIR_FORCED}; - # Ignore any partial or unknown command - next unless $last_line =~ /^restart/; # If last line begins "restart:", the rest of the line is read as # extra command line options to add to the restarted mysqld. - # Anything other than 'wait' or 'restart:' (with a colon) will - # result in a restart with original mysqld options. - if ($last_line =~ /restart_bindir\s+(\S+)(:.+)?/) { + # "restart" or "restart-" restarts with the original options. + # "restart_bindir [:opts]" additionally forces the mysqld + # binary to be picked from (used during development to + # test upgrades between two build trees). + # Anything else is treated as an error to catch typos in expect + # file commands (e.g. MDEV-39153). + if ($last_line =~ /^restart_bindir\s+(\S+)(:.+)?/) { $ENV{MTR_BINDIR_FORCED}= $1; if ($2) { my @rest_opt= split(' ', $2); $mysqld->{'restart_opts'}= \@rest_opt; } - } elsif ($last_line =~ /restart:(.+)/) { - my @rest_opt= split(' ', $1); - $mysqld->{'restart_opts'}= \@rest_opt; - } else { + } elsif ($last_line =~ /^restart:(.*)$/) { + # Empty tail (e.g. bare 'restart:') is equivalent to 'restart'. + my $rest_opt_str= $1; + if ($rest_opt_str =~ /\S/) { + my @rest_opt= split(' ', $rest_opt_str); + $mysqld->{'restart_opts'}= \@rest_opt; + } else { + delete $mysqld->{'restart_opts'}; + } + } elsif ($last_line =~ /^restart(-\S+)?\s*$/) { delete $mysqld->{'restart_opts'}; + } else { + mtr_error("Unknown command '$last_line' in expect file " . + "'$expect_file'"); } unlink($expect_file);