mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-28 00:00:11 +02:00
sync: Add LockFuture for Lock (#1184)
This commit is contained in:
committed by
Carl Lerche
parent
448302c3d4
commit
e2b4bdb647
@@ -1,5 +1,7 @@
|
||||
#![deny(warnings, rust_2018_idioms)]
|
||||
|
||||
use pin_utils::pin_mut;
|
||||
use std::future::Future;
|
||||
use tokio_sync::lock::Lock;
|
||||
use tokio_test::task::MockTask;
|
||||
use tokio_test::{assert_pending, assert_ready};
|
||||
@@ -48,3 +50,29 @@ fn readiness() {
|
||||
assert!(t2.is_woken());
|
||||
assert_ready!(t2.enter(|cx| l.poll_lock(cx)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lock() {
|
||||
let mut lock = Lock::new(false);
|
||||
|
||||
let mut lock2 = lock.clone();
|
||||
std::thread::spawn(move || {
|
||||
let l = lock2.lock();
|
||||
pin_mut!(l);
|
||||
|
||||
let mut task = MockTask::new();
|
||||
let mut g = task.enter(|cx| assert_ready!(l.poll(cx)));
|
||||
std::thread::sleep(std::time::Duration::from_millis(500));
|
||||
*g = true;
|
||||
drop(g);
|
||||
});
|
||||
|
||||
std::thread::sleep(std::time::Duration::from_millis(50));
|
||||
let mut task = MockTask::new();
|
||||
let l = lock.lock();
|
||||
pin_mut!(l);
|
||||
|
||||
task.enter(|cx| assert_pending!(l.poll(cx)));
|
||||
std::thread::sleep(std::time::Duration::from_millis(500));
|
||||
assert!(task.is_woken());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user