Move test synchronization to tests, not in `wasm-pack`

In `wasm-pack` it can't do cross-process synchronization, and in tests
there's now multiple processes which need to be synchronized.
master
Alex Crichton 7 years ago
parent 110d930351
commit f986edf4c7
  1. 6
      src/test/mod.rs
  2. 4
      tests/all/build.rs
  3. 2
      tests/all/main.rs
  4. 7
      tests/all/test.rs
  5. 11
      tests/all/utils/fixture.rs

@ -22,12 +22,6 @@ where
K: AsRef<OsStr>,
V: AsRef<OsStr>,
{
use std::sync::Mutex;
lazy_static! {
static ref ONE_TEST_AT_A_TIME: Mutex<()> = Mutex::new(());
}
let _locked = ONE_TEST_AT_A_TIME.lock().unwrap();
let output = {
let mut cmd = Command::new("cargo");
cmd.envs(envs);

@ -17,7 +17,9 @@ fn build_in_non_crate_directory_doesnt_panic() {
"running wasm-pack in a non-crate directory should fail, but it should not panic"
);
let err = result.unwrap_err();
assert!(err.iter_chain().any(|e| e.to_string().contains("missing a `Cargo.toml`")));
assert!(err
.iter_chain()
.any(|e| e.to_string().contains("missing a `Cargo.toml`")));
}
#[test]

@ -1,5 +1,7 @@
extern crate failure;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
#[macro_use]

@ -98,7 +98,10 @@ fn it_can_run_failing_tests() {
mode: build::BuildMode::Noinstall,
..Default::default()
});
assert_err(fixture.run(cmd), "Running Wasm tests with wasm-bindgen-test failed");
assert_err(
fixture.run(cmd),
"Running Wasm tests with wasm-bindgen-test failed",
);
}
#[test]
@ -121,6 +124,8 @@ fn it_can_find_a_webdriver_on_path() {
paths.insert(0, local_wasm_bindgen.parent().unwrap().to_path_buf());
let path = env::join_paths(paths).unwrap();
let _lock = fixture.lock();
let mut me = env::current_exe().unwrap();
me.pop();
me.pop();

@ -4,7 +4,7 @@ use std::fs;
use std::mem::ManuallyDrop;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::sync::{Once, ONCE_INIT};
use std::sync::{MutexGuard, Once, ONCE_INIT};
use std::thread;
use tempfile::TempDir;
use wasm_pack;
@ -208,6 +208,7 @@ impl Fixture {
let logger = wasm_pack::logger::new(&cmd, 3)?;
match cmd {
wasm_pack::command::Command::Test(cmd) => {
let _lock = self.lock();
let mut test = wasm_pack::command::test::Test::try_from_opts(cmd)?;
test.set_cache(self.cache());
test.run(&logger)
@ -220,6 +221,14 @@ impl Fixture {
_ => unreachable!(),
}
}
pub fn lock(&self) -> MutexGuard<'static, ()> {
use std::sync::Mutex;
lazy_static! {
static ref ONE_TEST_AT_A_TIME: Mutex<()> = Mutex::new(());
}
ONE_TEST_AT_A_TIME.lock().unwrap_or_else(|e| e.into_inner())
}
}
impl Drop for Fixture {

Loading…
Cancel
Save