extern crate tcplistener_accept_timeout; use tcplistener_accept_timeout::TcpListenerAcceptTimeout; use std::net::{TcpListener, TcpStream, Ipv4Addr}; use std::time::Duration; use std::thread; #[test] fn expire() { let listener = TcpListener::bind((Ipv4Addr::LOCALHOST, 0)).unwrap(); assert!(!listener.connection_pending(Some(Duration::from_millis(100)))); assert!(listener.accept_timeout(Some(Duration::from_millis(1000))).is_none()); } #[test] fn accepted() { let listener = TcpListener::bind((Ipv4Addr::LOCALHOST, 0)).unwrap(); let addr = listener.local_addr().unwrap(); thread::spawn(move || { thread::sleep(Duration::from_millis(500)); TcpStream::connect(addr).unwrap(); }); assert!(!listener.connection_pending(Some(Duration::from_millis(200)))); assert!(listener.connection_pending(Some(Duration::from_millis(400)))); assert!(listener.connection_pending(None)); assert!(listener.accept_timeout(Some(Duration::from_millis(1000))).unwrap().is_ok()); }