Skip to content

Commit c1153b0

Browse files
committed
move condvar test from mutex to condvar test file
Signed-off-by: Connor Tsui <[email protected]>
1 parent 3d5a408 commit c1153b0

File tree

2 files changed

+35
-33
lines changed

2 files changed

+35
-33
lines changed

library/std/tests/sync/condvar.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,3 +562,37 @@ fn nonpoison_timeout_nanoseconds() {
562562
}
563563
})
564564
}
565+
566+
#[test]
567+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
568+
fn test_arc_condvar_poison() {
569+
use std::sync::poison::{Condvar, Mutex};
570+
571+
struct Packet<T>(Arc<(Mutex<T>, Condvar)>);
572+
573+
let packet = Packet(Arc::new((Mutex::new(1), Condvar::new())));
574+
let packet2 = Packet(packet.0.clone());
575+
let (tx, rx) = channel();
576+
577+
let _t = thread::spawn(move || -> () {
578+
rx.recv().unwrap();
579+
let &(ref lock, ref cvar) = &*packet2.0;
580+
let _g = lock.lock().unwrap();
581+
cvar.notify_one();
582+
// Parent should fail when it wakes up.
583+
panic!();
584+
});
585+
586+
let &(ref lock, ref cvar) = &*packet.0;
587+
let mut lock = lock.lock().unwrap();
588+
tx.send(()).unwrap();
589+
while *lock == 1 {
590+
match cvar.wait(lock) {
591+
Ok(l) => {
592+
lock = l;
593+
assert_eq!(*lock, 1);
594+
}
595+
Err(..) => break,
596+
}
597+
}
598+
}

library/std/tests/sync/mutex.rs

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::ops::FnMut;
33
use std::panic::{self, AssertUnwindSafe};
44
use std::sync::atomic::{AtomicUsize, Ordering};
55
use std::sync::mpsc::channel;
6-
use std::sync::{Arc, Condvar, MappedMutexGuard, Mutex, MutexGuard, TryLockError};
6+
use std::sync::{Arc, MappedMutexGuard, Mutex, MutexGuard, TryLockError};
77
use std::{hint, mem, thread};
88

99
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -423,38 +423,6 @@ fn test_replace_poison() {
423423
inner(|| NonCopyNeedsDrop(10), || NonCopyNeedsDrop(20));
424424
}
425425

426-
#[test]
427-
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
428-
fn test_arc_condvar_poison() {
429-
struct Packet<T>(Arc<(Mutex<T>, Condvar)>);
430-
431-
let packet = Packet(Arc::new((Mutex::new(1), Condvar::new())));
432-
let packet2 = Packet(packet.0.clone());
433-
let (tx, rx) = channel();
434-
435-
let _t = thread::spawn(move || -> () {
436-
rx.recv().unwrap();
437-
let &(ref lock, ref cvar) = &*packet2.0;
438-
let _g = lock.lock().unwrap();
439-
cvar.notify_one();
440-
// Parent should fail when it wakes up.
441-
panic!();
442-
});
443-
444-
let &(ref lock, ref cvar) = &*packet.0;
445-
let mut lock = lock.lock().unwrap();
446-
tx.send(()).unwrap();
447-
while *lock == 1 {
448-
match cvar.wait(lock) {
449-
Ok(l) => {
450-
lock = l;
451-
assert_eq!(*lock, 1);
452-
}
453-
Err(..) => break,
454-
}
455-
}
456-
}
457-
458426
#[test]
459427
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
460428
fn test_mutex_arc_poison() {

0 commit comments

Comments
 (0)