From: Matt Corallo Date: Mon, 14 Nov 2022 23:08:31 +0000 (+0000) Subject: test that should repro it X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=f0fe67b18fb26d3d5356a2551fb7a5b560edefb5;p=rust-lightning test that should repro it --- diff --git a/lightning/Cargo.toml b/lightning/Cargo.toml index 543c674ec..50f85378c 100644 --- a/lightning/Cargo.toml +++ b/lightning/Cargo.toml @@ -51,6 +51,7 @@ core2 = { version = "0.3.0", optional = true, default-features = false } [dev-dependencies] hex = "0.4" regex = "1.5.6" +tokio = { version = "1", features = [ "io-util", "macros", "rt", "rt-multi-thread", "sync", "net", "time" ] } [dev-dependencies.bitcoin] version = "0.29.0" diff --git a/lightning/src/util/wakers.rs b/lightning/src/util/wakers.rs index 655fc9cf7..ed4045bc4 100644 --- a/lightning/src/util/wakers.rs +++ b/lightning/src/util/wakers.rs @@ -385,6 +385,42 @@ mod tests { (a, waker) } + use tokio; + #[tokio::test] + async fn tok_test() { + let notifier = Arc::new(Notifier::new()); + +let start = std::time::Instant::now(); + + let nt = Arc::clone(¬ifier); + let t = std::thread::spawn(move || { +eprintln!("{:?}, In Thread!", std::time::Instant::now() - start); + std::thread::sleep(std::time::Duration::from_secs(1)); +eprintln!("{:?}, Waking 1...", std::time::Instant::now() - start); + nt.notify(); + std::thread::sleep(std::time::Duration::from_secs(10)); +eprintln!("{:?}, Waking 2...", std::time::Instant::now() - start); + nt.notify(); + }); + + let mut pm_timer = tokio::time::interval(Duration::from_secs(5)); + for _ in 0..5 { +eprintln!("{:?}, Sleeping..", std::time::Instant::now() - start); + tokio::select! { + _ = notifier.get_future() => { +eprintln!("{:?}, HIIIIIIIII", std::time::Instant::now() - start); + } + _ = pm_timer.tick() => { +eprintln!("{:?}, PMT", std::time::Instant::now() - start); + } + }; + } +eprintln!("{:?}, DONE", std::time::Instant::now() - start); +t.join(); +eprintln!("{:?}: Joined", std::time::Instant::now() - start); +panic!(); + } + #[test] fn test_future() { let mut future = Future {