Skip to content

Commit 4321caf

Browse files
goffriecarllerche
authored andcommitted
Augment the fuzzer to open multiple concurrent streams. (#328)
This is how I found #319 and #320.
1 parent fc5efe7 commit 4321caf

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

tests/h2-fuzz/src/main.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#[macro_use]
21
extern crate futures;
32
extern crate tokio_io;
43
#[macro_use]
@@ -14,6 +13,7 @@ use std::cell::Cell;
1413
use std::io::{self, Read, Write};
1514
use std::sync::Arc;
1615
use tokio_io::{AsyncRead, AsyncWrite};
16+
use futures::stream::futures_unordered::FuturesUnordered;
1717

1818
struct MockIo<'a> {
1919
input: &'a [u8],
@@ -114,13 +114,15 @@ fn run(script: &[u8]) -> Result<(), h2::Error> {
114114
let notify_handle: executor::NotifyHandle = notify.clone().into();
115115
let io = MockIo { input: script };
116116
let (mut h2, mut connection) = h2::client::handshake(io).wait()?;
117-
let mut in_progress = None;
117+
let mut futs = FuturesUnordered::new();
118118
let future = future::poll_fn(|| {
119119
if let Async::Ready(()) = connection.poll()? {
120120
return Ok(Async::Ready(()));
121121
}
122-
if in_progress.is_none() {
123-
try_ready!(h2.poll_ready());
122+
while futs.len() < 128 {
123+
if h2.poll_ready()?.is_not_ready() {
124+
break;
125+
}
124126
let request = Request::builder()
125127
.method(Method::POST)
126128
.uri("https://example.com/")
@@ -129,14 +131,15 @@ fn run(script: &[u8]) -> Result<(), h2::Error> {
129131
let (resp, mut send) = h2.send_request(request, false)?;
130132
send.send_data(vec![0u8; 32769].into(), true).unwrap();
131133
drop(send);
132-
in_progress = Some(resp);
134+
futs.push(resp);
133135
}
134-
match in_progress.as_mut().unwrap().poll() {
135-
r @ Ok(Async::Ready(_)) | r @ Err(_) => {
136-
eprintln!("{:?}", r);
137-
in_progress = None;
136+
loop {
137+
match futs.poll() {
138+
Ok(Async::NotReady) | Ok(Async::Ready(None)) => break,
139+
r @ Ok(Async::Ready(_)) | r @ Err(_) => {
140+
eprintln!("{:?}", r);
141+
}
138142
}
139-
Ok(Async::NotReady) => (),
140143
}
141144
Ok::<_, h2::Error>(Async::NotReady)
142145
});

0 commit comments

Comments
 (0)