Repository navigation
test(grpc-js): build the tonic server without a protoc download #48420
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
Open
robobun
wants to merge
5
commits into
main
Choose a base branch
from
robobun/e9a447f6/test-tonic-no-protoc-download
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1bdcbd8
test(grpc-js): build the tonic server without a protoc download
robobun 815a4c1
test(grpc-js): drop unzipper, keep the hosts of the tonic test, check…
robobun c1177a2
test(grpc-js): compare field types and method signatures of helloworl…
robobun c71a904
test(grpc-js): tie helloworld.rs to helloworld.proto by a recorded hash
robobun 5de94e7
Merge remote-tracking branch 'origin/main' into robobun/e9a447f6/test…
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
202 changes: 202 additions & 0 deletions
202
test/js/third_party/grpc-js/fixtures/tonic-server/src/helloworld.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,202 @@ | ||
| // The output of tonic-build 0.13.1 for proto/helloworld.proto, checked in so | ||
| // that the test does not need protoc. test-tonic.test.ts fails when the .proto | ||
| // no longer has the hash below. To make this file again, put tonic-build back | ||
| // as a build dependency, run this from a build.rs with PROTOC set, copy | ||
| // $OUT_DIR/helloworld.rs over the generated lines, and set the hash to the | ||
| // one that the test expects: | ||
| // | ||
| // tonic_build::configure() | ||
| // .build_client(false) | ||
| // .compile_protos(&["proto/helloworld.proto"], &["proto"]) | ||
| // .unwrap(); | ||
| // | ||
| // sha256 of proto/helloworld.proto: 76ebff6ce48286b680babed9058e3571b4005f61c95ee48f4b0e58a8db0540c0 | ||
|
|
||
| // This file is @generated by prost-build. | ||
| #[derive(Clone, PartialEq, ::prost::Message)] | ||
| pub struct HelloRequest { | ||
| #[prost(string, tag = "1")] | ||
| pub name: ::prost::alloc::string::String, | ||
| } | ||
| #[derive(Clone, PartialEq, ::prost::Message)] | ||
| pub struct HelloReply { | ||
| #[prost(string, tag = "1")] | ||
| pub message: ::prost::alloc::string::String, | ||
| } | ||
| /// Generated server implementations. | ||
| pub mod greeter_server { | ||
| #![allow( | ||
| unused_variables, | ||
| dead_code, | ||
| missing_docs, | ||
| clippy::wildcard_imports, | ||
| clippy::let_unit_value, | ||
| )] | ||
| use tonic::codegen::*; | ||
| /// Generated trait containing gRPC methods that should be implemented for use with GreeterServer. | ||
| #[async_trait] | ||
| pub trait Greeter: std::marker::Send + std::marker::Sync + 'static { | ||
| async fn say_hello( | ||
| &self, | ||
| request: tonic::Request<super::HelloRequest>, | ||
| ) -> std::result::Result<tonic::Response<super::HelloReply>, tonic::Status>; | ||
| } | ||
| #[derive(Debug)] | ||
| pub struct GreeterServer<T> { | ||
| inner: Arc<T>, | ||
| accept_compression_encodings: EnabledCompressionEncodings, | ||
| send_compression_encodings: EnabledCompressionEncodings, | ||
| max_decoding_message_size: Option<usize>, | ||
| max_encoding_message_size: Option<usize>, | ||
| } | ||
| impl<T> GreeterServer<T> { | ||
| pub fn new(inner: T) -> Self { | ||
| Self::from_arc(Arc::new(inner)) | ||
| } | ||
| pub fn from_arc(inner: Arc<T>) -> Self { | ||
| Self { | ||
| inner, | ||
| accept_compression_encodings: Default::default(), | ||
| send_compression_encodings: Default::default(), | ||
| max_decoding_message_size: None, | ||
| max_encoding_message_size: None, | ||
| } | ||
| } | ||
| pub fn with_interceptor<F>( | ||
| inner: T, | ||
| interceptor: F, | ||
| ) -> InterceptedService<Self, F> | ||
| where | ||
| F: tonic::service::Interceptor, | ||
| { | ||
| InterceptedService::new(Self::new(inner), interceptor) | ||
| } | ||
| /// Enable decompressing requests with the given encoding. | ||
| #[must_use] | ||
| pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self { | ||
| self.accept_compression_encodings.enable(encoding); | ||
| self | ||
| } | ||
| /// Compress responses with the given encoding, if the client supports it. | ||
| #[must_use] | ||
| pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self { | ||
| self.send_compression_encodings.enable(encoding); | ||
| self | ||
| } | ||
| /// Limits the maximum size of a decoded message. | ||
| /// | ||
| /// Default: `4MB` | ||
| #[must_use] | ||
| pub fn max_decoding_message_size(mut self, limit: usize) -> Self { | ||
| self.max_decoding_message_size = Some(limit); | ||
| self | ||
| } | ||
| /// Limits the maximum size of an encoded message. | ||
| /// | ||
| /// Default: `usize::MAX` | ||
| #[must_use] | ||
| pub fn max_encoding_message_size(mut self, limit: usize) -> Self { | ||
| self.max_encoding_message_size = Some(limit); | ||
| self | ||
| } | ||
| } | ||
| impl<T, B> tonic::codegen::Service<http::Request<B>> for GreeterServer<T> | ||
| where | ||
| T: Greeter, | ||
| B: Body + std::marker::Send + 'static, | ||
| B::Error: Into<StdError> + std::marker::Send + 'static, | ||
| { | ||
| type Response = http::Response<tonic::body::Body>; | ||
| type Error = std::convert::Infallible; | ||
| type Future = BoxFuture<Self::Response, Self::Error>; | ||
| fn poll_ready( | ||
| &mut self, | ||
| _cx: &mut Context<'_>, | ||
| ) -> Poll<std::result::Result<(), Self::Error>> { | ||
| Poll::Ready(Ok(())) | ||
| } | ||
| fn call(&mut self, req: http::Request<B>) -> Self::Future { | ||
| match req.uri().path() { | ||
| "/helloworld.Greeter/SayHello" => { | ||
| #[allow(non_camel_case_types)] | ||
| struct SayHelloSvc<T: Greeter>(pub Arc<T>); | ||
| impl<T: Greeter> tonic::server::UnaryService<super::HelloRequest> | ||
| for SayHelloSvc<T> { | ||
| type Response = super::HelloReply; | ||
| type Future = BoxFuture< | ||
| tonic::Response<Self::Response>, | ||
| tonic::Status, | ||
| >; | ||
| fn call( | ||
| &mut self, | ||
| request: tonic::Request<super::HelloRequest>, | ||
| ) -> Self::Future { | ||
| let inner = Arc::clone(&self.0); | ||
| let fut = async move { | ||
| <T as Greeter>::say_hello(&inner, request).await | ||
| }; | ||
| Box::pin(fut) | ||
| } | ||
| } | ||
| let accept_compression_encodings = self.accept_compression_encodings; | ||
| let send_compression_encodings = self.send_compression_encodings; | ||
| let max_decoding_message_size = self.max_decoding_message_size; | ||
| let max_encoding_message_size = self.max_encoding_message_size; | ||
| let inner = self.inner.clone(); | ||
| let fut = async move { | ||
| let method = SayHelloSvc(inner); | ||
| let codec = tonic::codec::ProstCodec::default(); | ||
| let mut grpc = tonic::server::Grpc::new(codec) | ||
| .apply_compression_config( | ||
| accept_compression_encodings, | ||
| send_compression_encodings, | ||
| ) | ||
| .apply_max_message_size_config( | ||
| max_decoding_message_size, | ||
| max_encoding_message_size, | ||
| ); | ||
| let res = grpc.unary(method, req).await; | ||
| Ok(res) | ||
| }; | ||
| Box::pin(fut) | ||
| } | ||
| _ => { | ||
| Box::pin(async move { | ||
| let mut response = http::Response::new( | ||
| tonic::body::Body::default(), | ||
| ); | ||
| let headers = response.headers_mut(); | ||
| headers | ||
| .insert( | ||
| tonic::Status::GRPC_STATUS, | ||
| (tonic::Code::Unimplemented as i32).into(), | ||
| ); | ||
| headers | ||
| .insert( | ||
| http::header::CONTENT_TYPE, | ||
| tonic::metadata::GRPC_CONTENT_TYPE, | ||
| ); | ||
| Ok(response) | ||
| }) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| impl<T> Clone for GreeterServer<T> { | ||
| fn clone(&self) -> Self { | ||
| let inner = self.inner.clone(); | ||
| Self { | ||
| inner, | ||
| accept_compression_encodings: self.accept_compression_encodings, | ||
| send_compression_encodings: self.send_compression_encodings, | ||
| max_decoding_message_size: self.max_decoding_message_size, | ||
| max_encoding_message_size: self.max_encoding_message_size, | ||
| } | ||
| } | ||
| } | ||
| /// Generated gRPC service name | ||
| pub const SERVICE_NAME: &str = "helloworld.Greeter"; | ||
| impl<T> tonic::server::NamedService for GreeterServer<T> { | ||
| const NAME: &'static str = SERVICE_NAME; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.