test that should repro it
authorMatt Corallo <git@bluematt.me>
Mon, 14 Nov 2022 23:08:31 +0000 (23:08 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 14 Nov 2022 23:08:31 +0000 (23:08 +0000)
lightning/Cargo.toml
lightning/src/util/wakers.rs

index 543c674ec35cc5e0969a891a8ce100b61dff07a7..50f85378cc66678f83a3db3221b0274831f571e8 100644 (file)
@@ -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"
index 655fc9cf7ed5db8f6bfbbc9285eb3c6bef94f037..ed4045bc47bc186d7dad850300e61446103766ff 100644 (file)
@@ -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(&notifier);
+               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 {