Skip to content

Commit b62160e

Browse files
committed
Move tests from debug_sync to a new submodule
This will allow us to change the module regex match in debug_sync to make it more robust.
1 parent 558bfa3 commit b62160e

File tree

3 files changed

+96
-97
lines changed

3 files changed

+96
-97
lines changed

lightning/src/sync/debug_sync.rs

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -333,100 +333,3 @@ impl<T> RwLock<T> {
333333
}
334334

335335
pub type FairRwLock<T> = RwLock<T>;
336-
337-
mod tests {
338-
use super::{RwLock, Mutex};
339-
340-
#[test]
341-
#[should_panic]
342-
#[cfg(not(feature = "backtrace"))]
343-
fn recursive_lock_fail() {
344-
let mutex = Mutex::new(());
345-
let _a = mutex.lock().unwrap();
346-
let _b = mutex.lock().unwrap();
347-
}
348-
349-
#[test]
350-
fn recursive_read() {
351-
let lock = RwLock::new(());
352-
let _a = lock.read().unwrap();
353-
let _b = lock.read().unwrap();
354-
}
355-
356-
#[test]
357-
#[should_panic]
358-
fn lockorder_fail() {
359-
let a = Mutex::new(());
360-
let b = Mutex::new(());
361-
{
362-
let _a = a.lock().unwrap();
363-
let _b = b.lock().unwrap();
364-
}
365-
{
366-
let _b = b.lock().unwrap();
367-
let _a = a.lock().unwrap();
368-
}
369-
}
370-
371-
#[test]
372-
#[should_panic]
373-
fn write_lockorder_fail() {
374-
let a = RwLock::new(());
375-
let b = RwLock::new(());
376-
{
377-
let _a = a.write().unwrap();
378-
let _b = b.write().unwrap();
379-
}
380-
{
381-
let _b = b.write().unwrap();
382-
let _a = a.write().unwrap();
383-
}
384-
}
385-
386-
#[test]
387-
#[should_panic]
388-
fn read_lockorder_fail() {
389-
let a = RwLock::new(());
390-
let b = RwLock::new(());
391-
{
392-
let _a = a.read().unwrap();
393-
let _b = b.read().unwrap();
394-
}
395-
{
396-
let _b = b.read().unwrap();
397-
let _a = a.read().unwrap();
398-
}
399-
}
400-
401-
#[test]
402-
fn read_recursive_no_lockorder() {
403-
// Like the above, but note that no lockorder is implied when we recursively read-lock a
404-
// RwLock, causing this to pass just fine.
405-
let a = RwLock::new(());
406-
let b = RwLock::new(());
407-
let _outer = a.read().unwrap();
408-
{
409-
let _a = a.read().unwrap();
410-
let _b = b.read().unwrap();
411-
}
412-
{
413-
let _b = b.read().unwrap();
414-
let _a = a.read().unwrap();
415-
}
416-
}
417-
418-
#[test]
419-
#[should_panic]
420-
fn read_write_lockorder_fail() {
421-
let a = RwLock::new(());
422-
let b = RwLock::new(());
423-
{
424-
let _a = a.write().unwrap();
425-
let _b = b.read().unwrap();
426-
}
427-
{
428-
let _b = b.read().unwrap();
429-
let _a = a.write().unwrap();
430-
}
431-
}
432-
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
use crate::sync::debug_sync::{RwLock, Mutex};
2+
3+
#[test]
4+
#[should_panic]
5+
#[cfg(not(feature = "backtrace"))]
6+
fn recursive_lock_fail() {
7+
let mutex = Mutex::new(());
8+
let _a = mutex.lock().unwrap();
9+
let _b = mutex.lock().unwrap();
10+
}
11+
12+
#[test]
13+
fn recursive_read() {
14+
let lock = RwLock::new(());
15+
let _a = lock.read().unwrap();
16+
let _b = lock.read().unwrap();
17+
}
18+
19+
#[test]
20+
#[should_panic]
21+
fn lockorder_fail() {
22+
let a = Mutex::new(());
23+
let b = Mutex::new(());
24+
{
25+
let _a = a.lock().unwrap();
26+
let _b = b.lock().unwrap();
27+
}
28+
{
29+
let _b = b.lock().unwrap();
30+
let _a = a.lock().unwrap();
31+
}
32+
}
33+
34+
#[test]
35+
#[should_panic]
36+
fn write_lockorder_fail() {
37+
let a = RwLock::new(());
38+
let b = RwLock::new(());
39+
{
40+
let _a = a.write().unwrap();
41+
let _b = b.write().unwrap();
42+
}
43+
{
44+
let _b = b.write().unwrap();
45+
let _a = a.write().unwrap();
46+
}
47+
}
48+
49+
#[test]
50+
#[should_panic]
51+
fn read_lockorder_fail() {
52+
let a = RwLock::new(());
53+
let b = RwLock::new(());
54+
{
55+
let _a = a.read().unwrap();
56+
let _b = b.read().unwrap();
57+
}
58+
{
59+
let _b = b.read().unwrap();
60+
let _a = a.read().unwrap();
61+
}
62+
}
63+
64+
#[test]
65+
fn read_recursive_no_lockorder() {
66+
// Like the above, but note that no lockorder is implied when we recursively read-lock a
67+
// RwLock, causing this to pass just fine.
68+
let a = RwLock::new(());
69+
let b = RwLock::new(());
70+
let _outer = a.read().unwrap();
71+
{
72+
let _a = a.read().unwrap();
73+
let _b = b.read().unwrap();
74+
}
75+
{
76+
let _b = b.read().unwrap();
77+
let _a = a.read().unwrap();
78+
}
79+
}
80+
81+
#[test]
82+
#[should_panic]
83+
fn read_write_lockorder_fail() {
84+
let a = RwLock::new(());
85+
let b = RwLock::new(());
86+
{
87+
let _a = a.write().unwrap();
88+
let _b = b.read().unwrap();
89+
}
90+
{
91+
let _b = b.read().unwrap();
92+
let _a = a.write().unwrap();
93+
}
94+
}

lightning/src/sync/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
mod debug_sync;
33
#[cfg(all(feature = "std", not(feature = "_bench_unstable"), test))]
44
pub use debug_sync::*;
5+
#[cfg(all(feature = "std", not(feature = "_bench_unstable"), test))]
6+
mod debug_sync_tests;
57

68
#[cfg(all(feature = "std", any(feature = "_bench_unstable", not(test))))]
79
pub use ::std::sync::{Arc, Mutex, Condvar, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard};

0 commit comments

Comments
 (0)