From a9d8d2c62a32e225d0d206b0f8b381feb13e47c5 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 18 Jun 2014 13:18:36 -0700 Subject: [PATCH] Run tests in parallel Give each test is own root inside of the shared root to ensure that the tests are still isolated from one another. --- Makefile | 2 +- tests/support/paths.rs | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 216af20e0..23a2fed59 100644 --- 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 diff --git a/tests/support/paths.rs b/tests/support/paths.rs index 84013ac6b..cb7a5d9ae 100644 --- a/tests/support/paths.rs +++ b/tests/support/paths.rs @@ -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();