Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test for caching large output.
  • Loading branch information
ehuss committed Mar 10, 2020
commit c67cd7a1a2f13868fe1a7ee03fc326eca3f1b0e6
3 changes: 2 additions & 1 deletion src/cargo/core/compiler/job_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
59 changes: 59 additions & 0 deletions tests/testsuite/cache_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}