diff --git a/tests/async.rs b/tests/async.rs index 45c2e3b..9218e71 100644 --- a/tests/async.rs +++ b/tests/async.rs @@ -356,3 +356,30 @@ fn shutdown() -> io::Result<()> { Ok(()) }) } + +// prevent source from unregistering by trying to register it twice +#[test] +fn duplicate_socket_insert() -> io::Result<()> { + future::block_on(async { + let listener = Async::::bind(([127, 0, 0, 1], 0))?; + let addr = listener.as_ref().local_addr()?; + + // attempt to register twice + assert!(Async::new(&listener).is_err(), "fails upon second insert"); + + // Read and Write to confirm socket did not deregister on duplication attempt + // Write to stream_w + let mut stream_w = Async::::connect(addr).await?; + stream_w.write(LOREM_IPSUM).await?; + stream_w.get_ref().shutdown(Shutdown::Write)?; + + // Read from stream_r + let mut stream_r = listener.accept().await?.0; + let mut buffer = vec![0; LOREM_IPSUM.len()]; + stream_r.read_exact(&mut buffer).await?; + + assert_eq!(buffer, LOREM_IPSUM); + + Ok(()) + }) +}