mirror of https://github.com/smol-rs/polling
Add notify tests
This commit is contained in:
parent
cd0c0925c7
commit
49cdfb8d5a
|
@ -18,6 +18,7 @@ libc = "0.2.74"
|
|||
|
||||
[dev-dependencies]
|
||||
doc-comment = "0.3"
|
||||
easy-parallel = "3.1.0"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
# Patched version of wepoll that can be notified by PostQueuedCompletionStatus.
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
use std::io;
|
||||
use std::thread;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use easy_parallel::Parallel;
|
||||
use polling::Poller;
|
||||
|
||||
#[test]
|
||||
fn simple() -> io::Result<()> {
|
||||
let poller = Poller::new()?;
|
||||
let mut events = Vec::new();
|
||||
|
||||
for _ in 0..10 {
|
||||
poller.notify();
|
||||
poller.wait(&mut events, None);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn concurrent() -> io::Result<()> {
|
||||
let poller = Poller::new()?;
|
||||
let mut events = Vec::new();
|
||||
|
||||
for _ in 0..2 {
|
||||
Parallel::new()
|
||||
.add(|| {
|
||||
thread::sleep(Duration::from_secs(0));
|
||||
poller.notify().unwrap();
|
||||
})
|
||||
.finish(|| poller.wait(&mut events, None).unwrap());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -4,11 +4,11 @@ use std::time::{Duration, Instant};
|
|||
use polling::Poller;
|
||||
|
||||
#[test]
|
||||
fn timeout() -> io::Result<()> {
|
||||
fn twice() -> io::Result<()> {
|
||||
let poller = Poller::new()?;
|
||||
let mut events = Vec::new();
|
||||
|
||||
for _ in 0..5 {
|
||||
for _ in 0..2 {
|
||||
let start = Instant::now();
|
||||
poller.wait(&mut events, Some(Duration::from_secs(1)))?;
|
||||
let elapsed = start.elapsed();
|
||||
|
|
Loading…
Reference in New Issue