From: Eric Huss Date: Tue, 10 Mar 2020 17:55:04 +0000 (-0700) Subject: Add test for caching large output. X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=c67cd7a1a2f13868fe1a7ee03fc326eca3f1b0e6;p=cargo.git Add test for caching large output. --- diff --git a/src/cargo/core/compiler/job_queue.rs b/src/cargo/core/compiler/job_queue.rs index 57e6b835b..039d93d50 100644 --- a/src/cargo/core/compiler/job_queue.rs +++ b/src/cargo/core/compiler/job_queue.rs @@ -365,7 +365,8 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> { queue: self.queue, // 100 here is somewhat arbitrary. It is a few screenfulls of // output, and hopefully at most a few megabytes of memory for - // typical messages. + // typical messages. If you change this, please update the test + // caching_large_output, too. messages: Arc::new(Queue::new(100)), active: HashMap::new(), compiled: HashSet::new(), diff --git a/tests/testsuite/cache_messages.rs b/tests/testsuite/cache_messages.rs index eb31255b2..bc5f365b9 100644 --- a/tests/testsuite/cache_messages.rs +++ b/tests/testsuite/cache_messages.rs @@ -437,3 +437,62 @@ line 2 ) .run(); } + +#[cargo_test] +fn caching_large_output() { + // Handles large number of messages. + // This is an arbitrary amount that is greater than the 100 used in + // job_queue. This is here to check for deadlocks or any other problems. + const COUNT: usize = 250; + let rustc = project() + .at("rustc") + .file("Cargo.toml", &basic_manifest("rustc_alt", "1.0.0")) + .file( + "src/main.rs", + &format!( + r#" + fn main() {{ + for i in 0..{} {{ + eprintln!("{{{{\"message\": \"test message {{}}\", \"level\": \"warning\", \ + \"spans\": [], \"children\": [], \"rendered\": \"test message {{}}\"}}}}", + i, i); + }} + let r = std::process::Command::new("rustc") + .args(std::env::args_os().skip(1)) + .status(); + std::process::exit(r.unwrap().code().unwrap_or(2)); + }} + "#, + COUNT + ), + ) + .build(); + + let mut expected = String::new(); + for i in 0..COUNT { + expected.push_str(&format!("test message {}\n", i)); + } + + rustc.cargo("build").run(); + let p = project().file("src/lib.rs", "").build(); + p.cargo("check") + .env("RUSTC", rustc.bin("rustc_alt")) + .with_stderr(&format!( + "\ +[CHECKING] foo [..] +{}[FINISHED] dev [..] +", + expected + )) + .run(); + + p.cargo("check") + .env("RUSTC", rustc.bin("rustc_alt")) + .with_stderr(&format!( + "\ +{}[FINISHED] dev [..] +", + expected + )) + .run(); +}