Commit f197f9a5 authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

MDEV-32387 Windows - mtr output on is messed up with large MTR_PARALLEL.

Windows C runtime does not implement line buffering mode for stdio.

This sometimes makes output from different tests interleaved in MTR
MTR relies on this buffering (lines won't  output until "\n") to correctly
work in parallel scenarios.

Implement do-it-yourself line buffering on Windows, to workaround.
parent cbe61bf8
......@@ -76,6 +76,30 @@ if (-t STDOUT) {
}
}
# On Windows, stdio does not support line buffering
# This can make MTR output from multiple forked processes interleaved, messed up.
# Below is DYI stdout line buffering.
my $out_line="";
# Flush buffered line
sub flush_out {
print $out_line;
$out_line = "";
}
# Print to stdout
sub print_out {
if(IS_WIN32PERL) {
$out_line .= $_[0];
# Flush buffered output on new lines.
if (rindex($_[0], "\n") != -1) {
flush_out();
}
} else {
print($_[0]);
}
}
sub titlebar_stat($) {
sub time_format($) {
......@@ -116,10 +140,10 @@ sub _mtr_report_test_name ($) {
return unless defined $verbose;
print _name(). _timestamp();
printf "%-40s ", $tname;
print_out _name(). _timestamp();
print_out (sprintf "%-40s ", $tname);
my $worker = $tinfo->{worker};
print "w$worker " if defined $worker;
print_out "w$worker " if defined $worker;
return $tname;
}
......@@ -661,14 +685,14 @@ sub mtr_report (@) {
{
my @s = split /\[ (\S+) \]/, _name() . "@_\n";
if (@s > 1) {
print $s[0];
print_out $s[0];
&$set_color($s[1]);
print "[ $s[1] ]";
print_out "[ $s[1] ]";
&$set_color('reset');
print $s[2];
print_out $s[2];
titlebar_stat($s[1]) if $set_titlebar;
} else {
print $s[0];
print_out $s[0];
}
}
}
......@@ -676,6 +700,7 @@ sub mtr_report (@) {
# Print warning to screen
sub mtr_warning (@) {
flush_out();
print STDERR _name(). _timestamp().
"mysql-test-run: WARNING: ". join(" ", @_). "\n";
}
......@@ -683,7 +708,7 @@ sub mtr_warning (@) {
# Print error to screen and then exit
sub mtr_error (@) {
IO::Handle::flush(\*STDOUT) if IS_WINDOWS;
flush_out();
print STDERR _name(). _timestamp().
"mysql-test-run: *** ERROR: ". join(" ", @_). "\n";
if (IS_WINDOWS)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment