Skip to content

Commit 87bcaaa

Browse files
FarihaISgkodinov
authored andcommitted
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.
1 parent 5241bae commit 87bcaaa

1 file changed

Lines changed: 27 additions & 10 deletions

File tree

mysql-test/mariadb-test-run.pl

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4852,30 +4852,47 @@ sub check_expected_crash_and_restart {
48524852
# test script to control when the server should start
48534853
# up again. Keep trying for up to 5s at a time.
48544854
my $last_line= mtr_lastlinesfromfile($expect_file, 1);
4855-
if ($last_line =~ /^wait/ )
4855+
chomp $last_line;
4856+
# Skip empty lines: partial writes to the expect file can be observed
4857+
# before the intended command is fully written.
4858+
next if $last_line =~ /^\s*$/;
4859+
# "wait" or "wait-<tag>" (tag is a diagnostic marker, usually the
4860+
# name of the test that wrote the file).
4861+
if ($last_line =~ /^wait(-\S+)?\s*$/)
48564862
{
48574863
mtr_verbose("Test says wait before restart") if $waits == 0;
48584864
next;
48594865
}
48604866
delete $ENV{MTR_BINDIR_FORCED};
48614867

4862-
# Ignore any partial or unknown command
4863-
next unless $last_line =~ /^restart/;
48644868
# If last line begins "restart:", the rest of the line is read as
48654869
# extra command line options to add to the restarted mysqld.
4866-
# Anything other than 'wait' or 'restart:' (with a colon) will
4867-
# result in a restart with original mysqld options.
4868-
if ($last_line =~ /restart_bindir\s+(\S+)(:.+)?/) {
4870+
# "restart" or "restart-<tag>" restarts with the original options.
4871+
# "restart_bindir <path>[:opts]" additionally forces the mysqld
4872+
# binary to be picked from <path> (used during development to
4873+
# test upgrades between two build trees).
4874+
# Anything else is treated as an error to catch typos in expect
4875+
# file commands (e.g. MDEV-39153).
4876+
if ($last_line =~ /^restart_bindir\s+(\S+)(:.+)?/) {
48694877
$ENV{MTR_BINDIR_FORCED}= $1;
48704878
if ($2) {
48714879
my @rest_opt= split(' ', $2);
48724880
$mysqld->{'restart_opts'}= \@rest_opt;
48734881
}
4874-
} elsif ($last_line =~ /restart:(.+)/) {
4875-
my @rest_opt= split(' ', $1);
4876-
$mysqld->{'restart_opts'}= \@rest_opt;
4877-
} else {
4882+
} elsif ($last_line =~ /^restart:(.*)$/) {
4883+
# Empty tail (e.g. bare 'restart:') is equivalent to 'restart'.
4884+
my $rest_opt_str= $1;
4885+
if ($rest_opt_str =~ /\S/) {
4886+
my @rest_opt= split(' ', $rest_opt_str);
4887+
$mysqld->{'restart_opts'}= \@rest_opt;
4888+
} else {
4889+
delete $mysqld->{'restart_opts'};
4890+
}
4891+
} elsif ($last_line =~ /^restart(-\S+)?\s*$/) {
48784892
delete $mysqld->{'restart_opts'};
4893+
} else {
4894+
mtr_error("Unknown command '$last_line' in expect file " .
4895+
"'$expect_file'");
48794896
}
48804897
unlink($expect_file);
48814898

0 commit comments

Comments
 (0)