Use names suggestive of channel endpoints

This commit is contained in:
Oli Scherer 2022-07-21 07:39:54 +00:00
parent 68041b42fc
commit ecacc56843

View File

@ -126,7 +126,7 @@ pub fn run_tests(mut config: Config) -> Result<()> {
}); });
// A channel for the messages emitted by the individual test threads. // A channel for the messages emitted by the individual test threads.
let (finish_file, finished_files) = crossbeam::channel::unbounded(); let (finished_files_sender, finished_files_recv) = crossbeam::channel::unbounded();
enum TestResult { enum TestResult {
Ok, Ok,
Failed, Failed,
@ -135,7 +135,7 @@ enum TestResult {
s.spawn(|_| { s.spawn(|_| {
if config.quiet { if config.quiet {
for (i, (_, result)) in finished_files.into_iter().enumerate() { for (i, (_, result)) in finished_files_recv.into_iter().enumerate() {
// Humans start counting at 1 // Humans start counting at 1
let i = i + 1; let i = i + 1;
match result { match result {
@ -148,7 +148,7 @@ enum TestResult {
} }
} }
} else { } else {
for (msg, result) in finished_files { for (msg, result) in finished_files_recv {
eprint!("{msg} ... "); eprint!("{msg} ... ");
eprintln!( eprintln!(
"{}", "{}",
@ -166,9 +166,9 @@ enum TestResult {
// Create N worker threads that receive files to test. // Create N worker threads that receive files to test.
for _ in 0..std::thread::available_parallelism().unwrap().get() { for _ in 0..std::thread::available_parallelism().unwrap().get() {
let finish_file = finish_file.clone(); let finished_files_sender = finished_files_sender.clone();
threads.push(s.spawn(|_| -> Result<()> { threads.push(s.spawn(|_| -> Result<()> {
let finish_file = finish_file; let finished_files_sender = finished_files_sender;
for path in &receive { for path in &receive {
if !config.path_filter.is_empty() { if !config.path_filter.is_empty() {
let path_display = path.display().to_string(); let path_display = path.display().to_string();
@ -181,7 +181,8 @@ enum TestResult {
// Ignore file if only/ignore rules do (not) apply // Ignore file if only/ignore rules do (not) apply
if !test_file_conditions(&comments, &target, &config) { if !test_file_conditions(&comments, &target, &config) {
ignored.fetch_add(1, Ordering::Relaxed); ignored.fetch_add(1, Ordering::Relaxed);
finish_file.send((path.display().to_string(), TestResult::Ignored))?; finished_files_sender
.send((path.display().to_string(), TestResult::Ignored))?;
continue; continue;
} }
// Run the test for all revisions // Run the test for all revisions
@ -197,10 +198,10 @@ enum TestResult {
write!(msg, "(revision `{revision}`) ").unwrap(); write!(msg, "(revision `{revision}`) ").unwrap();
} }
if errors.is_empty() { if errors.is_empty() {
finish_file.send((msg, TestResult::Ok))?; finished_files_sender.send((msg, TestResult::Ok))?;
succeeded.fetch_add(1, Ordering::Relaxed); succeeded.fetch_add(1, Ordering::Relaxed);
} else { } else {
finish_file.send((msg, TestResult::Failed))?; finished_files_sender.send((msg, TestResult::Failed))?;
failures.lock().unwrap().push(( failures.lock().unwrap().push((
path.clone(), path.clone(),
m, m,