-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support timeouts with "grpc-timeout" header #516
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use futures_util::FutureExt; | ||
use integration_tests::pb::{test_client, test_server, Input, Output}; | ||
use std::time::Duration; | ||
use tokio::sync::oneshot; | ||
use tonic::{ | ||
transport::Server, | ||
Request, Response, Status, | ||
}; | ||
|
||
#[tokio::test] | ||
async fn cancelation_on_timeout() { | ||
struct Svc; | ||
|
||
#[tonic::async_trait] | ||
impl test_server::Test for Svc { | ||
async fn unary_call(&self, _req: Request<Input>) -> Result<Response<Output>, Status> { | ||
// Wait for a time longer than the timeout | ||
tokio::time::delay_for(Duration::from_millis(1_000)).await; | ||
Ok(Response::new(Output {})) | ||
} | ||
} | ||
|
||
let svc = test_server::TestServer::new(Svc); | ||
|
||
let (tx, rx) = oneshot::channel::<()>(); | ||
|
||
let jh = tokio::spawn(async move { | ||
Server::builder() | ||
.add_service(svc) | ||
.serve_with_shutdown("127.0.0.1:1322".parse().unwrap(), rx.map(drop)) | ||
.await | ||
.unwrap(); | ||
}); | ||
|
||
tokio::time::delay_for(Duration::from_millis(100)).await; | ||
|
||
let mut client = test_client::TestClient::connect("http://127.0.0.1:1322") | ||
.await | ||
.unwrap(); | ||
|
||
let mut req = Request::new(Input {}); | ||
req.metadata_mut().insert("grpc-timeout", "500m".parse().unwrap()); | ||
|
||
let err = client.unary_call(req).await.unwrap_err(); | ||
assert!(err.message().contains("Timeout expired")); | ||
// TODO: Need to return the correct type of code | ||
// assert_eq!(err.code(), Code::Cancelled); | ||
|
||
tx.send(()).unwrap(); | ||
|
||
jh.await.unwrap(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,11 +198,10 @@ pub struct OccupiedEntry<'a, VE: ValueEncoding> { | |
|
||
impl MetadataMap { | ||
// Headers reserved by the gRPC protocol. | ||
pub(crate) const GRPC_RESERVED_HEADERS: [&'static str; 8] = [ | ||
pub(crate) const GRPC_RESERVED_HEADERS: [&'static str; 7] = [ | ||
"te", | ||
"user-agent", | ||
"content-type", | ||
"grpc-timeout", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removing this definitely isn't right, but otherwise the header was getting stripped when I tried to set it in the integration test. Would love some guidance on how to set this header from a test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think its fine. As the user is now allowed to set it I guess its not reserved anymore. |
||
"grpc-message", | ||
"grpc-encoding", | ||
"grpc-message-type", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like something that should be fixed before merging 🤔