Skip to content

Commit a4a96b9

Browse files
committed
Add a dedicated thread for output printing
1 parent 5a4d71f commit a4a96b9

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

ui_test/src/lib.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,22 @@ pub fn run_tests(config: Config) -> Result<()> {
9494
drop(submit);
9595
});
9696

97+
// A channel for the messages emitted by the individual test threads.
98+
let (finish_file, finished_files) = crossbeam::channel::unbounded();
99+
100+
s.spawn(|_| {
101+
for msg in finished_files {
102+
eprintln!("{msg}");
103+
}
104+
});
105+
97106
let mut threads = vec![];
98107

99108
// Create N worker threads that receive files to test.
100109
for _ in 0..std::thread::available_parallelism().unwrap().get() {
110+
let finish_file = finish_file.clone();
101111
threads.push(s.spawn(|_| -> Result<()> {
112+
let finish_file = finish_file;
102113
for path in &receive {
103114
if !config.path_filter.is_empty() {
104115
let path_display = path.display().to_string();
@@ -111,11 +122,12 @@ pub fn run_tests(config: Config) -> Result<()> {
111122
// Ignore file if only/ignore rules do (not) apply
112123
if !test_file_conditions(&comments, &target, &config) {
113124
ignored.fetch_add(1, Ordering::Relaxed);
114-
eprintln!(
125+
let msg = format!(
115126
"{} ... {}",
116127
path.display(),
117128
"ignored (in-test comment)".yellow()
118129
);
130+
finish_file.send(msg)?;
119131
continue;
120132
}
121133
// Run the test for all revisions
@@ -132,10 +144,10 @@ pub fn run_tests(config: Config) -> Result<()> {
132144
}
133145
write!(msg, "... ").unwrap();
134146
if errors.is_empty() {
135-
eprintln!("{msg}{}", "ok".green());
147+
write!(msg, "{}", "ok".green()).unwrap();
136148
succeeded.fetch_add(1, Ordering::Relaxed);
137149
} else {
138-
eprintln!("{msg}{}", "FAILED".red().bold());
150+
write!(msg, "{}", "FAILED".red().bold()).unwrap();
139151
failures.lock().unwrap().push((
140152
path.clone(),
141153
m,
@@ -144,11 +156,13 @@ pub fn run_tests(config: Config) -> Result<()> {
144156
stderr,
145157
));
146158
}
159+
finish_file.send(msg)?;
147160
}
148161
}
149162
Ok(())
150163
}));
151164
}
165+
152166
for thread in threads {
153167
thread.join().unwrap()?;
154168
}

0 commit comments

Comments
 (0)