update flow control tests to use frame builders
This commit is contained in:
@@ -57,84 +57,39 @@ fn release_capacity_sends_window_update() {
|
|||||||
|
|
||||||
let (io, srv) = mock::new();
|
let (io, srv) = mock::new();
|
||||||
|
|
||||||
fn make_request() -> Request<()> {
|
|
||||||
Request::builder()
|
|
||||||
.method(Method::GET)
|
|
||||||
.uri("https://http2.akamai.com/")
|
|
||||||
.body(()).unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* // End Goal:
|
|
||||||
let mock = srv.assert_client_handshake().unwrap()
|
let mock = srv.assert_client_handshake().unwrap()
|
||||||
// .assert_settings ?
|
.recv_settings()
|
||||||
.and_then(|(_settings, srv)| {
|
.recv_frame(
|
||||||
srv.into_future().unwrap()
|
|
||||||
})
|
|
||||||
.recv(
|
|
||||||
frames::headers(1)
|
frames::headers(1)
|
||||||
.request(head.method, head.uri)
|
.request("GET", "https://http2.akamai.com/")
|
||||||
.eos()
|
.eos()
|
||||||
)
|
)
|
||||||
.send(&[
|
.send_frame(
|
||||||
frames::headers(1)
|
frames::headers(1)
|
||||||
.response(200),
|
.response(200)
|
||||||
frames::data(1, &payload[0..16_384]),
|
)
|
||||||
frames::data(1, &payload[0..16_384]),
|
.send_frame(frames::data(1, &payload[0..16_384]))
|
||||||
frames::data(1, &payload[0..16_384]),
|
.send_frame(frames::data(1, &payload[16_384..16_384 * 2]))
|
||||||
])
|
.send_frame(frames::data(1, &payload[16_384 * 2..16_384 * 3]))
|
||||||
.recv(
|
.recv_frame(
|
||||||
frames::window_update(0, 32_768)
|
frames::window_update(0, 32_768)
|
||||||
)
|
)
|
||||||
.recv(
|
.recv_frame(
|
||||||
frames::window_update(1, 32_768)
|
frames::window_update(1, 32_768)
|
||||||
)
|
)
|
||||||
*/
|
.send_frame(
|
||||||
|
frames::data(1, &payload[16_384 * 3..])
|
||||||
let mock = srv.assert_client_handshake().unwrap()
|
|
||||||
.and_then(|(_settings, srv)| {
|
|
||||||
srv.into_future().unwrap()
|
|
||||||
})
|
|
||||||
.and_then(|(frame, mut srv)| {
|
|
||||||
let head = make_request().into_parts().0;
|
|
||||||
let expected = frames::headers(1)
|
|
||||||
.request(head.method, head.uri)
|
|
||||||
.fields(head.headers)
|
|
||||||
.eos()
|
.eos()
|
||||||
.into();
|
)
|
||||||
assert_eq!(frame.unwrap(), expected);
|
// gotta end the connection
|
||||||
|
.map(drop);
|
||||||
let res = frames::headers(1)
|
|
||||||
.response(200)
|
|
||||||
.into();
|
|
||||||
srv.send(res).unwrap();
|
|
||||||
let data = frames::data(1, &payload[0..16_384]);
|
|
||||||
srv.send(data.into()).unwrap();
|
|
||||||
let data = frames::data(1, &payload[16_384..16_384 * 2]);
|
|
||||||
srv.send(data.into()).unwrap();
|
|
||||||
let data = frames::data(1, &payload[16_384 * 2..16_384 * 3]);
|
|
||||||
srv.send(data.into()).unwrap();
|
|
||||||
srv.into_future().unwrap()
|
|
||||||
})
|
|
||||||
.and_then(|(frame, srv)| {
|
|
||||||
let expected = frames::window_update(0, 32_768);
|
|
||||||
assert_eq!(frame.unwrap(), expected.into());
|
|
||||||
srv.into_future().unwrap()
|
|
||||||
})
|
|
||||||
.and_then(|(frame, mut srv)| {
|
|
||||||
let expected = frames::window_update(1, 32_768);
|
|
||||||
assert_eq!(frame.unwrap(), expected.into());
|
|
||||||
|
|
||||||
let data = frames::data(1, &payload[16_384 * 3..])
|
|
||||||
.eos();
|
|
||||||
srv.send(data.into()).unwrap();
|
|
||||||
Ok(())
|
|
||||||
});
|
|
||||||
|
|
||||||
let h2 = Client::handshake(io).unwrap()
|
let h2 = Client::handshake(io).unwrap()
|
||||||
.and_then(|mut h2| {
|
.and_then(|mut h2| {
|
||||||
eprintln!("h2.request");
|
let request = Request::builder()
|
||||||
let request = make_request();
|
.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()
|
.unwrap()
|
||||||
@@ -175,63 +130,52 @@ fn release_capacity_of_small_amount_does_not_send_window_update() {
|
|||||||
|
|
||||||
let payload = [0; 16];
|
let payload = [0; 16];
|
||||||
|
|
||||||
let mock = mock_io::Builder::new()
|
let (io, srv) = mock::new();
|
||||||
.handshake()
|
|
||||||
.write(&[
|
|
||||||
// GET /
|
|
||||||
0, 0, 16, 1, 5, 0, 0, 0, 1, 130, 135, 65, 139, 157, 41,
|
|
||||||
172, 75, 143, 168, 233, 25, 151, 33, 233, 132,
|
|
||||||
])
|
|
||||||
.write(frames::SETTINGS_ACK)
|
|
||||||
// Read response
|
|
||||||
.read(&[0, 0, 1, 1, 4, 0, 0, 0, 1, 0x88])
|
|
||||||
.read(&[
|
|
||||||
// DATA
|
|
||||||
0, 0, 16, 0, 1, 0, 0, 0, 1,
|
|
||||||
])
|
|
||||||
.read(&payload[..])
|
|
||||||
// write() or WINDOW_UPDATE purposefully excluded
|
|
||||||
|
|
||||||
// we send a 2nd stream in order to test the window update is
|
let mock = srv.assert_client_handshake().unwrap()
|
||||||
// is actually written to the socket
|
.recv_settings()
|
||||||
.write(&[
|
.recv_frame(
|
||||||
// GET /
|
frames::headers(1)
|
||||||
0, 0, 4, 1, 5, 0, 0, 0, 3, 130, 135, 190, 132,
|
.request("GET", "https://http2.akamai.com/")
|
||||||
])
|
.eos()
|
||||||
.read(&[0, 0, 1, 1, 5, 0, 0, 0, 3, 0x88])
|
)
|
||||||
.build();
|
.send_frame(
|
||||||
|
frames::headers(1)
|
||||||
|
.response(200)
|
||||||
|
)
|
||||||
|
.send_frame(frames::data(1, &payload[..]).eos())
|
||||||
|
// gotta end the connection
|
||||||
|
.map(drop);
|
||||||
|
|
||||||
let mut h2 = Client::handshake(mock)
|
let h2 = Client::handshake(io).unwrap()
|
||||||
.wait().unwrap();
|
.and_then(|mut h2| {
|
||||||
|
let request = Request::builder()
|
||||||
|
.method(Method::GET)
|
||||||
|
.uri("https://http2.akamai.com/")
|
||||||
|
.body(()).unwrap();
|
||||||
|
|
||||||
let request = Request::builder()
|
let req = h2.request(request, true).unwrap()
|
||||||
.method(Method::GET)
|
.unwrap()
|
||||||
.uri("https://http2.akamai.com/")
|
// Get the response
|
||||||
.body(()).unwrap();
|
.and_then(|resp| {
|
||||||
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
let mut stream = h2.request(request, true).unwrap();
|
let body = resp.into_parts().1;
|
||||||
|
body.into_future().unwrap()
|
||||||
// Get the response
|
})
|
||||||
let resp = h2.run(poll_fn(|| stream.poll_response())).unwrap();
|
// read the small body and then release it
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
.and_then(|(buf, mut body)| {
|
||||||
|
let buf = buf.unwrap();
|
||||||
let mut body = resp.into_parts().1;
|
assert_eq!(buf.len(), 16);
|
||||||
let buf = h2.run(poll_fn(|| body.poll())).unwrap().unwrap();
|
body.release_capacity(buf.len()).unwrap();
|
||||||
|
body.into_future().unwrap()
|
||||||
// release some capacity to send a window_update
|
})
|
||||||
body.release_capacity(buf.len()).unwrap();
|
.and_then(|(buf, _)| {
|
||||||
|
assert!(buf.is_none());
|
||||||
// send a 2nd stream to force flushing of window updates
|
Ok(())
|
||||||
let request = Request::builder()
|
});
|
||||||
.method(Method::GET)
|
h2.unwrap().join(req)
|
||||||
.uri("https://http2.akamai.com/")
|
});
|
||||||
.body(()).unwrap();
|
h2.join(mock).wait().unwrap();
|
||||||
let mut stream = h2.request(request, true).unwrap();
|
|
||||||
let resp = h2.run(poll_fn(|| stream.poll_response())).unwrap();
|
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
|
||||||
|
|
||||||
|
|
||||||
h2.wait().unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user