Skip to content

Commit abc4625

Browse files
knielsengrooverdan
authored andcommitted
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>
1 parent eb29190 commit abc4625

File tree

2 files changed

+53
-25
lines changed

2 files changed

+53
-25
lines changed

mysql-test/include/search_pattern_in_file.inc

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
# Optionally, SEARCH_ABORT can be set to "FOUND" or "NOT FOUND" and this
1919
# will abort if the search result doesn't match the requested one.
2020
#
21+
# Optionally, SEARCH_WAIT can be set to "FOUND" or "NOT FOUND", and this
22+
# will wait for the condition to occur. The timeout can be set in
23+
# SEARCH_TIMEOUT, default is 60 seconds.
24+
#
2125
# Optionally, SEARCH_OUTPUT can be set to control the format of output.
2226
# Supported formats:
2327
# - (default) : "FOUND n /pattern/ in FILE " or "NOT FOUND ..."
@@ -55,31 +59,50 @@ perl;
5559
my @search_files= glob($ENV{SEARCH_FILE});
5660
my $search_pattern= $ENV{SEARCH_PATTERN} or die "SEARCH_PATTERN not set";
5761
my $search_range= $ENV{SEARCH_RANGE};
58-
my $content;
59-
foreach my $search_file (@search_files) {
60-
open(FILE, '<', $search_file) || die("Can't open file $search_file: $!");
61-
my $file_content;
62-
if ($search_range > 0) {
63-
read(FILE, $file_content, $search_range, 0);
64-
} elsif ($search_range < 0) {
65-
my $size= -s $search_file;
66-
$search_range = -$size if $size > -$search_range;
67-
seek(FILE, $search_range, 2);
68-
read(FILE, $file_content, -$search_range, 0);
69-
} else {
70-
while(<FILE>) { # error log
71-
if (/^CURRENT_TEST:/) {
72-
$content='';
62+
my $timeout= $ENV{SEARCH_TIMEOUT} || 60;
63+
my @matches;
64+
my $res;
65+
66+
my $start_time= time();
67+
for (;;) {
68+
my $content;
69+
foreach my $search_file (@search_files) {
70+
open(FILE, '<', $search_file) || die("Can't open file $search_file: $!");
71+
my $file_content;
72+
if ($search_range > 0) {
73+
read(FILE, $file_content, $search_range, 0);
74+
} elsif ($search_range < 0) {
75+
my $size= -s $search_file;
76+
$search_range = -$size if $size > -$search_range;
77+
seek(FILE, $search_range, 2);
78+
read(FILE, $file_content, -$search_range, 0);
7379
} else {
74-
$content.=$_;
80+
while(<FILE>) { # error log
81+
if (/^CURRENT_TEST:/) {
82+
$content='';
83+
} else {
84+
$content.=$_;
85+
}
86+
}
87+
}
88+
close(FILE);
89+
$content.= $file_content;
90+
}
91+
@matches= ($content =~ /$search_pattern/gs);
92+
$res=@matches ? "FOUND " . scalar(@matches) : "NOT FOUND";
93+
94+
if (($ENV{SEARCH_WAIT} eq 'FOUND' && $res eq 'NOT FOUND') ||
95+
($ENV{SEARCH_WAIT} eq 'NOT FOUND' && $res =~ m{^FOUND })) {
96+
if (time() - $start_time < $timeout) {
97+
# Millisceond sleep emulated with select
98+
select(undef, undef, undef, 0.1);
99+
next;
75100
}
76-
}
101+
die "Timeout waiting for $ENV{SEARCH_WAIT} ".
102+
"for /$search_pattern/ in $ENV{SEARCH_FILE}\n";
77103
}
78-
close(FILE);
79-
$content.= $file_content;
104+
last;
80105
}
81-
my @matches= ($content =~ /$search_pattern/gs);
82-
my $res=@matches ? "FOUND " . scalar(@matches) : "NOT FOUND";
83106
84107
$ENV{SEARCH_FILE} =~ s{^.*?([^/\\]+)$}{$1};
85108

mysql-test/suite/innodb/t/mem_pressure.test

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,16 @@ let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err;
3838
let SEARCH_PATTERN= [Mm]emory pressure.*;
3939
--source include/search_pattern_in_file.inc
4040

41-
SELECT CAST(VARIABLE_VALUE AS INTEGER) < @dirty_prev AS LESS_DIRTY_IS_GOOD
42-
FROM INFORMATION_SCHEMA.GLOBAL_STATUS
43-
WHERE VARIABLE_NAME='Innodb_buffer_pool_pages_dirty';
44-
41+
# The garbage collection happens asynchronously after trigger, in a background
42+
# thread. So wait for it to happen to avoid sporadic failure.
43+
let $wait_condition=
44+
SELECT CAST(VARIABLE_VALUE AS INTEGER) < @dirty_prev AS LESS_DIRTY_IS_GOOD
45+
FROM INFORMATION_SCHEMA.GLOBAL_STATUS
46+
WHERE VARIABLE_NAME='Innodb_buffer_pool_pages_dirty';
47+
--source include/wait_condition.inc
48+
eval $wait_condition;
4549
let SEARCH_PATTERN= InnoDB: Memory pressure event freed.*;
50+
let SEARCH_WAIT= FOUND;
4651
--source include/search_pattern_in_file.inc
4752

4853
set debug_dbug=@save_dbug;

0 commit comments

Comments
 (0)