Skip to content

Commit 73fa8a1

Browse files
committed
[cargo-nextest] add a BufWriter around reporter writes
Stops lots of little syscalls from happening. Fixes #35.
1 parent 990b3a1 commit 73fa8a1

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cargo-nextest/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "cargo-nextest"
33
description = "A next-generation test runner for Rust."
4-
version = "0.9.2"
4+
version = "0.9.3"
55
readme = "README.md"
66
license = "Apache-2.0 OR MIT"
77
repository = "https://github.com/nextest-rs/nextest"

cargo-nextest/src/dispatch.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ use color_eyre::eyre::{Report, Result, WrapErr};
1212
use guppy::graph::PackageGraph;
1313
use nextest_runner::{
1414
config::NextestConfig,
15+
errors::WriteEventError,
1516
partition::PartitionerBuilder,
1617
reporter::{StatusLevel, TestOutputDisplay, TestReporterBuilder},
1718
runner::TestRunnerBuilder,
1819
signal::SignalHandler,
1920
test_filter::{RunIgnored, TestFilterBuilder},
2021
test_list::{OutputFormat, RustTestArtifact, SerializableFormat, TestList},
2122
};
22-
use std::io::Cursor;
23+
use std::io::{BufWriter, Cursor, Write};
2324
use supports_color::Stream;
2425

2526
/// A next-generation test runner for Rust.
@@ -322,7 +323,10 @@ impl AppImpl {
322323
}
323324
let stdout = std::io::stdout();
324325
let lock = stdout.lock();
325-
test_list.write(message_format.to_output_format(output.verbose), lock)?;
326+
// Buffer the output to minimize syscalls.
327+
let mut writer = BufWriter::new(lock);
328+
test_list.write(message_format.to_output_format(output.verbose), &mut writer)?;
329+
writer.flush()?;
326330
}
327331
Command::Run {
328332
ref profile,
@@ -355,11 +359,11 @@ impl AppImpl {
355359
.to_builder(no_capture)
356360
.build(&test_list, &profile, handler);
357361
let stderr = std::io::stderr();
362+
let mut writer = BufWriter::new(stderr);
358363
let run_stats = runner.try_execute(|event| {
359-
// TODO: consider turning this into a trait, to initialize and carry the lock
360-
// across callback invocations
361-
let lock = stderr.lock();
362-
reporter.report_event(event, lock)
364+
// Write and flush the event.
365+
reporter.report_event(event, &mut writer)?;
366+
writer.flush().map_err(WriteEventError::Io)
363367
})?;
364368
if !run_stats.is_success() {
365369
return Err(Report::new(ExpectedError::test_run_failed()));

site/src/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
This page documents new features and bugfixes for cargo-nextest. Please see the [stability
44
policy](book/stability.md) for how versioning works with cargo-nextest.
55

6+
## [0.9.3] - 2022-02-14
7+
8+
### Fixed
9+
10+
- Add a `BufWriter` around stderr for the reporter, reducing the number of syscalls and fixing
11+
issues around output overlap on Windows ([#35](https://github.com/nextest-rs/nextest/issues/35)). Thanks [@fdncred](https://github.com/fdncred) for reporting this!
12+
613
## [0.9.2] - 2022-02-14
714

815
### Fixed

0 commit comments

Comments
 (0)