1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-27 17:52:56 +01:00

add very simple http/2 test

This commit is contained in:
Nikolay Kim 2018-01-09 12:49:46 -08:00
parent 584d0c9e99
commit 6c7dda495b
2 changed files with 40 additions and 0 deletions

View File

@ -146,6 +146,11 @@ impl TestServer {
tcp.local_addr().unwrap() tcp.local_addr().unwrap()
} }
/// Construct test server url
pub fn addr(&self) -> net::SocketAddr {
self.addr
}
/// Construct test server url /// Construct test server url
pub fn url(&self, uri: &str) -> String { pub fn url(&self, uri: &str) -> String {
if uri.starts_with('/') { if uri.starts_with('/') {

View File

@ -3,11 +3,17 @@ extern crate actix_web;
extern crate tokio_core; extern crate tokio_core;
extern crate reqwest; extern crate reqwest;
extern crate futures; extern crate futures;
extern crate h2;
extern crate http;
use std::{net, thread, time}; use std::{net, thread, time};
use std::sync::{Arc, mpsc}; use std::sync::{Arc, mpsc};
use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::atomic::{AtomicUsize, Ordering};
use futures::Future; use futures::Future;
use h2::client;
use http::Request;
use tokio_core::net::TcpStream;
use tokio_core::reactor::Core;
use actix_web::*; use actix_web::*;
use actix::System; use actix::System;
@ -48,6 +54,35 @@ fn test_simple() {
assert!(reqwest::get(&srv.url("/")).unwrap().status().is_success()); 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] #[test]
fn test_application() { fn test_application() {
let srv = test::TestServer::with_factory( let srv = test::TestServer::with_factory(