add tests for #2606
authorJorge Aparicio <japaricious@gmail.com>
Sat, 23 Apr 2016 03:33:58 +0000 (22:33 -0500)
committerJorge Aparicio <japaricious@gmail.com>
Sat, 23 Apr 2016 03:33:58 +0000 (22:33 -0500)
tests/test_cargo_concurrent.rs
tests/test_cargo_install.rs

index 99dc624c0fa3be3b805826d08e6e766e6469c8a6..ef91c63bbd85fb7caed11e5cc99927de38b1da3e 100644 (file)
@@ -1,4 +1,4 @@
-use std::env;
+use std::{env, str};
 use std::fs::{self, File};
 use std::io::Write;
 use std::net::TcpListener;
@@ -15,6 +15,12 @@ use test_cargo_install::{cargo_home, has_installed_exe};
 
 fn setup() {}
 
+fn pkg(name: &str, vers: &str) {
+    Package::new(name, vers)
+        .file("src/main.rs", "fn main() {{}}")
+        .publish();
+}
+
 test!(multiple_installs {
     let p = project("foo")
         .file("a/Cargo.toml", r#"
@@ -52,6 +58,34 @@ test!(multiple_installs {
     assert_that(cargo_home(), has_installed_exe("bar"));
 });
 
+test!(concurrent_installs {
+    const LOCKED_BUILD: &'static str = "waiting for file lock on build directory";
+
+    pkg("foo", "0.0.1");
+    pkg("bar", "0.0.1");
+
+    let mut a = ::cargo_process().arg("install").arg("foo").build_command();
+    let mut b = ::cargo_process().arg("install").arg("bar").build_command();
+
+    a.stdout(Stdio::piped()).stderr(Stdio::piped());
+    b.stdout(Stdio::piped()).stderr(Stdio::piped());
+
+    let a = a.spawn().unwrap();
+    let b = b.spawn().unwrap();
+    let a = thread::spawn(move || a.wait_with_output().unwrap());
+    let b = b.wait_with_output().unwrap();
+    let a = a.join().unwrap();
+
+    assert!(!str::from_utf8(&a.stderr).unwrap().contains(LOCKED_BUILD));
+    assert!(!str::from_utf8(&b.stderr).unwrap().contains(LOCKED_BUILD));
+
+    assert_that(a, execs().with_status(0));
+    assert_that(b, execs().with_status(0));
+
+    assert_that(cargo_home(), has_installed_exe("foo"));
+    assert_that(cargo_home(), has_installed_exe("bar"));
+});
+
 test!(one_install_should_be_bad {
     let p = project("foo")
         .file("a/Cargo.toml", r#"
index 31d9bf7fcd817dfde419f85e6dc5eac2c7917153..cfad68443c8dbaba155c6ad968ddafed32937cad 100644 (file)
@@ -659,3 +659,18 @@ test!(q_silences_warnings {
     assert_that(cargo_process("install").arg("-q").arg("--path").arg(p.root()),
                 execs().with_status(0).with_stderr(""));
 });
+
+test!(readonly_dir {
+    pkg("foo", "0.0.1");
+
+    let root = paths::root();
+    let dir = &root.join("readonly");
+    fs::create_dir(root.join("readonly")).unwrap();
+    let mut perms = fs::metadata(dir).unwrap().permissions();
+    perms.set_readonly(true);
+    fs::set_permissions(dir, perms).unwrap();
+
+    assert_that(cargo_process("install").arg("foo").cwd(dir),
+                execs().with_status(0));
+    assert_that(cargo_home(), has_installed_exe("foo"));
+});