Skip to content

Commit

Permalink
MDEV-32387 Windows - mtr output on is messed up with large MTR_PARALLEL.
Browse files Browse the repository at this point in the history
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
workin parallel scenarios.

Implement do-it-yourself line buffering on Windows, to workaround.
  • Loading branch information
vaintroub committed Oct 10, 2023
1 parent cbe61bf commit 1942363
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions mysql-test/lib/mtr_report.pm
Expand Up @@ -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($) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -661,29 +685,30 @@ 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];
}
}
}


# Print warning to screen
sub mtr_warning (@) {
flush_out();
print STDERR _name(). _timestamp().
"mysql-test-run: WARNING: ". join(" ", @_). "\n";
}


# 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)
Expand Down

0 comments on commit 1942363

Please sign in to comment.