-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathwaker.rs
More file actions
54 lines (43 loc) · 1.48 KB
/
waker.rs
File metadata and controls
54 lines (43 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use std::time::{Duration, Instant};
use compio_runtime::ResumeUnwind;
#[test]
fn cross_thread_waker_interrupts_poll() {
let rt = compio_runtime::Runtime::new().unwrap();
rt.block_on(async {
let (tx, rx) = flume::bounded::<u32>(1);
let handle = compio_runtime::spawn(async move { rx.recv_async().await.unwrap() });
std::thread::spawn(move || {
std::thread::sleep(Duration::from_millis(10));
tx.send(42).unwrap();
});
let start = Instant::now();
let val = handle.await.resume_unwind().unwrap();
let elapsed = start.elapsed();
assert_eq!(val, 42);
assert!(
elapsed < Duration::from_millis(200),
"took {elapsed:?}, expected < 200ms"
);
});
}
#[test]
fn same_thread_waker_schedules_promptly() {
let rt = compio_runtime::Runtime::new().unwrap();
rt.block_on(async {
let (tx, rx) = flume::bounded::<u32>(1);
compio_runtime::spawn(async move {
let val = rx.recv_async().await.unwrap();
assert_eq!(val, 42);
})
.detach();
compio_runtime::time::sleep(Duration::from_millis(10)).await;
let start = Instant::now();
tx.send(42).unwrap();
compio_runtime::time::sleep(Duration::from_millis(200)).await;
let elapsed = start.elapsed();
assert!(
elapsed < Duration::from_millis(400),
"took {elapsed:?}, expected < 400ms"
);
});
}