Merge pull request #6866 from paritytech/td-fix-dapps-tests

Fix dapps tests in master
This commit is contained in:
Marek Kotewicz 2017-10-24 11:31:14 +07:00 committed by GitHub
commit 3e5d9b92c1

View File

@ -16,7 +16,7 @@
use std::thread; use std::thread;
use std::time::Duration; use std::time::Duration;
use std::io::{Read, Write}; use std::io::{self, Read, Write};
use std::str::{self, Lines}; use std::str::{self, Lines};
use std::net::{TcpStream, SocketAddr}; use std::net::{TcpStream, SocketAddr};
@ -83,9 +83,18 @@ pub fn request(address: &SocketAddr, request: &str) -> Response {
req.set_read_timeout(Some(Duration::from_secs(2))).unwrap(); req.set_read_timeout(Some(Duration::from_secs(2))).unwrap();
req.write_all(request.as_bytes()).unwrap(); req.write_all(request.as_bytes()).unwrap();
let mut response = String::new(); let mut response = Vec::new();
let _ = req.read_to_string(&mut response); loop {
let mut chunk = [0; 32 *1024];
match req.read(&mut chunk) {
Err(ref err) if err.kind() == io::ErrorKind::WouldBlock => break,
Err(err) => panic!("Unable to read response: {:?}", err),
Ok(0) => break,
Ok(read) => response.extend_from_slice(&chunk[..read]),
}
}
let response = String::from_utf8_lossy(&response).into_owned();
let mut lines = response.lines(); let mut lines = response.lines();
let status = lines.next().expect("Expected a response").to_owned(); let status = lines.next().expect("Expected a response").to_owned();
let headers_raw = read_block(&mut lines, false); let headers_raw = read_block(&mut lines, false);