X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Futil%2Fwakers.rs;h=8eb6c25c6189b6aa27dcc62266dc9a40b709f689;hb=593d8c4610f082441563d4906d64175a354b1cfc;hp=166771948fad62bc2f10078b5360fb67207f50f5;hpb=7bc52aa62cb3c32f51b242ad3fa0ae16aee80cec;p=rust-lightning diff --git a/lightning/src/util/wakers.rs b/lightning/src/util/wakers.rs index 16677194..8eb6c25c 100644 --- a/lightning/src/util/wakers.rs +++ b/lightning/src/util/wakers.rs @@ -15,9 +15,9 @@ use alloc::sync::Arc; use core::mem; -use sync::{Condvar, Mutex}; +use crate::sync::{Condvar, Mutex}; -use prelude::*; +use crate::prelude::*; #[cfg(any(test, feature = "std"))] use std::time::{Duration, Instant}; @@ -103,7 +103,7 @@ impl Notifier { Future { state: Arc::new(Mutex::new(FutureState { callbacks: Vec::new(), - complete: false, + complete: true, })) } } else if let Some(existing_state) = &lock.1 { @@ -217,10 +217,24 @@ mod tests { use core::future::Future as FutureTrait; use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker}; + #[test] + fn notifier_pre_notified_future() { + // Previously, if we generated a future after a `Notifier` had been notified, the future + // would never complete. This tests this behavior, ensuring the future instead completes + // immediately. + let notifier = Notifier::new(); + notifier.notify(); + + let callback = Arc::new(AtomicBool::new(false)); + let callback_ref = Arc::clone(&callback); + notifier.get_future().register_callback(Box::new(move || assert!(!callback_ref.fetch_or(true, Ordering::SeqCst)))); + assert!(callback.load(Ordering::SeqCst)); + } + #[cfg(feature = "std")] #[test] fn test_wait_timeout() { - use sync::Arc; + use crate::sync::Arc; use std::thread; let persistence_notifier = Arc::new(Notifier::new());