Use rustfmt to enforce consistent formatting

This change adds a .rustfmt.toml that includes ALL supported settings,
12 of which we have overridden to attempt to cater to our own
proclivities.

rustfmt is checked in the rust-nightly CI job.
This commit is contained in:
Oliver Gould
2017-09-08 17:20:41 +00:00
parent 93925e6d1f
commit 897bf84163
60 changed files with 2087 additions and 1620 deletions

View File

@@ -13,8 +13,7 @@ fn handshake() {
.write(SETTINGS_ACK)
.build();
let h2 = Client::handshake(mock)
.wait().unwrap();
let h2 = Client::handshake(mock).wait().unwrap();
trace!("hands have been shook");
@@ -40,13 +39,13 @@ fn recv_invalid_server_stream_id() {
.write(&[0, 0, 8, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
.build();
let mut h2 = Client::handshake(mock)
.wait().unwrap();
let mut h2 = Client::handshake(mock).wait().unwrap();
// Send the request
let request = Request::builder()
.uri("https://http2.akamai.com/")
.body(()).unwrap();
.body(())
.unwrap();
info!("sending request");
let stream = h2.request(request, true).unwrap();
@@ -60,19 +59,16 @@ fn recv_invalid_server_stream_id() {
#[test]
#[ignore]
fn request_without_scheme() {
}
fn request_without_scheme() {}
#[test]
#[ignore]
fn request_with_h1_version() {
}
fn request_with_h1_version() {}
#[test]
#[ignore]
fn sending_request_on_closed_soket() {
}
fn sending_request_on_closed_soket() {}
const SETTINGS: &'static [u8] = &[0, 0, 0, 4, 0, 0, 0, 0, 0];
const SETTINGS_ACK: &'static [u8] = &[0, 0, 0, 4, 1, 0, 0, 0, 0];

View File

@@ -6,16 +6,13 @@ use std::error::Error;
#[test]
fn read_none() {
let mut codec = Codec::from(
mock_io::Builder::new()
.build());
let mut codec = Codec::from(mock_io::Builder::new().build());
assert_closed!(codec);
}
#[test]
fn read_frame_too_big() {
}
fn read_frame_too_big() {}
// ===== DATA =====
@@ -103,16 +100,13 @@ fn read_data_stream_id_zero() {
// ===== HEADERS =====
#[test]
fn read_headers_without_pseudo() {
}
fn read_headers_without_pseudo() {}
#[test]
fn read_headers_with_pseudo() {
}
fn read_headers_with_pseudo() {}
#[test]
fn read_headers_empty_payload() {
}
fn read_headers_empty_payload() {}
#[test]
fn update_max_frame_len_at_rest() {
@@ -130,5 +124,6 @@ fn update_max_frame_len_at_rest() {
codec.set_max_recv_frame_size(2);
assert_eq!(codec.max_recv_frame_size(), 2);
assert_eq!(codec.poll().unwrap_err().description(), "frame size too big");
assert_eq!(codec.poll().unwrap_err().description(),
"frame size too big");
}

View File

@@ -0,0 +1 @@

View File

@@ -27,13 +27,13 @@ fn send_data_without_requesting_capacity() {
.read(&[0, 0, 1, 1, 5, 0, 0, 0, 1, 0x89])
.build();
let mut h2 = Client::handshake(mock)
.wait().unwrap();
let mut h2 = Client::handshake(mock).wait().unwrap();
let request = Request::builder()
.method(Method::POST)
.uri("https://http2.akamai.com/")
.body(()).unwrap();
.body(())
.unwrap();
let mut stream = h2.request(request, false).unwrap();
@@ -82,14 +82,14 @@ fn release_capacity_sends_window_update() {
// gotta end the connection
.map(drop);
let h2 = Client::handshake(io).unwrap()
.and_then(|mut h2| {
let request = Request::builder()
.method(Method::GET)
.uri("https://http2.akamai.com/")
.body(()).unwrap();
let h2 = Client::handshake(io).unwrap().and_then(|mut h2| {
let request = Request::builder()
.method(Method::GET)
.uri("https://http2.akamai.com/")
.body(())
.unwrap();
let req = h2.request(request, true).unwrap()
let req = h2.request(request, true).unwrap()
.unwrap()
// Get the response
.and_then(|resp| {
@@ -117,8 +117,8 @@ fn release_capacity_sends_window_update() {
assert_eq!(buf.unwrap().len(), payload.len());
Ok(())
});
h2.unwrap().join(req)
});
h2.unwrap().join(req)
});
h2.join(mock).wait().unwrap();
}
@@ -145,14 +145,14 @@ fn release_capacity_of_small_amount_does_not_send_window_update() {
// gotta end the connection
.map(drop);
let h2 = Client::handshake(io).unwrap()
.and_then(|mut h2| {
let request = Request::builder()
.method(Method::GET)
.uri("https://http2.akamai.com/")
.body(()).unwrap();
let h2 = Client::handshake(io).unwrap().and_then(|mut h2| {
let request = Request::builder()
.method(Method::GET)
.uri("https://http2.akamai.com/")
.body(())
.unwrap();
let req = h2.request(request, true).unwrap()
let req = h2.request(request, true).unwrap()
.unwrap()
// Get the response
.and_then(|resp| {
@@ -171,20 +171,18 @@ fn release_capacity_of_small_amount_does_not_send_window_update() {
assert!(buf.is_none());
Ok(())
});
h2.unwrap().join(req)
});
h2.unwrap().join(req)
});
h2.join(mock).wait().unwrap();
}
#[test]
#[ignore]
fn expand_window_sends_window_update() {
}
fn expand_window_sends_window_update() {}
#[test]
#[ignore]
fn expand_window_calls_are_coalesced() {
}
fn expand_window_calls_are_coalesced() {}
#[test]
fn recv_data_overflows_connection_window() {
@@ -212,23 +210,23 @@ fn recv_data_overflows_connection_window() {
.send_frame(frames::data(1, vec![0u8; 128]).eos())
// expecting goaway for the conn, not stream
.recv_frame(frames::go_away(0).flow_control());
// connection is ended by client
// connection is ended by client
let h2 = Client::handshake(io).unwrap()
.and_then(|mut h2| {
let request = Request::builder()
.method(Method::GET)
.uri("https://http2.akamai.com/")
.body(()).unwrap();
let h2 = Client::handshake(io).unwrap().and_then(|mut h2| {
let request = Request::builder()
.method(Method::GET)
.uri("https://http2.akamai.com/")
.body(())
.unwrap();
let req = h2.request(request, true).unwrap()
.unwrap()
.and_then(|resp| {
assert_eq!(resp.status(), StatusCode::OK);
let body = resp.into_parts().1;
body.concat2()
.unwrap()
/* FIXME: body stream should error also
let req = h2.request(request, true)
.unwrap()
.unwrap()
.and_then(|resp| {
assert_eq!(resp.status(), StatusCode::OK);
let body = resp.into_parts().1;
body.concat2().unwrap()
/* FIXME: body stream should error also
.then(|res| {
let err = res.unwrap_err();
assert_eq!(
@@ -238,21 +236,18 @@ fn recv_data_overflows_connection_window() {
Ok::<(), ()>(())
})
*/
});
// client should see a flow control error
let conn = h2.then(|res| {
let err = res.unwrap_err();
assert_eq!(
err.to_string(),
"protocol error: flow-control protocol violated"
);
Ok::<(), ()>(())
});
conn.unwrap().join(req)
});
h2.join(mock).wait().unwrap();
// client should see a flow control error
let conn = h2.then(|res| {
let err = res.unwrap_err();
assert_eq!(err.to_string(),
"protocol error: flow-control protocol violated");
Ok::<(), ()>(())
});
conn.unwrap().join(req)
});
h2.join(mock).wait().unwrap();
}
#[test]
@@ -274,52 +269,52 @@ fn stream_close_by_data_frame_releases_capacity() {
let window_size = frame::DEFAULT_INITIAL_WINDOW_SIZE as usize;
let h2 = Client::handshake(m).unwrap()
.and_then(|mut h2| {
let request = Request::builder()
.method(Method::POST)
.uri("https://http2.akamai.com/")
.body(()).unwrap();
let h2 = Client::handshake(m).unwrap().and_then(|mut h2| {
let request = Request::builder()
.method(Method::POST)
.uri("https://http2.akamai.com/")
.body(())
.unwrap();
// Send request
let mut s1 = h2.request(request, false).unwrap();
// Send request
let mut s1 = h2.request(request, false).unwrap();
// This effectively reserves the entire connection window
s1.reserve_capacity(window_size);
// This effectively reserves the entire connection window
s1.reserve_capacity(window_size);
// The capacity should be immediately available as nothing else is
// happening on the stream.
assert_eq!(s1.capacity(), window_size);
// The capacity should be immediately available as nothing else is
// happening on the stream.
assert_eq!(s1.capacity(), window_size);
let request = Request::builder()
.method(Method::POST)
.uri("https://http2.akamai.com/")
.body(()).unwrap();
let request = Request::builder()
.method(Method::POST)
.uri("https://http2.akamai.com/")
.body(())
.unwrap();
// Create a second stream
let mut s2 = h2.request(request, false).unwrap();
// Create a second stream
let mut s2 = h2.request(request, false).unwrap();
// Request capacity
s2.reserve_capacity(5);
// Request capacity
s2.reserve_capacity(5);
// There should be no available capacity (as it is being held up by
// the previous stream
assert_eq!(s2.capacity(), 0);
// There should be no available capacity (as it is being held up by
// the previous stream
assert_eq!(s2.capacity(), 0);
// Closing the previous stream by sending an empty data frame will
// release the capacity to s2
s1.send_data("".into(), true).unwrap();
// Closing the previous stream by sending an empty data frame will
// release the capacity to s2
s1.send_data("".into(), true).unwrap();
// The capacity should be available
assert_eq!(s2.capacity(), 5);
// The capacity should be available
assert_eq!(s2.capacity(), 5);
// Send the frame
s2.send_data("hello".into(), true).unwrap();
// Send the frame
s2.send_data("hello".into(), true).unwrap();
// Wait for the connection to close
h2.unwrap()
})
;
// Wait for the connection to close
h2.unwrap()
});
let mock = mock.assert_client_handshake().unwrap()
// Get the first frame
@@ -357,11 +352,9 @@ fn stream_close_by_data_frame_releases_capacity() {
assert!(data.is_end_stream());
Ok(())
})
;
});
let _ = h2.join(mock)
.wait().unwrap();
let _ = h2.join(mock).wait().unwrap();
}
#[test]
@@ -371,52 +364,52 @@ fn stream_close_by_trailers_frame_releases_capacity() {
let window_size = frame::DEFAULT_INITIAL_WINDOW_SIZE as usize;
let h2 = Client::handshake(m).unwrap()
.and_then(|mut h2| {
let request = Request::builder()
.method(Method::POST)
.uri("https://http2.akamai.com/")
.body(()).unwrap();
let h2 = Client::handshake(m).unwrap().and_then(|mut h2| {
let request = Request::builder()
.method(Method::POST)
.uri("https://http2.akamai.com/")
.body(())
.unwrap();
// Send request
let mut s1 = h2.request(request, false).unwrap();
// Send request
let mut s1 = h2.request(request, false).unwrap();
// This effectively reserves the entire connection window
s1.reserve_capacity(window_size);
// This effectively reserves the entire connection window
s1.reserve_capacity(window_size);
// The capacity should be immediately available as nothing else is
// happening on the stream.
assert_eq!(s1.capacity(), window_size);
// The capacity should be immediately available as nothing else is
// happening on the stream.
assert_eq!(s1.capacity(), window_size);
let request = Request::builder()
.method(Method::POST)
.uri("https://http2.akamai.com/")
.body(()).unwrap();
let request = Request::builder()
.method(Method::POST)
.uri("https://http2.akamai.com/")
.body(())
.unwrap();
// Create a second stream
let mut s2 = h2.request(request, false).unwrap();
// Create a second stream
let mut s2 = h2.request(request, false).unwrap();
// Request capacity
s2.reserve_capacity(5);
// Request capacity
s2.reserve_capacity(5);
// There should be no available capacity (as it is being held up by
// the previous stream
assert_eq!(s2.capacity(), 0);
// There should be no available capacity (as it is being held up by
// the previous stream
assert_eq!(s2.capacity(), 0);
// Closing the previous stream by sending a trailers frame will
// release the capacity to s2
s1.send_trailers(Default::default()).unwrap();
// Closing the previous stream by sending a trailers frame will
// release the capacity to s2
s1.send_trailers(Default::default()).unwrap();
// The capacity should be available
assert_eq!(s2.capacity(), 5);
// The capacity should be available
assert_eq!(s2.capacity(), 5);
// Send the frame
s2.send_data("hello".into(), true).unwrap();
// Send the frame
s2.send_data("hello".into(), true).unwrap();
// Wait for the connection to close
h2.unwrap()
})
;
// Wait for the connection to close
h2.unwrap()
});
let mock = mock.assert_client_handshake().unwrap()
// Get the first frame
@@ -453,22 +446,18 @@ fn stream_close_by_trailers_frame_releases_capacity() {
assert!(data.is_end_stream());
Ok(())
})
;
});
let _ = h2.join(mock)
.wait().unwrap();
let _ = h2.join(mock).wait().unwrap();
}
#[test]
#[ignore]
fn stream_close_by_send_reset_frame_releases_capacity() {
}
fn stream_close_by_send_reset_frame_releases_capacity() {}
#[test]
#[ignore]
fn stream_close_by_recv_reset_frame_releases_capacity() {
}
fn stream_close_by_recv_reset_frame_releases_capacity() {}
use futures::{Async, Poll};
@@ -496,19 +485,21 @@ fn recv_window_update_on_stream_closed_by_data_frame() {
let _ = ::env_logger::init();
let (io, srv) = mock::new();
let h2 = Client::handshake(io).unwrap()
let h2 = Client::handshake(io)
.unwrap()
.and_then(|mut h2| {
let request = Request::builder()
.method(Method::POST)
.uri("https://http2.akamai.com/")
.body(()).unwrap();
.body(())
.unwrap();
let stream = h2.request(request, false).unwrap();
// Wait for the response
h2.drive(GetResponse {
stream: Some(stream),
})
stream: Some(stream),
})
})
.and_then(|(h2, (response, mut stream))| {
assert_eq!(response.status(), StatusCode::OK);
@@ -518,26 +509,18 @@ fn recv_window_update_on_stream_closed_by_data_frame() {
// Wait for the connection to close
h2.unwrap()
})
;
});
let srv = srv.assert_client_handshake().unwrap()
let srv = srv.assert_client_handshake()
.unwrap()
.recv_settings()
.recv_frame(
frames::headers(1)
.request("POST", "https://http2.akamai.com/")
)
.send_frame(
frames::headers(1)
.response(200)
)
.recv_frame(frames::headers(1).request("POST", "https://http2.akamai.com/"))
.send_frame(frames::headers(1).response(200))
.recv_frame(frames::data(1, "hello").eos())
.send_frame(frames::window_update(1, 5))
.map(drop)
;
.map(drop);
let _ = h2.join(srv)
.wait().unwrap();
let _ = h2.join(srv).wait().unwrap();
}
#[test]
@@ -545,12 +528,14 @@ fn reserved_capacity_assigned_in_multi_window_updates() {
let _ = ::env_logger::init();
let (io, srv) = mock::new();
let h2 = Client::handshake(io).unwrap()
let h2 = Client::handshake(io)
.unwrap()
.and_then(|mut h2| {
let request = Request::builder()
.method(Method::POST)
.uri("https://http2.akamai.com/")
.body(()).unwrap();
.body(())
.unwrap();
let mut stream = h2.request(request, false).unwrap();
@@ -567,15 +552,16 @@ fn reserved_capacity_assigned_in_multi_window_updates() {
stream.send_data("hello".into(), false).unwrap();
stream.send_data("world".into(), true).unwrap();
h2.drive(GetResponse { stream: Some(stream) })
h2.drive(GetResponse {
stream: Some(stream),
})
})
.and_then(|(h2, (response, _))| {
assert_eq!(response.status(), StatusCode::NO_CONTENT);
// Wait for the connection to close
h2.unwrap()
})
;
});
let srv = srv.assert_client_handshake().unwrap()
.recv_settings()
@@ -613,9 +599,7 @@ fn reserved_capacity_assigned_in_multi_window_updates() {
.recv_frame(frames::data(1, "hello").eos())
.send_frame(frames::window_update(1, 5))
*/
.map(drop)
;
.map(drop);
let _ = h2.join(srv)
.wait().unwrap();
let _ = h2.join(srv).wait().unwrap();
}

View File

@@ -8,10 +8,10 @@ fn recv_single_ping() {
let (m, mock) = mock::new();
// Create the handshake
let h2 = Client::handshake(m).unwrap()
.and_then(|conn| conn.unwrap());
let h2 = Client::handshake(m).unwrap().and_then(|conn| conn.unwrap());
let mock = mock.assert_client_handshake().unwrap()
let mock = mock.assert_client_handshake()
.unwrap()
.and_then(|(_, mut mock)| {
let frame = frame::Ping::new();
mock.send(frame.into()).unwrap();
@@ -30,6 +30,5 @@ fn recv_single_ping() {
Ok(())
});
let _ = h2.join(mock)
.wait().unwrap();
let _ = h2.join(mock).wait().unwrap();
}

View File

@@ -25,13 +25,13 @@ fn single_stream_send_large_body() {
.read(&[0, 0, 1, 1, 5, 0, 0, 0, 1, 0x89])
.build();
let mut h2 = Client::handshake(mock)
.wait().unwrap();
let mut h2 = Client::handshake(mock).wait().unwrap();
let request = Request::builder()
.method(Method::POST)
.uri("https://http2.akamai.com/")
.body(()).unwrap();
.body(())
.unwrap();
let mut stream = h2.request(request, false).unwrap();
@@ -79,13 +79,13 @@ fn single_stream_send_extra_large_body_multi_frames_one_buffer() {
.read(&[0, 0, 1, 1, 5, 0, 0, 0, 1, 0x89])
.build();
let mut h2 = Client::handshake(mock)
.wait().unwrap();
let mut h2 = Client::handshake(mock).wait().unwrap();
let request = Request::builder()
.method(Method::POST)
.uri("https://http2.akamai.com/")
.body(()).unwrap();
.body(())
.unwrap();
let mut stream = h2.request(request, false).unwrap();
@@ -144,13 +144,13 @@ fn single_stream_send_extra_large_body_multi_frames_multi_buffer() {
.read(&[0, 0, 1, 1, 5, 0, 0, 0, 1, 0x89])
.build();
let mut h2 = Client::handshake(mock)
.wait().unwrap();
let mut h2 = Client::handshake(mock).wait().unwrap();
let request = Request::builder()
.method(Method::POST)
.uri("https://http2.akamai.com/")
.body(()).unwrap();
.body(())
.unwrap();
let mut stream = h2.request(request, false).unwrap();
@@ -175,12 +175,14 @@ fn send_data_receive_window_update() {
let _ = ::env_logger::init();
let (m, mock) = mock::new();
let h2 = Client::handshake(m).unwrap()
let h2 = Client::handshake(m)
.unwrap()
.and_then(|mut h2| {
let request = Request::builder()
.method(Method::POST)
.uri("https://http2.akamai.com/")
.body(()).unwrap();
.body(())
.unwrap();
// Send request
let mut stream = h2.request(request, false).unwrap();
@@ -240,9 +242,7 @@ fn send_data_receive_window_update() {
let data = assert_data!(frame.unwrap());
assert_eq!(data.payload().len(), (frame::DEFAULT_MAX_FRAME_SIZE-1) as usize);
Ok(())
})
;
});
let _ = h2.join(mock)
.wait().unwrap();
let _ = h2.join(mock).wait().unwrap();
}

View File

@@ -17,13 +17,11 @@ fn read_preface_in_multiple_frames() {
.read(SETTINGS_ACK)
.build();
let h2 = Server::handshake(mock)
.wait().unwrap();
let h2 = Server::handshake(mock).wait().unwrap();
assert!(Stream::wait(h2).next().is_none());
}
#[test]
#[ignore]
fn accept_with_pending_connections_after_socket_close() {
}
fn accept_with_pending_connections_after_socket_close() {}

View File

@@ -20,13 +20,13 @@ fn send_recv_headers_only() {
.read(&[0, 0, 1, 1, 5, 0, 0, 0, 1, 0x89])
.build();
let mut h2 = Client::handshake(mock)
.wait().unwrap();
let mut h2 = Client::handshake(mock).wait().unwrap();
// Send the request
let request = Request::builder()
.uri("https://http2.akamai.com/")
.body(()).unwrap();
.body(())
.unwrap();
info!("sending request");
let mut stream = h2.request(request, true).unwrap();
@@ -62,13 +62,13 @@ fn send_recv_data() {
])
.build();
let mut h2 = Client::handshake2(mock)
.wait().unwrap();
let mut h2 = Client::handshake2(mock).wait().unwrap();
let request = Request::builder()
.method(Method::POST)
.uri("https://http2.akamai.com/")
.body(()).unwrap();
.body(())
.unwrap();
info!("sending request");
let mut stream = h2.request(request, false).unwrap();
@@ -119,13 +119,13 @@ fn send_headers_recv_data_single_frame() {
])
.build();
let mut h2 = Client::handshake(mock)
.wait().unwrap();
let mut h2 = Client::handshake(mock).wait().unwrap();
// Send the request
let request = Request::builder()
.uri("https://http2.akamai.com/")
.body(()).unwrap();
.body(())
.unwrap();
info!("sending request");
let mut stream = h2.request(request, true).unwrap();
@@ -154,10 +154,10 @@ fn closed_streams_are_released() {
let _ = ::env_logger::init();
let (io, srv) = mock::new();
let h2 = Client::handshake(io).unwrap()
let h2 = Client::handshake(io)
.unwrap()
.and_then(|mut h2| {
let request = Request::get("https://example.com/")
.body(()).unwrap();
let request = Request::get("https://example.com/").body(()).unwrap();
// Send request
let stream = h2.request(request, true).unwrap();
@@ -179,26 +179,18 @@ fn closed_streams_are_released() {
assert_eq!(0, h2.num_wired_streams());
Ok(())
})
;
});
let srv = srv.assert_client_handshake().unwrap()
let srv = srv.assert_client_handshake()
.unwrap()
.recv_settings()
.recv_frame(
frames::headers(1)
.request("GET", "https://example.com/")
.eos()
)
.send_frame(
frames::headers(1)
.response(204)
.eos()
)
.close()
;
.recv_frame(frames::headers(1)
.request("GET", "https://example.com/")
.eos())
.send_frame(frames::headers(1).response(204).eos())
.close();
let _ = h2.join(srv)
.wait().unwrap();
let _ = h2.join(srv).wait().unwrap();
}
/*

View File

@@ -23,13 +23,13 @@ fn recv_trailers_only() {
])
.build();
let mut h2 = Client::handshake(mock)
.wait().unwrap();
let mut h2 = Client::handshake(mock).wait().unwrap();
// Send the request
let request = Request::builder()
.uri("https://http2.akamai.com/")
.body(()).unwrap();
.body(())
.unwrap();
info!("sending request");
let mut stream = h2.request(request, true).unwrap();
@@ -71,13 +71,13 @@ fn send_trailers_immediately() {
])
.build();
let mut h2 = Client::handshake(mock)
.wait().unwrap();
let mut h2 = Client::handshake(mock).wait().unwrap();
// Send the request
let request = Request::builder()
.uri("https://http2.akamai.com/")
.body(()).unwrap();
.body(())
.unwrap();
info!("sending request");
let mut stream = h2.request(request, false).unwrap();