Skip to content

Commit a4e5c91

Browse files
committed
libtest: Force a newline every 100 dots when testing in quiet mode.
Rationale: We use --quiet mode when testing a PR in the CI. Also, we use `stamp` to prefix every line with a timestamp. Previously, when testing in --quiet mode, we will only print a dot for each test without any line breaks. Combined with `stamp`, this means we'd need to wait for all tests to complete before writing the output. On Travis CI, if we don't print anything within 30 minutes, the job will be forcefully canceled. This makes it very easy to spuriously-timeout when testing non-default images like arm-android using the CI. This commit tries to workaround the issue by printing a new line every 100 dots, forcing `stamp` to emit something to reset Travis's countdown.
1 parent 666687a commit a4e5c91

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/libtest/lib.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ use std::thread;
7171
use std::time::{Instant, Duration};
7272

7373
const TEST_WARN_TIMEOUT_S: u64 = 60;
74+
const QUIET_MODE_MAX_COLUMN: usize = 100; // insert a '\n' after 100 tests in quiet mode
7475

7576
// to be used by rustc to compile tests in libtest
7677
pub mod test {
@@ -614,7 +615,14 @@ impl<T: Write> ConsoleTestState<T> {
614615
pub fn write_short_result(&mut self, verbose: &str, quiet: &str, color: term::color::Color)
615616
-> io::Result<()> {
616617
if self.quiet {
617-
self.write_pretty(quiet, color)
618+
self.write_pretty(quiet, color)?;
619+
if self.current_test_count() % QUIET_MODE_MAX_COLUMN == QUIET_MODE_MAX_COLUMN - 1 {
620+
// we insert a new line every 100 dots in order to flush the
621+
// screen when dealing with line-buffered output (e.g. piping to
622+
// `stamp` in the rust CI).
623+
self.write_plain("\n")?;
624+
}
625+
Ok(())
618626
} else {
619627
self.write_pretty(verbose, color)?;
620628
self.write_plain("\n")
@@ -771,9 +779,12 @@ impl<T: Write> ConsoleTestState<T> {
771779
Ok(())
772780
}
773781

782+
fn current_test_count(&self) -> usize {
783+
self.passed + self.failed + self.ignored + self.measured + self.allowed_fail
784+
}
785+
774786
pub fn write_run_finish(&mut self) -> io::Result<bool> {
775-
assert!(self.passed + self.failed + self.ignored + self.measured +
776-
self.allowed_fail == self.total);
787+
assert!(self.current_test_count() == self.total);
777788

778789
if self.options.display_output {
779790
self.write_outputs()?;

0 commit comments

Comments
 (0)