diff --git a/tonic-examples/src/helloworld/client.rs b/tonic-examples/src/helloworld/client.rs index 661f8a5..8165819 100644 --- a/tonic-examples/src/helloworld/client.rs +++ b/tonic-examples/src/helloworld/client.rs @@ -1,4 +1,4 @@ -use tonic::transport::Client; +use tonic::transport::Channel; pub mod hello_world { include!(concat!(env!("OUT_DIR"), "/helloworld.rs")); @@ -9,7 +9,7 @@ pub mod hello_world { async fn main() -> Result<(), Box> { let origin = http::Uri::from_static("http://[::1]:50051"); - let svc = Client::builder().build(origin)?; + let svc = Channel::builder().build(origin)?; let mut client = hello_world::GreeterClient::new(svc); diff --git a/tonic-examples/src/routeguide/client.rs b/tonic-examples/src/routeguide/client.rs index 8f846f7..725cbee 100644 --- a/tonic-examples/src/routeguide/client.rs +++ b/tonic-examples/src/routeguide/client.rs @@ -2,7 +2,7 @@ use futures::TryStreamExt; use route_guide::{Point, RouteNote}; use std::time::{Duration, Instant}; use tokio::timer::Interval; -use tonic::{transport::Client, Request}; +use tonic::{transport::Channel, Request}; mod route_guide { include!(concat!(env!("OUT_DIR"), "/routeguide.rs")); @@ -13,7 +13,7 @@ mod route_guide { async fn main() -> Result<(), Box> { let origin = http::Uri::from_static("http://[::1]:10000"); - let svc = Client::builder().build(origin)?; + let svc = Channel::builder().build(origin)?; let mut client = route_guide::RouteGuideClient::new(svc); let start = Instant::now(); diff --git a/tonic-interop/bin/darwin/client b/tonic-interop/bin/darwin/client new file mode 100755 index 0000000..9933b90 Binary files /dev/null and b/tonic-interop/bin/darwin/client differ diff --git a/tonic-interop/bin/darwin/server b/tonic-interop/bin/darwin/server new file mode 100755 index 0000000..e276f09 Binary files /dev/null and b/tonic-interop/bin/darwin/server differ diff --git a/tonic-interop/src/bin/client.rs b/tonic-interop/src/bin/client.rs index 76f4b31..de862f6 100644 --- a/tonic-interop/src/bin/client.rs +++ b/tonic-interop/src/bin/client.rs @@ -1,5 +1,6 @@ use structopt::{clap::arg_enum, StructOpt}; use tonic_interop::client; +use tonic::transport::Channel; #[derive(StructOpt)] struct Opts { @@ -25,8 +26,15 @@ async fn main() -> Result<(), Box> { let addr = "localhost:10000"; let origin = http::Uri::from_shared(format!("http://{}", addr).into()).unwrap(); - let mut client = client::create(origin.clone()).await?; - let mut unimplemented_client = client::create_unimplemented(origin).await?; + let channel = Channel::builder() + // .tls(ca) + // .tls_override_domain("foo.test.google.fr") + .build(origin)?; + + let mut client = client::TestClient::new(channel.clone()); + let mut unimplemented_client = client::UnimplementedClient::new(channel); + + let mut failures = Vec::new(); for test_case in test_cases { println!("{:?}:", test_case); @@ -63,9 +71,18 @@ async fn main() -> Result<(), Box> { for result in test_results { println!(" {}", result); + + if result.is_failed() { + failures.push(result); + } } } + if !failures.is_empty() { + println!("{} tests failed", failures.len()); + std::process::exit(1); + } + Ok(()) } diff --git a/tonic-interop/src/client.rs b/tonic-interop/src/client.rs index 77d4d50..d0093ee 100644 --- a/tonic-interop/src/client.rs +++ b/tonic-interop/src/client.rs @@ -1,11 +1,11 @@ use crate::{pb::*, test_assert, TestAssertion}; use futures_util::{future, stream, SinkExt, StreamExt}; use tokio::sync::mpsc; -use tonic::transport::Client; +use tonic::transport::Channel; use tonic::{metadata::MetadataValue, Code, Request, Response, Status}; -pub type TestClient = TestServiceClient; -pub type UnimplementedClient = UnimplementedServiceClient; +pub type TestClient = TestServiceClient; +pub type UnimplementedClient = UnimplementedServiceClient; tonic::client!(service = "grpc.testing.TestService", proto = "crate::pb"); tonic::client!( @@ -22,11 +22,11 @@ const SPECIAL_TEST_STATUS_MESSAGE: &'static str = "\t\ntest with whitespace\r\nand Unicode BMP ☺ and non-BMP 😈\t\n"; pub async fn create(origin: http::Uri) -> Result> { - let ca = tokio::fs::read("tonic-interop/data/ca.pem").await?; + // let ca = tokio::fs::read("tonic-interop/data/ca.pem").await?; - let svc = Client::builder() - .tls(ca) - .tls_override_domain("foo.test.google.fr") + let svc = Channel::builder() + // .tls(ca) + // .tls_override_domain("foo.test.google.fr") .build(origin)?; Ok(TestServiceClient::new(svc)) @@ -35,11 +35,11 @@ pub async fn create(origin: http::Uri) -> Result Result> { - let ca = tokio::fs::read("tonic-interop/data/ca.pem").await?; + // let ca = tokio::fs::read("tonic-interop/data/ca.pem").await?; - let svc = Client::builder() - .tls(ca) - .tls_override_domain("foo.test.google.fr") + let svc = Channel::builder() + // .tls(ca) + // .tls_override_domain("foo.test.google.fr") .build(origin)?; Ok(UnimplementedServiceClient::new(svc)) diff --git a/tonic-interop/src/lib.rs b/tonic-interop/src/lib.rs index 03b64ed..0a4008f 100644 --- a/tonic-interop/src/lib.rs +++ b/tonic-interop/src/lib.rs @@ -47,6 +47,15 @@ pub enum TestAssertion { }, } +impl TestAssertion { + pub fn is_failed(&self) -> bool { + match self { + TestAssertion::Failed { .. } => true, + _ => false, + } + } +} + impl fmt::Display for TestAssertion { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { use console::{style, Emoji}; diff --git a/tonic-interop/test.sh b/tonic-interop/test.sh index bacf8d2..52841a0 100755 --- a/tonic-interop/test.sh +++ b/tonic-interop/test.sh @@ -1,3 +1,19 @@ +#!/usr/bin/env bash + +set -eu +set -o pipefail + +SERVER="tonic-interop/bin/darwin/server" + +# run the test server +./"${SERVER}" & +SERVER_PID=$! +echo ":; started grpc-go test server." + +# trap exits to make sure we kill the server process when the script exits, +# regardless of why (errors, SIGTERM, etc). +trap 'echo ":; killing test server"; kill ${SERVER_PID};' EXIT + cargo run -p tonic-interop --bin client -- \ --test_case=empty_unary,large_unary,client_streaming,server_streaming,ping_pong,\ empty_stream,status_code_and_message,special_status_message,unimplemented_method,\ diff --git a/tonic/Cargo.toml b/tonic/Cargo.toml index 0ef1f4c..ce22a95 100644 --- a/tonic/Cargo.toml +++ b/tonic/Cargo.toml @@ -27,12 +27,12 @@ tower-make = "=0.1.0-alpha.2" tower-reconnect = { path = "../../tower/tower-reconnect", optional = true } tower-buffer = { path = "../../tower/tower-buffer", optional = true } -# openssl +# openssl tokio-openssl = { version = "=0.4.0-alpha.4", optional = true } openssl = { version = "0.10", optional = true } # rustls -tokio-rustls = { path = "../../tokio-rustls", optional = true } +tokio-rustls = { version = "0.12.0-alpha.2", optional = true } [features] default = ["transport"] diff --git a/tonic/src/transport/client.rs b/tonic/src/transport/channel.rs similarity index 90% rename from tonic/src/transport/client.rs rename to tonic/src/transport/channel.rs index 97cbf9b..f9cff8b 100644 --- a/tonic/src/transport/client.rs +++ b/tonic/src/transport/channel.rs @@ -26,17 +26,17 @@ type Inner = Box< >; #[derive(Clone)] -pub struct Client { +pub struct Channel { svc: Buffer>, } -impl Client { +impl Channel { pub fn builder() -> Builder { Builder::new() } } -impl GrpcService for Client { +impl GrpcService for Channel { type ResponseBody = hyper::Body; type Error = super::Error; @@ -89,7 +89,7 @@ impl Builder { self } - pub fn build(&self, uri: T) -> Result + pub fn build(&self, uri: T) -> Result where Uri: http::HttpTryFrom, { @@ -107,7 +107,7 @@ impl Builder { .unwrap_or_else(|| uri.to_string()); #[cfg(not(any(feature = "openssl-1", feature = "rustls")))] - panic!("tls configured when no tls implementation feature was selected!"); + unreachable!("tls configured when no tls implementation feature was selected!"); #[cfg(feature = "openssl-1")] let connector = super::openssl::TlsConnector::new(ca.clone(), domain)?; @@ -131,9 +131,7 @@ impl Builder { let svc = BoxService::new(svc); Buffer::new(Box::new(svc) as Inner, 100) }; - // let connector = super::rustls::TlsConnector::load(ca).await?; - // let connector = super::openssl::TlsConnector::load(ca).await?; - Ok(Client { svc }) + Ok(Channel { svc }) } } diff --git a/tonic/src/transport/mod.rs b/tonic/src/transport/mod.rs index b9e6b6d..b40c6f3 100644 --- a/tonic/src/transport/mod.rs +++ b/tonic/src/transport/mod.rs @@ -1,10 +1,10 @@ -mod client; +mod channel; #[cfg(feature = "openssl-1")] mod openssl; #[cfg(feature = "rustls")] mod rustls; -pub use self::client::Client; +pub use self::channel::Channel; use std::{error, fmt}; diff --git a/tonic/src/transport/openssl.rs b/tonic/src/transport/openssl.rs index 5661f81..8ecd321 100644 --- a/tonic/src/transport/openssl.rs +++ b/tonic/src/transport/openssl.rs @@ -23,7 +23,7 @@ impl TlsConnector { pub fn new(ca: Vec, domain: String) -> Result { let mut config = SslConnector::builder(SslMethod::tls()).unwrap(); - config.set_alpn_protos(b"\x02h2").unwrap(); + config.set_alpn_protos(b"\x06h2").unwrap(); let ca = X509::from_pem(&ca[..]).unwrap();