Skip to content

Commit f197f9a

Browse files
committed
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.
1 parent cbe61bf commit f197f9a

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

mysql-test/lib/mtr_report.pm

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,30 @@ if (-t STDOUT) {
7676
}
7777
}
7878

79+
# On Windows, stdio does not support line buffering
80+
# This can make MTR output from multiple forked processes interleaved, messed up.
81+
# Below is DYI stdout line buffering.
82+
my $out_line="";
83+
84+
# Flush buffered line
85+
sub flush_out {
86+
print $out_line;
87+
$out_line = "";
88+
}
89+
90+
# Print to stdout
91+
sub print_out {
92+
if(IS_WIN32PERL) {
93+
$out_line .= $_[0];
94+
# Flush buffered output on new lines.
95+
if (rindex($_[0], "\n") != -1) {
96+
flush_out();
97+
}
98+
} else {
99+
print($_[0]);
100+
}
101+
}
102+
79103
sub titlebar_stat($) {
80104

81105
sub time_format($) {
@@ -116,10 +140,10 @@ sub _mtr_report_test_name ($) {
116140

117141
return unless defined $verbose;
118142

119-
print _name(). _timestamp();
120-
printf "%-40s ", $tname;
143+
print_out _name(). _timestamp();
144+
print_out (sprintf "%-40s ", $tname);
121145
my $worker = $tinfo->{worker};
122-
print "w$worker " if defined $worker;
146+
print_out "w$worker " if defined $worker;
123147

124148
return $tname;
125149
}
@@ -661,29 +685,30 @@ sub mtr_report (@) {
661685
{
662686
my @s = split /\[ (\S+) \]/, _name() . "@_\n";
663687
if (@s > 1) {
664-
print $s[0];
688+
print_out $s[0];
665689
&$set_color($s[1]);
666-
print "[ $s[1] ]";
690+
print_out "[ $s[1] ]";
667691
&$set_color('reset');
668-
print $s[2];
692+
print_out $s[2];
669693
titlebar_stat($s[1]) if $set_titlebar;
670694
} else {
671-
print $s[0];
695+
print_out $s[0];
672696
}
673697
}
674698
}
675699

676700

677701
# Print warning to screen
678702
sub mtr_warning (@) {
703+
flush_out();
679704
print STDERR _name(). _timestamp().
680705
"mysql-test-run: WARNING: ". join(" ", @_). "\n";
681706
}
682707

683708

684709
# Print error to screen and then exit
685710
sub mtr_error (@) {
686-
IO::Handle::flush(\*STDOUT) if IS_WINDOWS;
711+
flush_out();
687712
print STDERR _name(). _timestamp().
688713
"mysql-test-run: *** ERROR: ". join(" ", @_). "\n";
689714
if (IS_WINDOWS)

0 commit comments

Comments
 (0)