1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-27 18:02:13 +03:00

MDEV-34753 memory pressure - erroneous termination condition

Fix race condition in test case by waiting for the expected state to occur.

Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
This commit is contained in:
Kristian Nielsen
2024-10-18 16:49:51 +02:00
committed by Daniel Black
parent eb29190398
commit abc46259c6
2 changed files with 53 additions and 25 deletions

View File

@ -18,6 +18,10 @@
# Optionally, SEARCH_ABORT can be set to "FOUND" or "NOT FOUND" and this
# will abort if the search result doesn't match the requested one.
#
# Optionally, SEARCH_WAIT can be set to "FOUND" or "NOT FOUND", and this
# will wait for the condition to occur. The timeout can be set in
# SEARCH_TIMEOUT, default is 60 seconds.
#
# Optionally, SEARCH_OUTPUT can be set to control the format of output.
# Supported formats:
# - (default) : "FOUND n /pattern/ in FILE " or "NOT FOUND ..."
@ -55,31 +59,50 @@ perl;
my @search_files= glob($ENV{SEARCH_FILE});
my $search_pattern= $ENV{SEARCH_PATTERN} or die "SEARCH_PATTERN not set";
my $search_range= $ENV{SEARCH_RANGE};
my $content;
foreach my $search_file (@search_files) {
open(FILE, '<', $search_file) || die("Can't open file $search_file: $!");
my $file_content;
if ($search_range > 0) {
read(FILE, $file_content, $search_range, 0);
} elsif ($search_range < 0) {
my $size= -s $search_file;
$search_range = -$size if $size > -$search_range;
seek(FILE, $search_range, 2);
read(FILE, $file_content, -$search_range, 0);
} else {
while(<FILE>) { # error log
if (/^CURRENT_TEST:/) {
$content='';
my $timeout= $ENV{SEARCH_TIMEOUT} || 60;
my @matches;
my $res;
my $start_time= time();
for (;;) {
my $content;
foreach my $search_file (@search_files) {
open(FILE, '<', $search_file) || die("Can't open file $search_file: $!");
my $file_content;
if ($search_range > 0) {
read(FILE, $file_content, $search_range, 0);
} elsif ($search_range < 0) {
my $size= -s $search_file;
$search_range = -$size if $size > -$search_range;
seek(FILE, $search_range, 2);
read(FILE, $file_content, -$search_range, 0);
} else {
$content.=$_;
while(<FILE>) { # error log
if (/^CURRENT_TEST:/) {
$content='';
} else {
$content.=$_;
}
}
}
}
close(FILE);
$content.= $file_content;
}
close(FILE);
$content.= $file_content;
@matches= ($content =~ /$search_pattern/gs);
$res=@matches ? "FOUND " . scalar(@matches) : "NOT FOUND";
if (($ENV{SEARCH_WAIT} eq 'FOUND' && $res eq 'NOT FOUND') ||
($ENV{SEARCH_WAIT} eq 'NOT FOUND' && $res =~ m{^FOUND })) {
if (time() - $start_time < $timeout) {
# Millisceond sleep emulated with select
select(undef, undef, undef, 0.1);
next;
}
die "Timeout waiting for $ENV{SEARCH_WAIT} ".
"for /$search_pattern/ in $ENV{SEARCH_FILE}\n";
}
last;
}
my @matches= ($content =~ /$search_pattern/gs);
my $res=@matches ? "FOUND " . scalar(@matches) : "NOT FOUND";
$ENV{SEARCH_FILE} =~ s{^.*?([^/\\]+)$}{$1};