Skip to content

Commit c67cd7a

Browse files
committed
Add test for caching large output.
1 parent e2b28f7 commit c67cd7a

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

src/cargo/core/compiler/job_queue.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
365365
queue: self.queue,
366366
// 100 here is somewhat arbitrary. It is a few screenfulls of
367367
// output, and hopefully at most a few megabytes of memory for
368-
// typical messages.
368+
// typical messages. If you change this, please update the test
369+
// caching_large_output, too.
369370
messages: Arc::new(Queue::new(100)),
370371
active: HashMap::new(),
371372
compiled: HashSet::new(),

tests/testsuite/cache_messages.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,3 +437,62 @@ line 2
437437
)
438438
.run();
439439
}
440+
441+
#[cargo_test]
442+
fn caching_large_output() {
443+
// Handles large number of messages.
444+
// This is an arbitrary amount that is greater than the 100 used in
445+
// job_queue. This is here to check for deadlocks or any other problems.
446+
const COUNT: usize = 250;
447+
let rustc = project()
448+
.at("rustc")
449+
.file("Cargo.toml", &basic_manifest("rustc_alt", "1.0.0"))
450+
.file(
451+
"src/main.rs",
452+
&format!(
453+
r#"
454+
fn main() {{
455+
for i in 0..{} {{
456+
eprintln!("{{{{\"message\": \"test message {{}}\", \"level\": \"warning\", \
457+
\"spans\": [], \"children\": [], \"rendered\": \"test message {{}}\"}}}}",
458+
i, i);
459+
}}
460+
let r = std::process::Command::new("rustc")
461+
.args(std::env::args_os().skip(1))
462+
.status();
463+
std::process::exit(r.unwrap().code().unwrap_or(2));
464+
}}
465+
"#,
466+
COUNT
467+
),
468+
)
469+
.build();
470+
471+
let mut expected = String::new();
472+
for i in 0..COUNT {
473+
expected.push_str(&format!("test message {}\n", i));
474+
}
475+
476+
rustc.cargo("build").run();
477+
let p = project().file("src/lib.rs", "").build();
478+
p.cargo("check")
479+
.env("RUSTC", rustc.bin("rustc_alt"))
480+
.with_stderr(&format!(
481+
"\
482+
[CHECKING] foo [..]
483+
{}[FINISHED] dev [..]
484+
",
485+
expected
486+
))
487+
.run();
488+
489+
p.cargo("check")
490+
.env("RUSTC", rustc.bin("rustc_alt"))
491+
.with_stderr(&format!(
492+
"\
493+
{}[FINISHED] dev [..]
494+
",
495+
expected
496+
))
497+
.run();
498+
}

0 commit comments

Comments
 (0)