Skip to content

Commit

Permalink
decoder: improve pending events queue test
Browse files Browse the repository at this point in the history
Check that that number of polled file descriptors returned by epoll is
also correct.
  • Loading branch information
Gnurou committed Jul 19, 2024
1 parent 6c56dab commit 2542fc6
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,38 +278,46 @@ mod tests {

// Empty queue should not signal.
let mut events = [EpollEvent::empty()];
epoll.wait(&mut events, EpollTimeout::ZERO).unwrap();
assert_eq!(events, [EpollEvent::empty()]);
let nb_fds = epoll.wait(&mut events, EpollTimeout::ZERO).unwrap();
assert_eq!(nb_fds, 0);

// Events in the queue should signal.
queue.push(());
let mut events = [EpollEvent::empty()];
epoll.wait(&mut events, EpollTimeout::ZERO).unwrap();
let nb_fds = epoll.wait(&mut events, EpollTimeout::ZERO).unwrap();
assert_eq!(nb_fds, 1);
assert_eq!(events, [EpollEvent::new(EpollFlags::EPOLLIN, 1)]);

// The queue is empty again and should not signal.
queue.next().unwrap();
let mut events = [EpollEvent::empty()];
epoll.wait(&mut events, EpollTimeout::ZERO).unwrap();
let nb_fds = epoll.wait(&mut events, EpollTimeout::ZERO).unwrap();
assert_eq!(nb_fds, 0);
assert_eq!(events, [EpollEvent::empty()]);

// Add 3 elements to the queue, it should signal until we remove them all.
queue.extend(std::iter::repeat(()).take(3));
let mut events = [EpollEvent::empty()];
epoll.wait(&mut events, EpollTimeout::ZERO).unwrap();
let nb_fds = epoll.wait(&mut events, EpollTimeout::ZERO).unwrap();
assert_eq!(nb_fds, 1);
assert_eq!(events, [EpollEvent::new(EpollFlags::EPOLLIN, 1)]);

queue.next().unwrap();
let mut events = [EpollEvent::empty()];
epoll.wait(&mut events, EpollTimeout::ZERO).unwrap();
let nb_fds = epoll.wait(&mut events, EpollTimeout::ZERO).unwrap();
assert_eq!(nb_fds, 1);
assert_eq!(events, [EpollEvent::new(EpollFlags::EPOLLIN, 1)]);

queue.next().unwrap();
let mut events = [EpollEvent::empty()];
epoll.wait(&mut events, EpollTimeout::ZERO).unwrap();
let nb_fds = epoll.wait(&mut events, EpollTimeout::ZERO).unwrap();
assert_eq!(nb_fds, 1);
assert_eq!(events, [EpollEvent::new(EpollFlags::EPOLLIN, 1)]);

queue.next().unwrap();
let mut events = [EpollEvent::empty()];
epoll.wait(&mut events, EpollTimeout::ZERO).unwrap();
let nb_fds = epoll.wait(&mut events, EpollTimeout::ZERO).unwrap();
assert_eq!(nb_fds, 0);
assert_eq!(events, [EpollEvent::empty()]);
}
}

0 comments on commit 2542fc6

Please sign in to comment.