Skip to content
This repository has been archived by the owner on Jun 27, 2022. It is now read-only.

Commit

Permalink
Reinstate timeout test.
Browse files Browse the repository at this point in the history
  • Loading branch information
meqif committed Jun 22, 2015
1 parent 3a50ba0 commit 97ed76b
Showing 1 changed file with 41 additions and 46 deletions.
87 changes: 41 additions & 46 deletions src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1664,62 +1664,57 @@ mod test {
iotry!(server.recv_from(&mut buf));
}

// #[test]
// #[ignore]
// // `std::net::UdpSocket` no longer supports timeouts, so this test is deprecated for now.
// fn test_socket_timeout_request() {
// let (server_addr, client_addr) = (next_test_ip4().to_socket_addrs().unwrap().next().unwrap(),
// next_test_ip4().to_socket_addrs().unwrap().next().unwrap());
#[test]
fn test_socket_timeout_request() {
let (server_addr, client_addr) = (next_test_ip4().to_socket_addrs().unwrap().next().unwrap(),
next_test_ip4().to_socket_addrs().unwrap().next().unwrap());

// let client = iotry!(UtpSocket::bind(client_addr));
// let mut server = iotry!(UtpSocket::bind(server_addr));
// const LEN: usize = 512;
// let data = (0..LEN).map(|idx| idx as u8).collect::<Vec<u8>>();
// let d = data.clone();
let client = iotry!(UtpSocket::bind(client_addr));
let mut server = iotry!(UtpSocket::bind(server_addr));
const LEN: usize = 512;
let data = (0..LEN).map(|idx| idx as u8).collect::<Vec<u8>>();
let d = data.clone();

// assert!(server.state == SocketState::New);
// assert!(client.state == SocketState::New);
assert!(server.state == SocketState::New);
assert!(client.state == SocketState::New);

// // Check proper difference in client's send connection id and receive connection id
// assert_eq!(client.sender_connection_id, client.receiver_connection_id + 1);
// Check proper difference in client's send connection id and receive connection id
assert_eq!(client.sender_connection_id, client.receiver_connection_id + 1);

// thread::spawn(move || {
// let mut client = iotry!(UtpSocket::connect(server_addr));
// assert!(client.state == SocketState::Connected);
// assert_eq!(client.connected_to, server_addr);
// iotry!(client.send_to(&d[..]));
// drop(client);
// });
thread::spawn(move || {
let mut client = iotry!(UtpSocket::connect(server_addr));
assert!(client.state == SocketState::Connected);
assert_eq!(client.connected_to, server_addr);
iotry!(client.send_to(&d[..]));
drop(client);
});

// let mut buf = [0u8; BUF_SIZE];
// match server.recv(&mut buf) {
// e => println!("{:?}", e),
// }
// // After establishing a new connection, the server's ids are a mirror of the client's.
// assert_eq!(server.receiver_connection_id, server.sender_connection_id + 1);
// assert_eq!(server.connected_to, client_addr);
let mut buf = [0u8; BUF_SIZE];
server.recv(&mut buf).unwrap();
// After establishing a new connection, the server's ids are a mirror of the client's.
assert_eq!(server.receiver_connection_id, server.sender_connection_id + 1);

// assert!(server.state == SocketState::Connected);
assert!(server.state == SocketState::Connected);

// // Purposefully read from UDP socket directly and discard it, in order
// // to behave as if the packet was lost and thus trigger the timeout
// // handling in the *next* call to `UtpSocket.recv_from`.
// iotry!(server.socket.recv_from(&mut buf));
// Purposefully read from UDP socket directly and discard it, in order
// to behave as if the packet was lost and thus trigger the timeout
// handling in the *next* call to `UtpSocket.recv_from`.
iotry!(server.socket.recv_from(&mut buf));

// // Set a much smaller than usual timeout, for quicker test completion
// server.congestion_timeout = 50;
// Set a much smaller than usual timeout, for quicker test completion
server.congestion_timeout = 50;

// // Now wait for the previously discarded packet
// loop {
// match server.recv_from(&mut buf) {
// Ok((0, _)) => continue,
// Ok(_) => break,
// Err(e) => panic!("{:?}", e),
// }
// }
// Now wait for the previously discarded packet
loop {
match server.recv_from(&mut buf) {
Ok((0, _)) => continue,
Ok(_) => break,
Err(e) => panic!("{}", e),
}
}

// drop(server);
// }
drop(server);
}

#[test]
fn test_sorted_buffer_insertion() {
Expand Down

0 comments on commit 97ed76b

Please sign in to comment.