diff --git a/mysql-test/include/search_pattern_in_file.inc b/mysql-test/include/search_pattern_in_file.inc index ab3c95fce3c..05bd2f71e65 100644 --- a/mysql-test/include/search_pattern_in_file.inc +++ b/mysql-test/include/search_pattern_in_file.inc @@ -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() { # 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() { # 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}; diff --git a/mysql-test/suite/innodb/t/mem_pressure.test b/mysql-test/suite/innodb/t/mem_pressure.test index 1e91ae0dff4..5dbcea439a3 100644 --- a/mysql-test/suite/innodb/t/mem_pressure.test +++ b/mysql-test/suite/innodb/t/mem_pressure.test @@ -38,11 +38,16 @@ let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err; let SEARCH_PATTERN= [Mm]emory pressure.*; --source include/search_pattern_in_file.inc -SELECT CAST(VARIABLE_VALUE AS INTEGER) < @dirty_prev AS LESS_DIRTY_IS_GOOD -FROM INFORMATION_SCHEMA.GLOBAL_STATUS -WHERE VARIABLE_NAME='Innodb_buffer_pool_pages_dirty'; - +# The garbage collection happens asynchronously after trigger, in a background +# thread. So wait for it to happen to avoid sporadic failure. +let $wait_condition= + SELECT CAST(VARIABLE_VALUE AS INTEGER) < @dirty_prev AS LESS_DIRTY_IS_GOOD + FROM INFORMATION_SCHEMA.GLOBAL_STATUS + WHERE VARIABLE_NAME='Innodb_buffer_pool_pages_dirty'; +--source include/wait_condition.inc +eval $wait_condition; let SEARCH_PATTERN= InnoDB: Memory pressure event freed.*; +let SEARCH_WAIT= FOUND; --source include/search_pattern_in_file.inc set debug_dbug=@save_dbug;