Skip to content

Commit 2a0469e

Browse files
committed
f moar test
1 parent 5f76c12 commit 2a0469e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lightning/src/util/wakers.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,4 +575,28 @@ mod tests {
575575
assert!(woken.load(Ordering::SeqCst));
576576
assert_eq!(Pin::new(&mut future).poll(&mut Context::from_waker(&waker)), Poll::Ready(()));
577577
}
578+
579+
#[test]
580+
fn test_multi_future_sleep() {
581+
// Tests the `Sleeper` with multiple futures.
582+
let notifier_a = Notifier::new();
583+
let notifier_b = Notifier::new();
584+
585+
// Set both notifiers as woken without sleeping yet.
586+
notifier_a.notify();
587+
notifier_b.notify();
588+
Sleeper::from_two_futures(notifier_a.get_future(), notifier_b.get_future()).wait();
589+
590+
// One future has woken us up, but the other should still have a pending notification.
591+
Sleeper::from_two_futures(notifier_a.get_future(), notifier_b.get_future()).wait();
592+
593+
// However once we've slept twice, we should no longer have any pending notifications
594+
#[cfg(feature = "std")]
595+
assert!(!Sleeper::from_two_futures(notifier_a.get_future(), notifier_b.get_future())
596+
.wait_timeout(Duration::from_millis(10)));
597+
598+
// Test ordering somewhat more.
599+
notifier_a.notify();
600+
Sleeper::from_two_futures(notifier_a.get_future(), notifier_b.get_future()).wait();
601+
}
578602
}

0 commit comments

Comments
 (0)