Skip to content

Commit

Permalink
fix awc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Dec 20, 2019
1 parent c877840 commit 74fa406
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 48 deletions.
96 changes: 56 additions & 40 deletions awc/tests/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use rand::Rng;

use actix_http::HttpService;
use actix_http_test::test_server;
use actix_service::pipeline_factory;
use actix_web::dev::BodyEncoding;
use actix_service::{map_config, pipeline_factory, IntoServiceFactory};
use actix_web::dev::{AppConfig, BodyEncoding};
use actix_web::http::Cookie;
use actix_web::middleware::Compress;
use actix_web::{
Expand Down Expand Up @@ -170,10 +170,12 @@ async fn test_connection_reuse() {
ok(io)
})
.and_then(
HttpService::new(
HttpService::new(map_config(
App::new()
.service(web::resource("/").route(web::to(|| HttpResponse::Ok()))),
)
.service(web::resource("/").route(web::to(|| HttpResponse::Ok())))
.into_factory(),
|_| AppConfig::default(),
))
.tcp(),
)
});
Expand Down Expand Up @@ -206,10 +208,12 @@ async fn test_connection_force_close() {
ok(io)
})
.and_then(
HttpService::new(
HttpService::new(map_config(
App::new()
.service(web::resource("/").route(web::to(|| HttpResponse::Ok()))),
)
.service(web::resource("/").route(web::to(|| HttpResponse::Ok())))
.into_factory(),
|_| AppConfig::default(),
))
.tcp(),
)
});
Expand All @@ -235,22 +239,25 @@ async fn test_connection_server_close() {
let num = Arc::new(AtomicUsize::new(0));
let num2 = num.clone();

let srv = test_server(move || {
let num2 = num2.clone();
pipeline_factory(move |io| {
num2.fetch_add(1, Ordering::Relaxed);
ok(io)
})
.and_then(
HttpService::new(
App::new().service(
web::resource("/")
.route(web::to(|| HttpResponse::Ok().force_close().finish())),
),
let srv =
test_server(move || {
let num2 = num2.clone();
pipeline_factory(move |io| {
num2.fetch_add(1, Ordering::Relaxed);
ok(io)
})
.and_then(
HttpService::new(map_config(
App::new()
.service(web::resource("/").route(web::to(|| {
HttpResponse::Ok().force_close().finish()
})))
.into_factory(),
|_| AppConfig::default(),
))
.tcp(),
)
.tcp(),
)
});
});

let client = awc::Client::default();

Expand Down Expand Up @@ -280,8 +287,14 @@ async fn test_connection_wait_queue() {
ok(io)
})
.and_then(
HttpService::new(App::new().service(
web::resource("/").route(web::to(|| HttpResponse::Ok().body(STR))),
HttpService::new(map_config(
App::new()
.service(
web::resource("/")
.route(web::to(|| HttpResponse::Ok().body(STR))),
)
.into_factory(),
|_| AppConfig::default(),
))
.tcp(),
)
Expand Down Expand Up @@ -317,22 +330,25 @@ async fn test_connection_wait_queue_force_close() {
let num = Arc::new(AtomicUsize::new(0));
let num2 = num.clone();

let srv = test_server(move || {
let num2 = num2.clone();
pipeline_factory(move |io| {
num2.fetch_add(1, Ordering::Relaxed);
ok(io)
})
.and_then(
HttpService::new(
App::new().service(
web::resource("/")
.route(web::to(|| HttpResponse::Ok().force_close().body(STR))),
),
let srv =
test_server(move || {
let num2 = num2.clone();
pipeline_factory(move |io| {
num2.fetch_add(1, Ordering::Relaxed);
ok(io)
})
.and_then(
HttpService::new(map_config(
App::new()
.service(web::resource("/").route(web::to(|| {
HttpResponse::Ok().force_close().body(STR)
})))
.into_factory(),
|_| AppConfig::default(),
))
.tcp(),
)
.tcp(),
)
});
});

let client = awc::Client::build()
.connector(awc::Connector::new().limit(1).finish())
Expand Down
11 changes: 7 additions & 4 deletions awc/tests/test_rustls_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use std::sync::Arc;

use actix_http::HttpService;
use actix_http_test::test_server;
use actix_service::{pipeline_factory, ServiceFactory};
use actix_service::{map_config, pipeline_factory, ServiceFactory, IntoServiceFactory};
use actix_web::http::Version;
use actix_web::{web, App, HttpResponse};
use actix_web::{web, App, HttpResponse, dev::AppConfig};
use futures::future::ok;
use open_ssl::ssl::{SslAcceptor, SslFiletype, SslMethod, SslVerifyMode};
use rust_tls::ClientConfig;
Expand Down Expand Up @@ -62,8 +62,11 @@ async fn _test_connection_reuse_h2() {
})
.and_then(
HttpService::build()
.h2(App::new()
.service(web::resource("/").route(web::to(|| HttpResponse::Ok()))))
.h2(map_config(App::new()
.service(web::resource("/").route(web::to(|| HttpResponse::Ok())))
.into_factory(),
|_| AppConfig::default(),
))
.openssl(ssl_acceptor())
.map_err(|_| ()),
)
Expand Down
14 changes: 10 additions & 4 deletions awc/tests/test_ssl_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use std::sync::Arc;

use actix_http::HttpService;
use actix_http_test::test_server;
use actix_service::{pipeline_factory, ServiceFactory};
use actix_service::{map_config, pipeline_factory, IntoServiceFactory, ServiceFactory};
use actix_web::http::Version;
use actix_web::{web, App, HttpResponse};
use actix_web::{dev::AppConfig, web, App, HttpResponse};
use futures::future::ok;
use open_ssl::ssl::{SslAcceptor, SslConnector, SslFiletype, SslMethod, SslVerifyMode};

Expand Down Expand Up @@ -44,8 +44,14 @@ async fn test_connection_reuse_h2() {
})
.and_then(
HttpService::build()
.h2(App::new()
.service(web::resource("/").route(web::to(|| HttpResponse::Ok()))))
.h2(map_config(
App::new()
.service(
web::resource("/").route(web::to(|| HttpResponse::Ok())),
)
.into_factory(),
|_| AppConfig::default(),
))
.openssl(ssl_acceptor())
.map_err(|_| ()),
)
Expand Down

0 comments on commit 74fa406

Please sign in to comment.