Skip to content

Commit

Permalink
tests: Add test for #154
Browse files Browse the repository at this point in the history
* Test to prevent double registration from unregistering source

* amending to clippy + fmt and windows borrow_mut rules

* moving to TcpListener

* new register instead of binding to same address
  • Loading branch information
siqpush authored Oct 11, 2023
1 parent a5da16f commit 3564317
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<TcpListener>::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::<TcpStream>::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(())
})
}

0 comments on commit 3564317

Please sign in to comment.