summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/evil_rwlock.rs18
-rw-r--r--tests/retry_rw.rs10
2 files changed, 28 insertions, 0 deletions
diff --git a/tests/evil_rwlock.rs b/tests/evil_rwlock.rs
index 9eed8a8..4be86a1 100644
--- a/tests/evil_rwlock.rs
+++ b/tests/evil_rwlock.rs
@@ -1,3 +1,4 @@
+use std::panic::AssertUnwindSafe;
use std::sync::Arc;
use happylock::collection::{BoxedLockCollection, RetryingLockCollection};
@@ -63,6 +64,23 @@ fn boxed_rwlocks() {
assert!(good_mutex.scoped_try_write(&mut key, |_| {}).is_ok());
assert!(evil_mutex.scoped_try_write(&mut key, |_| {}).is_err());
assert!(useless_mutex.scoped_try_write(&mut key, |_| {}).is_ok());
+
+ std::thread::scope(|s| {
+ s.spawn(|| {
+ let evil_mutex = AssertUnwindSafe(evil_mutex);
+ let r = std::panic::catch_unwind(|| {
+ let key = ThreadKey::get().unwrap();
+ evil_mutex.write(key);
+ });
+
+ assert!(r.is_err());
+ });
+
+ s.spawn(|| {
+ let key = ThreadKey::get().unwrap();
+ good_mutex.write(key);
+ });
+ });
}
#[test]
diff --git a/tests/retry_rw.rs b/tests/retry_rw.rs
index 976ab14..0a946b0 100644
--- a/tests/retry_rw.rs
+++ b/tests/retry_rw.rs
@@ -24,11 +24,21 @@ fn thread_2() {
assert_eq!(*guard[2], 3);
}
+fn thread_3() {
+ let key = ThreadKey::get().unwrap();
+ std::thread::sleep(Duration::from_millis(50));
+ let guard = RWLOCK_1.write(key);
+ std::thread::sleep(Duration::from_millis(50));
+ assert_eq!(*guard, 1);
+}
+
#[test]
fn retries() {
let t1 = std::thread::spawn(thread_1);
let t2 = std::thread::spawn(thread_2);
+ let t3 = std::thread::spawn(thread_3);
t1.join().unwrap();
t2.join().unwrap();
+ t3.join().unwrap();
}