Skip to content

Commit

Permalink
Test closing incoming connections before a response is sent
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralith committed Feb 25, 2024
1 parent 88e6958 commit 1ed8e97
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
27 changes: 27 additions & 0 deletions quinn-proto/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,33 @@ fn instant_close_2() {
);
}

#[test]
fn instant_server_close() {
let _guard = subscribe();
let mut pair = Pair::default();
info!("connecting");
pair.begin_connect(client_config());
pair.drive_client();
pair.server.drive_incoming(pair.time, pair.client.addr);
let server_ch = pair.server.assert_accept();
info!("closing");
pair.server
.connections
.get_mut(&server_ch)
.unwrap()
.close(pair.time, VarInt(42), Bytes::new());
pair.drive();
assert_matches!(
pair.client_conn_mut(server_ch).poll(),
Some(Event::ConnectionLost {
reason: ConnectionError::ConnectionClosed(ConnectionClose {
error_code: TransportErrorCode::APPLICATION_ERROR,
..
}),
})
);
}

#[test]
fn idle_timeout() {
let _guard = subscribe();
Expand Down
10 changes: 10 additions & 0 deletions quinn-proto/src/tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ impl TestEndpoint {
}

pub(super) fn drive(&mut self, now: Instant, remote: SocketAddr) {
self.drive_incoming(now, remote);
self.drive_outgoing(now);
}

pub(super) fn drive_incoming(&mut self, now: Instant, remote: SocketAddr) {
if let Some(ref socket) = self.socket {
loop {
let mut buf = [0; 8192];
Expand Down Expand Up @@ -360,6 +365,11 @@ impl TestEndpoint {
}
}
}
}

pub(super) fn drive_outgoing(&mut self, now: Instant) {
let buffer_size = self.endpoint.config().get_max_udp_payload_size() as usize;
let mut buf = BytesMut::with_capacity(buffer_size);

loop {
let mut endpoint_events: Vec<(ConnectionHandle, EndpointEvent)> = vec![];
Expand Down

0 comments on commit 1ed8e97

Please sign in to comment.