Run tests in parallel
authorAlex Crichton <alex@alexcrichton.com>
Wed, 18 Jun 2014 20:18:36 +0000 (13:18 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 19 Jun 2014 18:52:51 +0000 (11:52 -0700)
Give each test is own root inside of the shared root to ensure that the tests
are still isolated from one another.

Makefile
tests/support/paths.rs

index 216af20e062c5e8811e65921a0c9340b4fa305f3..23a2fed593d85a960cd61fcd76e7c823e1f7f713 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -61,7 +61,7 @@ test-unit: target/tests/test-unit
        target/tests/test-unit $(only)
 
 test-integration: target/tests/test-integration
-       RUST_TEST_TASKS=1 $< $(only)
+       $< $(only)
 
 test: test-unit test-integration
 
index 84013ac6b2e8f94ac772d328dedf19b1cf3819d2..cb7a5d9ae678da720f9d41ab6c9e49342dc76326 100644 (file)
@@ -1,12 +1,21 @@
-use std::{io,os};
 use std::io::IoResult;
 use std::io::fs;
+use std::sync::atomics;
+use std::{io, os};
+
 use cargo::util::realpath;
 
 static CARGO_INTEGRATION_TEST_DIR : &'static str = "cargo-integration-tests";
 
+local_data_key!(task_id: uint)
+
+static mut NEXT_ID: atomics::AtomicUint = atomics::INIT_ATOMIC_UINT;
+
 pub fn root() -> Path {
-    realpath(&os::tmpdir().join(CARGO_INTEGRATION_TEST_DIR)).unwrap()
+    let my_id = *task_id.get().unwrap();
+    let path = os::tmpdir().join(CARGO_INTEGRATION_TEST_DIR)
+                           .join(format!("test-{}", my_id));
+    realpath(&path).unwrap()
 }
 
 pub fn home() -> Path {
@@ -40,6 +49,8 @@ impl PathExt for Path {
  * Ensure required test directories exist and are empty
  */
 pub fn setup() {
+    let my_id = unsafe { NEXT_ID.fetch_add(1, atomics::SeqCst) };
+    task_id.replace(Some(my_id));
     debug!("path setup; root={}; home={}", root().display(), home().display());
     root().rm_rf().unwrap();
     home().mkdir_p().unwrap();