]> git.proxmox.com Git - cargo.git/commitdiff
Add test for caching large output.
authorEric Huss <eric@huss.org>
Tue, 10 Mar 2020 17:55:04 +0000 (10:55 -0700)
committerEric Huss <eric@huss.org>
Tue, 10 Mar 2020 18:23:18 +0000 (11:23 -0700)
src/cargo/core/compiler/job_queue.rs
tests/testsuite/cache_messages.rs

index 57e6b835b6bcfe90398547664dd59953509b8d75..039d93d50d7cb82cb91b5b351e4c5a8ae99fa728 100644 (file)
@@ -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(),
index eb31255b2565137657ab11a9355d4a3214b8a7af..bc5f365b90a3ccdb644d33e0dd20173bc599d95d 100644 (file)
@@ -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();
+}