From ebb57452109743f8f522551c8d10684045c73bb2 Mon Sep 17 00:00:00 2001 From: TXXT Date: Tue, 26 May 2020 11:33:13 +0000 Subject: [PATCH] update integration test Signed-off-by: TXXT --- src/lib.rs | 44 ++++++++++++++++++++++---------------------- tests/tests.rs | 16 +++++----------- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f7cbac1..ae8ec29 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -714,9 +714,9 @@ pub fn list() -> Vec<(String, String)> { #[doc(hidden)] pub fn eval) -> R>(name: &str, f: F) -> Option { let id = thread::current().id(); - let group = REGISTRY_GROUP.read().unwrap(); let p = { + let group = REGISTRY_GROUP.read().unwrap(); let registry = group .get(&id) .unwrap_or(®ISTRY_GLOBAL.registry) @@ -761,13 +761,13 @@ pub fn eval) -> R>(name: &str, f: F) -> Option { /// A call to `cfg` with a particular fail point name overwrites any existing actions for /// that fail point, including those set via the `FAILPOINTS` environment variable. pub fn cfg>(name: S, actions: &str) -> Result<(), String> { - let id = thread::current().id(); - let group = REGISTRY_GROUP.read().unwrap(); - let mut registry = group - .get(&id) - .unwrap_or(®ISTRY_GLOBAL.registry) - .write() - .unwrap(); + let registry = { + let group = REGISTRY_GROUP.read().unwrap(); + let id = thread::current().id(); + group.get(&id).unwrap_or(®ISTRY_GLOBAL.registry).clone() + }; + + let mut registry = registry.write().unwrap(); set(&mut registry, name.into(), actions) } @@ -781,13 +781,13 @@ where S: Into, F: Fn() + Send + Sync + 'static, { - let id = thread::current().id(); - let group = REGISTRY_GROUP.read().unwrap(); - let mut registry = group - .get(&id) - .unwrap_or(®ISTRY_GLOBAL.registry) - .write() - .unwrap(); + let registry = { + let group = REGISTRY_GROUP.read().unwrap(); + let id = thread::current().id(); + group.get(&id).unwrap_or(®ISTRY_GLOBAL.registry).clone() + }; + + let mut registry = registry.write().unwrap(); let p = registry .entry(name.into()) @@ -803,13 +803,13 @@ where /// If the local registry doesn't exist, it will try to delete the corresponding /// action in the global registry. pub fn remove>(name: S) { - let id = thread::current().id(); - let group = REGISTRY_GROUP.read().unwrap(); - let mut registry = group - .get(&id) - .unwrap_or(®ISTRY_GLOBAL.registry) - .write() - .unwrap(); + let registry = { + let group = REGISTRY_GROUP.read().unwrap(); + let id = thread::current().id(); + group.get(&id).unwrap_or(®ISTRY_GLOBAL.registry).clone() + }; + + let mut registry = registry.write().unwrap(); if let Some(p) = registry.remove(name.as_ref()) { // wake up all pause failpoint. diff --git a/tests/tests.rs b/tests/tests.rs index 7f187c1..36784f8 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -19,32 +19,26 @@ fn test_pause() { fail::cfg("pause", "pause").unwrap(); let (tx, rx) = mpsc::channel(); - // control `f()` is executed before next failpoint config - let (tx_before, rx_before) = mpsc::channel(); let thread_registry = local_registry.clone(); thread::spawn(move || { thread_registry.register_current(); // pause - tx_before.send(()).unwrap(); tx.send(f()).unwrap(); // woken up by new order pause, and then pause again. - tx_before.send(()).unwrap(); tx.send(f()).unwrap(); // woken up by remove, and then quit immediately. tx.send(f()).unwrap(); }); - rx_before.recv().unwrap(); - assert!(rx.recv_timeout(Duration::from_millis(2000)).is_err()); + assert!(rx.recv_timeout(Duration::from_millis(100)).is_err()); fail::cfg("pause", "pause").unwrap(); - rx.recv_timeout(Duration::from_millis(500)).unwrap(); + rx.recv_timeout(Duration::from_millis(100)).unwrap(); - rx_before.recv().unwrap(); - assert!(rx.recv_timeout(Duration::from_millis(2000)).is_err()); + assert!(rx.recv_timeout(Duration::from_millis(100)).is_err()); fail::remove("pause"); - rx.recv_timeout(Duration::from_millis(500)).unwrap(); - rx.recv_timeout(Duration::from_millis(500)).unwrap(); + rx.recv_timeout(Duration::from_millis(100)).unwrap(); + rx.recv_timeout(Duration::from_millis(100)).unwrap(); } #[test]