Skip to content

Commit 793b45f

Browse files
committed
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)
1 parent 0250ef2 commit 793b45f

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

library/alloc/tests/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#![feature(thin_box)]
4242
#![feature(strict_provenance)]
4343
#![feature(drain_keep_rest)]
44+
#![feature(local_waker)]
4445
#![allow(internal_features)]
4546
#![deny(fuzzy_provenance_casts)]
4647
#![deny(unsafe_op_in_unsafe_fn)]
@@ -62,6 +63,7 @@ mod rc;
6263
mod slice;
6364
mod str;
6465
mod string;
66+
mod task;
6567
mod thin_box;
6668
mod vec;
6769
mod vec_deque;

library/alloc/tests/task.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use alloc::rc::Rc;
2+
use alloc::sync::Arc;
3+
use alloc::task::{LocalWake, Wake};
4+
use core::task::{LocalWaker, Waker};
5+
6+
#[test]
7+
fn test_waker_will_wake_clone() {
8+
struct NoopWaker;
9+
10+
impl Wake for NoopWaker {
11+
fn wake(self: Arc<Self>) {}
12+
}
13+
14+
let waker = Waker::from(Arc::new(NoopWaker));
15+
let clone = waker.clone();
16+
17+
assert!(waker.will_wake(&clone));
18+
assert!(clone.will_wake(&waker));
19+
}
20+
21+
#[test]
22+
fn test_local_waker_will_wake_clone() {
23+
struct NoopWaker;
24+
25+
impl LocalWake for NoopWaker {
26+
fn wake(self: Rc<Self>) {}
27+
}
28+
29+
let waker = LocalWaker::from(Rc::new(NoopWaker));
30+
let clone = waker.clone();
31+
32+
assert!(waker.will_wake(&clone));
33+
assert!(clone.will_wake(&waker));
34+
}

0 commit comments

Comments
 (0)