Skip to content

Commit 22ddd0c

Browse files
committed
f more tests
1 parent 29ae257 commit 22ddd0c

File tree

1 file changed

+65
-3
lines changed

1 file changed

+65
-3
lines changed

lightning/src/debug_sync.rs

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,9 @@ fn recursive_lock_fail() {
276276

277277
#[test]
278278
fn recursive_read() {
279-
let mutex = RwLock::new(());
280-
let _a = mutex.read().unwrap();
281-
let _b = mutex.read().unwrap();
279+
let lock = RwLock::new(());
280+
let _a = lock.read().unwrap();
281+
let _b = lock.read().unwrap();
282282
}
283283

284284
#[test]
@@ -295,3 +295,65 @@ fn lockorder_fail() {
295295
let _a = a.lock().unwrap();
296296
}
297297
}
298+
299+
#[test]
300+
#[should_panic]
301+
fn write_lockorder_fail() {
302+
let a = RwLock::new(());
303+
let b = RwLock::new(());
304+
{
305+
let _a = a.write().unwrap();
306+
let _b = b.write().unwrap();
307+
}
308+
{
309+
let _b = b.write().unwrap();
310+
let _a = a.write().unwrap();
311+
}
312+
}
313+
314+
#[test]
315+
#[should_panic]
316+
fn read_lockorder_fail() {
317+
let a = RwLock::new(());
318+
let b = RwLock::new(());
319+
{
320+
let _a = a.read().unwrap();
321+
let _b = b.read().unwrap();
322+
}
323+
{
324+
let _b = b.read().unwrap();
325+
let _a = a.read().unwrap();
326+
}
327+
}
328+
329+
#[test]
330+
fn read_recurisve_no_lockorder() {
331+
// Like the above, but note that no lockorder is implied when we recursively read-lock a
332+
// RwLock, causing this to pass just fine.
333+
let a = RwLock::new(());
334+
let b = RwLock::new(());
335+
let _outer = a.read().unwrap();
336+
{
337+
let _a = a.read().unwrap();
338+
let _b = b.read().unwrap();
339+
}
340+
{
341+
let _b = b.read().unwrap();
342+
let _a = a.read().unwrap();
343+
}
344+
}
345+
346+
#[test]
347+
#[should_panic]
348+
fn read_write_lockorder_fail() {
349+
let a = RwLock::new(());
350+
let b = RwLock::new(());
351+
{
352+
let _a = a.write().unwrap();
353+
let _b = b.read().unwrap();
354+
}
355+
{
356+
let _b = b.read().unwrap();
357+
let _a = a.write().unwrap();
358+
}
359+
}

0 commit comments

Comments
 (0)