Skip to content

Commit

Permalink
Add test for caching large output.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Mar 10, 2020
1 parent e2b28f7 commit c67cd7a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
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();
}

0 comments on commit c67cd7a

Please sign in to comment.