Add notify tests

This commit is contained in:
Stjepan Glavina 2020-08-15 08:23:45 +02:00
parent cd0c0925c7
commit 49cdfb8d5a
3 changed files with 39 additions and 2 deletions

View File

@ -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.

36
tests/notify.rs Normal file
View File

@ -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(())
}

View File

@ -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();