Add Waker::will_wake tests

Currently fails:

    ---- task::test_waker_will_wake_clone stdout ----
    thread 'task::test_waker_will_wake_clone' panicked at library/alloc/tests/task.rs:17:5:
    assertion failed: waker.will_wake(&clone)
This commit is contained in:
David Tolnay 2024-02-25 20:53:48 -08:00
parent 0250ef2571
commit 793b45f53a
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 36 additions and 0 deletions

View File

@ -41,6 +41,7 @@
#![feature(thin_box)] #![feature(thin_box)]
#![feature(strict_provenance)] #![feature(strict_provenance)]
#![feature(drain_keep_rest)] #![feature(drain_keep_rest)]
#![feature(local_waker)]
#![allow(internal_features)] #![allow(internal_features)]
#![deny(fuzzy_provenance_casts)] #![deny(fuzzy_provenance_casts)]
#![deny(unsafe_op_in_unsafe_fn)] #![deny(unsafe_op_in_unsafe_fn)]
@ -62,6 +63,7 @@
mod slice; mod slice;
mod str; mod str;
mod string; mod string;
mod task;
mod thin_box; mod thin_box;
mod vec; mod vec;
mod vec_deque; mod vec_deque;

View File

@ -0,0 +1,34 @@
use alloc::rc::Rc;
use alloc::sync::Arc;
use alloc::task::{LocalWake, Wake};
use core::task::{LocalWaker, Waker};
#[test]
fn test_waker_will_wake_clone() {
struct NoopWaker;
impl Wake for NoopWaker {
fn wake(self: Arc<Self>) {}
}
let waker = Waker::from(Arc::new(NoopWaker));
let clone = waker.clone();
assert!(waker.will_wake(&clone));
assert!(clone.will_wake(&waker));
}
#[test]
fn test_local_waker_will_wake_clone() {
struct NoopWaker;
impl LocalWake for NoopWaker {
fn wake(self: Rc<Self>) {}
}
let waker = LocalWaker::from(Rc::new(NoopWaker));
let clone = waker.clone();
assert!(waker.will_wake(&clone));
assert!(clone.will_wake(&waker));
}