From 6c7dda495b52690342477ab9a13794a57cd3db27 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 9 Jan 2018 12:49:46 -0800 Subject: [PATCH] add very simple http/2 test --- src/test.rs | 5 +++++ tests/test_server.rs | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/test.rs b/src/test.rs index f92ed8e6..4f2433a9 100644 --- a/src/test.rs +++ b/src/test.rs @@ -146,6 +146,11 @@ impl TestServer { tcp.local_addr().unwrap() } + /// Construct test server url + pub fn addr(&self) -> net::SocketAddr { + self.addr + } + /// Construct test server url pub fn url(&self, uri: &str) -> String { if uri.starts_with('/') { diff --git a/tests/test_server.rs b/tests/test_server.rs index 032c750f..51919cd5 100644 --- a/tests/test_server.rs +++ b/tests/test_server.rs @@ -3,11 +3,17 @@ extern crate actix_web; extern crate tokio_core; extern crate reqwest; extern crate futures; +extern crate h2; +extern crate http; use std::{net, thread, time}; use std::sync::{Arc, mpsc}; use std::sync::atomic::{AtomicUsize, Ordering}; use futures::Future; +use h2::client; +use http::Request; +use tokio_core::net::TcpStream; +use tokio_core::reactor::Core; use actix_web::*; use actix::System; @@ -48,6 +54,35 @@ fn test_simple() { assert!(reqwest::get(&srv.url("/")).unwrap().status().is_success()); } +#[test] +fn test_h2() { + let srv = test::TestServer::new(|app| app.handler(httpcodes::HTTPOk)); + let addr = srv.addr(); + + let mut core = Core::new().unwrap(); + let handle = core.handle(); + let tcp = TcpStream::connect(&addr, &handle); + + let tcp = tcp.then(|res| { + client::handshake(res.unwrap()) + }).then(move |res| { + let (mut client, h2) = res.unwrap(); + + let request = Request::builder() + .uri(format!("https://{}/", addr).as_str()) + .body(()) + .unwrap(); + let (response, _) = client.send_request(request, false).unwrap(); + + // Spawn a task to run the conn... + handle.spawn(h2.map_err(|e| println!("GOT ERR={:?}", e))); + + response + }); + let resp = core.run(tcp).unwrap(); + assert_eq!(resp.status(), StatusCode::OK); +} + #[test] fn test_application() { let srv = test::TestServer::with_factory(