Skip to content

Commit

Permalink
Move test synchronization to tests, not in wasm-pack
Browse files Browse the repository at this point in the history
In `wasm-pack` it can't do cross-process synchronization, and in tests
there's now multiple processes which need to be synchronized.
  • Loading branch information
alexcrichton committed Nov 2, 2018
1 parent 110d930 commit f986edf
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
6 changes: 0 additions & 6 deletions src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion tests/all/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions tests/all/main.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
7 changes: 6 additions & 1 deletion tests/all/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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();
Expand Down
11 changes: 10 additions & 1 deletion tests/all/utils/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit f986edf

Please sign in to comment.