-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Extending Interop tests #2642
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
znaczko
wants to merge
11
commits into
grpc:master
Choose a base branch
from
znaczko:interop_tests
base: master
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
Extending Interop tests #2642
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f7de1a5
Add interop client test for cacheable_unary
znaczko 2325fbf
add interop client test for client_compressed_unary
znaczko 8daa641
add interop client test for server_compressed_unary
znaczko 29f5da6
add interop client test for cancel_after_begin
znaczko 7011322
add interop client test for cancel_after_first_response
znaczko 7f3de65
add interop client test for timeout_on_sleeping_server
znaczko c82bddb
add input parameters: server_host, server_host_override, server_port
znaczko 42ab4c2
add input parameters:
znaczko 8a3f89d
fixed fmt errors
znaczko 9ffcefd
Fix for error: multiple fields are never read
znaczko d875dae
Fix for CI error with certficate
znaczko 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
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 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 |
|---|---|---|
|
|
@@ -16,11 +16,28 @@ use tonic::transport::Certificate; | |
| use tonic::transport::ClientTlsConfig; | ||
| use tonic::transport::Endpoint; | ||
|
|
||
| #[allow(dead_code)] | ||
| #[derive(Debug)] | ||
| struct Opts { | ||
| use_tls: bool, | ||
| test_case: Vec<Testcase>, | ||
| codec: Codec, | ||
| server_host: String, | ||
| server_port: u16, | ||
| server_host_override: Option<String>, | ||
| use_test_ca: bool, | ||
| default_service_account: Option<String>, | ||
| oauth_scope: Option<String>, | ||
| service_account_key_file: Option<String>, | ||
| service_config_json: Option<String>, | ||
| additional_metadata: Option<String>, | ||
| google_c2p_universe_domain: Option<String>, | ||
| soak_iterations: usize, | ||
| soak_max_failures: usize, | ||
| soak_per_iteration_max_acceptable_latency_ms: u32, | ||
| soak_overall_timeout_seconds: Option<u32>, | ||
| soak_min_time_ms_between_rpcs: u32, | ||
| soak_num_threads: usize, | ||
| } | ||
|
|
||
| #[derive(Debug)] | ||
|
|
@@ -50,6 +67,35 @@ impl Opts { | |
| test_case.split(',').map(Testcase::from_str).collect() | ||
| })?, | ||
| codec: pargs.value_from_str("--codec")?, | ||
| server_host: pargs | ||
| .opt_value_from_str("--server_host")? | ||
| .unwrap_or_else(|| "localhost".to_string()), | ||
| server_port: pargs.opt_value_from_str("--server_port")?.unwrap_or(10000), | ||
| server_host_override: pargs.opt_value_from_str("--server_host_override")?, | ||
| use_test_ca: match pargs.opt_value_from_str::<_, bool>("--use_test_ca") { | ||
| Ok(Some(val)) => val, | ||
| Ok(None) => true, | ||
| Err(_) => true, | ||
| }, | ||
| default_service_account: pargs.opt_value_from_str("--default_service_account")?, | ||
| oauth_scope: pargs.opt_value_from_str("--oauth_scope")?, | ||
| service_account_key_file: pargs.opt_value_from_str("--service_account_key_file")?, | ||
| service_config_json: pargs.opt_value_from_str("--service_config_json")?, | ||
| additional_metadata: pargs.opt_value_from_str("--additional_metadata")?, | ||
| google_c2p_universe_domain: pargs.opt_value_from_str("--google_c2p_universe_domain")?, | ||
| soak_iterations: pargs.opt_value_from_str("--soak_iterations")?.unwrap_or(10), | ||
| soak_max_failures: pargs | ||
| .opt_value_from_str("--soak_max_failures")? | ||
| .unwrap_or(0), | ||
| soak_per_iteration_max_acceptable_latency_ms: pargs | ||
| .opt_value_from_str("--soak_per_iteration_max_acceptable_latency_ms")? | ||
| .unwrap_or(1000), | ||
| soak_overall_timeout_seconds: pargs | ||
| .opt_value_from_str("--soak_overall_timeout_seconds")?, | ||
| soak_min_time_ms_between_rpcs: pargs | ||
| .opt_value_from_str("--soak_min_time_ms_between_rpcs")? | ||
| .unwrap_or(0), | ||
| soak_num_threads: pargs.opt_value_from_str("--soak_num_threads")?.unwrap_or(1), | ||
| }) | ||
| } | ||
| } | ||
|
|
@@ -62,53 +108,102 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
|
|
||
| let test_cases = matches.test_case; | ||
|
|
||
| let additional_metadata = if let Some(ref am) = matches.additional_metadata { | ||
|
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 Opts should keep |
||
| let mut map = tonic::metadata::MetadataMap::new(); | ||
| for pair in am.split(';') { | ||
| if pair.is_empty() { | ||
| continue; | ||
| } | ||
| if let Some(colon_idx) = pair.find(':') { | ||
| let (key_str, val_str) = pair.split_at(colon_idx); | ||
| let val_str = &val_str[1..]; // strip the leading colon | ||
| let key_str = key_str.trim(); | ||
| let val_str = val_str.trim(); | ||
|
|
||
| if key_str.ends_with("-bin") { | ||
| use base64::Engine; | ||
| let decoded_val = base64::engine::general_purpose::STANDARD.decode(val_str)?; | ||
| let key = tonic::metadata::BinaryMetadataKey::from_str(key_str)?; | ||
| let value = tonic::metadata::MetadataValue::from_bytes(&decoded_val); | ||
| map.insert_bin(key, value); | ||
| } else { | ||
| let key = tonic::metadata::AsciiMetadataKey::from_str(key_str)?; | ||
| let value = tonic::metadata::MetadataValue::try_from(val_str)?; | ||
| map.insert(key, value); | ||
| } | ||
| } | ||
| } | ||
| Some(map) | ||
| } else { | ||
| None | ||
| }; | ||
|
|
||
| let (mut client, mut unimplemented_client): ( | ||
| Box<dyn InteropTest>, | ||
| Box<dyn InteropTestUnimplemented>, | ||
| ) = match matches.codec { | ||
| Codec::Prost => { | ||
| let scheme = if matches.use_tls { "https" } else { "http" }; | ||
| let mut endpoint = Endpoint::try_from(format!("{scheme}://localhost:10000"))? | ||
| let host = &matches.server_host; | ||
| let port = matches.server_port; | ||
| let mut endpoint = Endpoint::try_from(format!("{scheme}://{host}:{port}"))? | ||
| .timeout(Duration::from_secs(5)) | ||
| .concurrency_limit(30); | ||
|
|
||
| if matches.use_tls { | ||
| let pem = std::fs::read_to_string("interop/data/ca.pem")?; | ||
| let ca = Certificate::from_pem(pem); | ||
| endpoint = endpoint.tls_config( | ||
| ClientTlsConfig::new() | ||
| .ca_certificate(ca) | ||
| .domain_name("foo.test.google.fr"), | ||
| )?; | ||
| let mut tls_config = ClientTlsConfig::new(); | ||
| if matches.use_test_ca { | ||
| let pem = std::fs::read_to_string("interop/data/ca.pem")?; | ||
| let ca = Certificate::from_pem(pem); | ||
| tls_config = tls_config.ca_certificate(ca); | ||
| } | ||
| let domain_name = matches | ||
| .server_host_override | ||
| .as_deref() | ||
| .unwrap_or("foo.test.google.fr"); | ||
| tls_config = tls_config.domain_name(domain_name); | ||
| endpoint = endpoint.tls_config(tls_config)?; | ||
| } | ||
|
|
||
| let channel = endpoint.connect().await?; | ||
|
|
||
| let interceptor = interop::client::MetadataInterceptor { | ||
| metadata: additional_metadata.unwrap_or_default(), | ||
| }; | ||
| ( | ||
| Box::new(client_prost::TestClient::new(channel.clone())), | ||
| Box::new(client_prost::UnimplementedClient::new(channel)), | ||
| Box::new(client_prost::TestClient::new( | ||
| tonic::codegen::InterceptedService::new(channel.clone(), interceptor.clone()), | ||
| )), | ||
| Box::new(client_prost::UnimplementedClient::new( | ||
| tonic::codegen::InterceptedService::new(channel, interceptor), | ||
| )), | ||
| ) | ||
| } | ||
| Codec::Protobuf => { | ||
| let host = &matches.server_host; | ||
| let port = matches.server_port; | ||
| let target_uri = format!("dns:///{host}:{port}"); | ||
|
|
||
| let channel = if matches.use_tls { | ||
| let _ = rustls::crypto::ring::default_provider().install_default(); | ||
|
|
||
| let pem = std::fs::read_to_string("interop/data/ca.pem")?; | ||
| let root_certs = RootCertificates::from_pem(pem); | ||
| let creds = RustlsChannelCredendials::new( | ||
| GrpcClientTlsConfig::new() | ||
| .with_root_certificates_provider(StaticProvider::new(root_certs)), | ||
| )?; | ||
| let channel_options = | ||
| ChannelOptions::default().override_authority("test.test.google.fr"); | ||
| grpc::client::Channel::new( | ||
| "dns:///localhost:10000", | ||
| Arc::new(creds), | ||
| channel_options, | ||
| ) | ||
| let mut tls_config = GrpcClientTlsConfig::new(); | ||
| if matches.use_test_ca { | ||
| let pem = std::fs::read_to_string("interop/data/ca.pem")?; | ||
| let root_certs = RootCertificates::from_pem(pem); | ||
| tls_config = | ||
| tls_config.with_root_certificates_provider(StaticProvider::new(root_certs)); | ||
| } | ||
| let creds = RustlsChannelCredendials::new(tls_config)?; | ||
| let domain_name = matches | ||
| .server_host_override | ||
| .as_deref() | ||
| .unwrap_or("test.test.google.fr"); | ||
| let channel_options = ChannelOptions::default().override_authority(domain_name); | ||
| grpc::client::Channel::new(&target_uri, Arc::new(creds), channel_options) | ||
| } else { | ||
| grpc::client::Channel::new( | ||
| "dns:///localhost:10000", | ||
| &target_uri, | ||
| Arc::new(LocalChannelCredentials::new()), | ||
| ChannelOptions::default(), | ||
| ) | ||
|
|
@@ -129,6 +224,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
|
|
||
| match test_case { | ||
| Testcase::EmptyUnary => client.empty_unary(&mut test_results).await, | ||
| Testcase::CacheableUnary => client.cacheable_unary(&mut test_results).await, | ||
| Testcase::ClientCompressedUnary => { | ||
| client.client_compressed_unary(&mut test_results).await | ||
| } | ||
| Testcase::ServerCompressedUnary => { | ||
| client.server_compressed_unary(&mut test_results).await | ||
| } | ||
| Testcase::LargeUnary => client.large_unary(&mut test_results).await, | ||
| Testcase::ClientStreaming => client.client_streaming(&mut test_results).await, | ||
| Testcase::ServerStreaming => client.server_streaming(&mut test_results).await, | ||
|
|
@@ -147,6 +249,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
| .await | ||
| } | ||
| Testcase::CustomMetadata => client.custom_metadata(&mut test_results).await, | ||
| Testcase::CancelAfterBegin => client.cancel_after_begin(&mut test_results).await, | ||
| Testcase::CancelAfterFirstResponse => { | ||
| client.cancel_after_first_response(&mut test_results).await | ||
| } | ||
| Testcase::TimeoutOnSleepingServer => { | ||
| client.timeout_on_sleeping_server(&mut test_results).await | ||
| } | ||
| _ => unimplemented!(), | ||
| } | ||
|
|
||
|
|
||
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 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.
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.
maybe add a comment which members and why are currently unused or apply
#[allow(dead_code)]only to the members that are unused and make a general comment why they are currently unused