diff options
Diffstat (limited to 'src/ruby')
35 files changed, 375 insertions, 333 deletions
diff --git a/src/ruby/README.md b/src/ruby/README.md index 5c7dae654a..f6fce3ed22 100644 --- a/src/ruby/README.md +++ b/src/ruby/README.md @@ -22,6 +22,12 @@ BUILD FROM SOURCE --------------------- - Clone this repository +- Init submodules + +```sh +git submodule update --init +``` + - Install Ruby 2.x. Consider doing this with [RVM](http://rvm.io), it's a nice way of controlling the exact ruby version that's used. ```sh diff --git a/src/ruby/bin/apis/pubsub_demo.rb b/src/ruby/bin/apis/pubsub_demo.rb index 6f155650ed..c565771d45 100755 --- a/src/ruby/bin/apis/pubsub_demo.rb +++ b/src/ruby/bin/apis/pubsub_demo.rb @@ -193,7 +193,7 @@ end Args = Struct.new(:host, :port, :action, :project_id, :topic_name, :sub_name) -# validates the the command line options, returning them as an Arg. +# validates the command line options, returning them as an Arg. def parse_args args = Args.new('pubsub-staging.googleapis.com', 443, 'list_some_topics', 'stoked-keyword-656') diff --git a/src/ruby/end2end/channel_closing_client.rb b/src/ruby/end2end/channel_closing_client.rb index 8f6888c203..62c742158a 100755 --- a/src/ruby/end2end/channel_closing_client.rb +++ b/src/ruby/end2end/channel_closing_client.rb @@ -44,7 +44,7 @@ def main ch = GRPC::Core::Channel.new("localhost:#{server_port}", {}, :this_channel_is_insecure) - srv = GRPC::RpcServer.new + srv = new_rpc_server_for_testing thd = Thread.new do srv.add_http2_port("0.0.0.0:#{client_control_port}", :this_port_is_insecure) srv.handle(ChannelClosingClientController.new(ch)) diff --git a/src/ruby/end2end/client_memory_usage_client.rb b/src/ruby/end2end/client_memory_usage_client.rb new file mode 100755 index 0000000000..c6268b4469 --- /dev/null +++ b/src/ruby/end2end/client_memory_usage_client.rb @@ -0,0 +1,44 @@ +#!/usr/bin/env ruby + +# Copyright 2018 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require_relative './end2end_common' +require 'objspace' + +def main + server_port = '' + loop_count = 200 + + OptionParser.new do |opts| + opts.on('--client_control_port=P', String) do + STDERR.puts 'client_control_port ignored' + end + opts.on('--server_port=P', String) do |p| + server_port = p + end + end.parse! + + loop_count.times do + stub = Echo::EchoServer::Stub.new("localhost:#{server_port}", :this_channel_is_insecure) + stub.echo(Echo::EchoRequest.new(request: 'client/child')) + + # Get memory usage of all objects + ObjectSpace.memsize_of_all + end + + STDERR.puts "Succeeded in getting memory usage for #{loop_count} times" +end + +main diff --git a/src/ruby/end2end/client_memory_usage_driver.rb b/src/ruby/end2end/client_memory_usage_driver.rb new file mode 100755 index 0000000000..9e46d7e529 --- /dev/null +++ b/src/ruby/end2end/client_memory_usage_driver.rb @@ -0,0 +1,36 @@ +#!/usr/bin/env ruby + +# Copyright 2018 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require_relative './end2end_common' + +def main + STDERR.puts 'start server' + server_runner = ServerRunner.new(EchoServerImpl) + server_port = server_runner.run + STDERR.puts 'start client' + _, client_pid = start_client('client_memory_usage_client.rb', server_port) + + Process.wait(client_pid) + + client_exit_code = $CHILD_STATUS + if client_exit_code != 0 + raise "Getting memory usage was failed, exit code #{client_exit_code}" + end +ensure + server_runner.stop +end + +main diff --git a/src/ruby/end2end/end2end_common.rb b/src/ruby/end2end/end2end_common.rb index 790fc23e92..ffbaa1986d 100755 --- a/src/ruby/end2end/end2end_common.rb +++ b/src/ruby/end2end/end2end_common.rb @@ -29,6 +29,9 @@ require 'optparse' require 'thread' require 'timeout' require 'English' # see https://github.com/bbatsov/rubocop/issues/1747 +require_relative '../spec/support/helpers' + +include GRPC::Spec::Helpers # GreeterServer is simple server that implements the Helloworld Greeter server. class EchoServerImpl < Echo::EchoServer::Service @@ -46,7 +49,7 @@ class ServerRunner end def run - @srv = GRPC::RpcServer.new(@rpc_server_args) + @srv = new_rpc_server_for_testing(@rpc_server_args) port = @srv.add_http2_port('0.0.0.0:0', :this_port_is_insecure) @srv.handle(@service_impl) diff --git a/src/ruby/end2end/multiple_killed_watching_threads_driver.rb b/src/ruby/end2end/multiple_killed_watching_threads_driver.rb index 59f6f275e4..8f078cfbed 100755 --- a/src/ruby/end2end/multiple_killed_watching_threads_driver.rb +++ b/src/ruby/end2end/multiple_killed_watching_threads_driver.rb @@ -20,7 +20,7 @@ Thread.abort_on_exception = true include GRPC::Core::ConnectivityStates -def watch_state(ch) +def watch_state(ch, sleep_time) thd = Thread.new do state = ch.connectivity_state(false) fail "non-idle state: #{state}" unless state == IDLE @@ -28,23 +28,34 @@ def watch_state(ch) end # sleep to get the thread into the middle of a # "watch connectivity state" call - sleep 0.1 + sleep sleep_time thd.kill end -def main +def run_multiple_killed_watches(num_threads, sleep_time) channels = [] - 10.times do + num_threads.times do ch = GRPC::Core::Channel.new('dummy_host', nil, :this_channel_is_insecure) - watch_state(ch) + watch_state(ch, sleep_time) channels << ch end # checking state should still be safe to call channels.each do |c| - fail unless c.connectivity_state(false) == FATAL_FAILURE + connectivity_state = c.connectivity_state(false) + # The state should be FATAL_FAILURE in the case that it was interrupted + # while watching connectivity state, and IDLE if it we never started + # watching the channel's connectivity state + unless [FATAL_FAILURE, IDLE].include?(connectivity_state) + fail "unexpected connectivity state: #{connectivity_state}" + end end end +def main + run_multiple_killed_watches(10, 0.1) + run_multiple_killed_watches(1000, 0.001) +end + main diff --git a/src/ruby/end2end/sig_handling_client.rb b/src/ruby/end2end/sig_handling_client.rb index 129ad7cb7f..6cd289a29b 100755 --- a/src/ruby/end2end/sig_handling_client.rb +++ b/src/ruby/end2end/sig_handling_client.rb @@ -66,7 +66,7 @@ def main # The "shutdown" RPC should end very quickly. # Allow a few seconds to be safe. - srv = GRPC::RpcServer.new(poll_period: 3) + srv = new_rpc_server_for_testing(poll_period: 3) srv.add_http2_port("0.0.0.0:#{client_control_port}", :this_port_is_insecure) stub = Echo::EchoServer::Stub.new("localhost:#{server_port}", diff --git a/src/ruby/ext/grpc/extconf.rb b/src/ruby/ext/grpc/extconf.rb index 9d2cf2a08a..e8e87e4f15 100644 --- a/src/ruby/ext/grpc/extconf.rb +++ b/src/ruby/ext/grpc/extconf.rb @@ -61,7 +61,7 @@ ENV['EMBED_ZLIB'] = 'true' ENV['EMBED_CARES'] = 'true' ENV['ARCH_FLAGS'] = RbConfig::CONFIG['ARCH_FLAG'] ENV['ARCH_FLAGS'] = '-arch i386 -arch x86_64' if RUBY_PLATFORM =~ /darwin/ -ENV['CFLAGS'] = '-DGPR_BACKWARDS_COMPATIBILITY_MODE' +ENV['CPPFLAGS'] = '-DGPR_BACKWARDS_COMPATIBILITY_MODE' output_dir = File.expand_path(RbConfig::CONFIG['topdir']) grpc_lib_dir = File.join(output_dir, 'libs', grpc_config) @@ -94,7 +94,6 @@ $CFLAGS << ' -std=c99 ' $CFLAGS << ' -Wall ' $CFLAGS << ' -Wextra ' $CFLAGS << ' -pedantic ' -$CFLAGS << ' -Wno-format ' output = File.join('grpc', 'grpc_c') puts 'Generating Makefile for ' + output diff --git a/src/ruby/ext/grpc/rb_call.c b/src/ruby/ext/grpc/rb_call.c index 7f3ca2a8e7..b6c0791469 100644 --- a/src/ruby/ext/grpc/rb_call.c +++ b/src/ruby/ext/grpc/rb_call.c @@ -103,23 +103,11 @@ static void grpc_rb_call_destroy(void* p) { xfree(p); } -static size_t md_ary_datasize(const void* p) { - const grpc_metadata_array* const ary = (grpc_metadata_array*)p; - size_t i, datasize = sizeof(grpc_metadata_array); - for (i = 0; i < ary->count; ++i) { - const grpc_metadata* const md = &ary->metadata[i]; - datasize += GRPC_SLICE_LENGTH(md->key); - datasize += GRPC_SLICE_LENGTH(md->value); - } - datasize += ary->capacity * sizeof(grpc_metadata); - return datasize; -} - static const rb_data_type_t grpc_rb_md_ary_data_type = { "grpc_metadata_array", {GRPC_RB_GC_NOT_MARKED, GRPC_RB_GC_DONT_FREE, - md_ary_datasize, + GRPC_RB_MEMSIZE_UNAVAILABLE, {NULL, NULL}}, NULL, NULL, diff --git a/src/ruby/ext/grpc/rb_channel.c b/src/ruby/ext/grpc/rb_channel.c index 1d11a53aa7..e8bfeb32a0 100644 --- a/src/ruby/ext/grpc/rb_channel.c +++ b/src/ruby/ext/grpc/rb_channel.c @@ -362,8 +362,8 @@ static void wait_for_watch_state_op_complete_unblocking_func(void* arg) { /* Wait until the channel's connectivity state becomes different from * "last_state", or "deadline" expires. - * Returns true if the the channel's connectivity state becomes - * different from "last_state" within "deadline". + * Returns true if the channel's connectivity state becomes different + * from "last_state" within "deadline". * Returns false if "deadline" expires before the channel's connectivity * state changes from "last_state". * */ @@ -427,16 +427,15 @@ static VALUE grpc_rb_channel_create_call(VALUE self, VALUE parent, VALUE mask, parent_call = grpc_rb_get_wrapped_call(parent); } - cq = grpc_completion_queue_create_for_pluck(NULL); TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper); if (wrapper->bg_wrapped == NULL) { rb_raise(rb_eRuntimeError, "closed!"); return Qnil; } + cq = grpc_completion_queue_create_for_pluck(NULL); method_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(method), RSTRING_LEN(method)); - call = grpc_channel_create_call(wrapper->bg_wrapped->channel, parent_call, flags, cq, method_slice, host_slice_ptr, grpc_rb_time_timeval(deadline, diff --git a/src/ruby/ext/grpc/rb_compression_options.c b/src/ruby/ext/grpc/rb_compression_options.c index e24f20d2f9..4ba6991ef6 100644 --- a/src/ruby/ext/grpc/rb_compression_options.c +++ b/src/ruby/ext/grpc/rb_compression_options.c @@ -27,6 +27,8 @@ #include <grpc/impl/codegen/compression_types.h> #include <grpc/impl/codegen/grpc_types.h> #include <grpc/support/alloc.h> +#include <grpc/support/log.h> +#include <grpc/support/string_util.h> #include <string.h> #include "rb_grpc.h" @@ -159,7 +161,6 @@ void grpc_rb_compression_options_algorithm_name_to_value_internal( grpc_compression_algorithm* algorithm_value, VALUE algorithm_name) { grpc_slice name_slice; VALUE algorithm_name_as_string = Qnil; - char* tmp_str = NULL; Check_Type(algorithm_name, T_SYMBOL); @@ -175,8 +176,17 @@ void grpc_rb_compression_options_algorithm_name_to_value_internal( * the algorithm parse function * in GRPC core. */ if (!grpc_compression_algorithm_parse(name_slice, algorithm_value)) { - tmp_str = grpc_slice_to_c_string(name_slice); - rb_raise(rb_eNameError, "Invalid compression algorithm name: %s", tmp_str); + char* name_slice_str = grpc_slice_to_c_string(name_slice); + char* error_message_str = NULL; + VALUE error_message_ruby_str = Qnil; + GPR_ASSERT(gpr_asprintf(&error_message_str, + "Invalid compression algorithm name: %s", + name_slice_str) != -1); + gpr_free(name_slice_str); + error_message_ruby_str = + rb_str_new(error_message_str, strlen(error_message_str)); + gpr_free(error_message_str); + rb_raise(rb_eNameError, "%s", StringValueCStr(error_message_ruby_str)); } grpc_slice_unref(name_slice); diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.c b/src/ruby/ext/grpc/rb_grpc_imports.generated.c index 56f1d4c93f..a12819e87c 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.c +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.c @@ -22,16 +22,15 @@ #include "rb_grpc_imports.generated.h" +grpc_compression_algorithm_is_message_type grpc_compression_algorithm_is_message_import; +grpc_compression_algorithm_is_stream_type grpc_compression_algorithm_is_stream_import; grpc_compression_algorithm_parse_type grpc_compression_algorithm_parse_import; grpc_compression_algorithm_name_type grpc_compression_algorithm_name_import; -grpc_stream_compression_algorithm_name_type grpc_stream_compression_algorithm_name_import; grpc_compression_algorithm_for_level_type grpc_compression_algorithm_for_level_import; -grpc_stream_compression_algorithm_for_level_type grpc_stream_compression_algorithm_for_level_import; grpc_compression_options_init_type grpc_compression_options_init_import; grpc_compression_options_enable_algorithm_type grpc_compression_options_enable_algorithm_import; grpc_compression_options_disable_algorithm_type grpc_compression_options_disable_algorithm_import; grpc_compression_options_is_algorithm_enabled_type grpc_compression_options_is_algorithm_enabled_import; -grpc_compression_options_is_stream_compression_algorithm_enabled_type grpc_compression_options_is_stream_compression_algorithm_enabled_import; grpc_metadata_array_init_type grpc_metadata_array_init_import; grpc_metadata_array_destroy_type grpc_metadata_array_destroy_import; grpc_call_details_init_type grpc_call_details_init_import; @@ -51,10 +50,6 @@ grpc_completion_queue_shutdown_type grpc_completion_queue_shutdown_import; grpc_completion_queue_destroy_type grpc_completion_queue_destroy_import; grpc_completion_queue_thread_local_cache_init_type grpc_completion_queue_thread_local_cache_init_import; grpc_completion_queue_thread_local_cache_flush_type grpc_completion_queue_thread_local_cache_flush_import; -grpc_alarm_create_type grpc_alarm_create_import; -grpc_alarm_set_type grpc_alarm_set_import; -grpc_alarm_cancel_type grpc_alarm_cancel_import; -grpc_alarm_destroy_type grpc_alarm_destroy_import; grpc_channel_check_connectivity_state_type grpc_channel_check_connectivity_state_import; grpc_channel_num_external_connectivity_watchers_type grpc_channel_num_external_connectivity_watchers_import; grpc_channel_watch_connectivity_state_type grpc_channel_watch_connectivity_state_import; @@ -73,6 +68,8 @@ grpc_channel_get_info_type grpc_channel_get_info_import; grpc_insecure_channel_create_type grpc_insecure_channel_create_import; grpc_lame_client_channel_create_type grpc_lame_client_channel_create_import; grpc_channel_destroy_type grpc_channel_destroy_import; +grpc_channel_get_trace_type grpc_channel_get_trace_import; +grpc_channel_get_uuid_type grpc_channel_get_uuid_import; grpc_call_cancel_type grpc_call_cancel_import; grpc_call_cancel_with_status_type grpc_call_cancel_with_status_import; grpc_call_ref_type grpc_call_ref_import; @@ -111,6 +108,9 @@ grpc_auth_context_release_type grpc_auth_context_release_import; grpc_auth_context_add_property_type grpc_auth_context_add_property_import; grpc_auth_context_add_cstring_property_type grpc_auth_context_add_cstring_property_import; grpc_auth_context_set_peer_identity_property_name_type grpc_auth_context_set_peer_identity_property_name_import; +grpc_ssl_session_cache_create_lru_type grpc_ssl_session_cache_create_lru_import; +grpc_ssl_session_cache_destroy_type grpc_ssl_session_cache_destroy_import; +grpc_ssl_session_cache_create_channel_arg_type grpc_ssl_session_cache_create_channel_arg_import; grpc_channel_credentials_release_type grpc_channel_credentials_release_import; grpc_google_default_credentials_create_type grpc_google_default_credentials_create_import; grpc_set_ssl_roots_override_callback_type grpc_set_ssl_roots_override_callback_import; @@ -204,27 +204,8 @@ gpr_malloc_aligned_type gpr_malloc_aligned_import; gpr_free_aligned_type gpr_free_aligned_import; gpr_set_allocation_functions_type gpr_set_allocation_functions_import; gpr_get_allocation_functions_type gpr_get_allocation_functions_import; -gpr_avl_create_type gpr_avl_create_import; -gpr_avl_ref_type gpr_avl_ref_import; -gpr_avl_unref_type gpr_avl_unref_import; -gpr_avl_add_type gpr_avl_add_import; -gpr_avl_remove_type gpr_avl_remove_import; -gpr_avl_get_type gpr_avl_get_import; -gpr_avl_maybe_get_type gpr_avl_maybe_get_import; -gpr_avl_is_empty_type gpr_avl_is_empty_import; -gpr_cmdline_create_type gpr_cmdline_create_import; -gpr_cmdline_add_int_type gpr_cmdline_add_int_import; -gpr_cmdline_add_flag_type gpr_cmdline_add_flag_import; -gpr_cmdline_add_string_type gpr_cmdline_add_string_import; -gpr_cmdline_on_extra_arg_type gpr_cmdline_on_extra_arg_import; -gpr_cmdline_set_survive_failure_type gpr_cmdline_set_survive_failure_import; -gpr_cmdline_parse_type gpr_cmdline_parse_import; -gpr_cmdline_destroy_type gpr_cmdline_destroy_import; -gpr_cmdline_usage_string_type gpr_cmdline_usage_string_import; gpr_cpu_num_cores_type gpr_cpu_num_cores_import; gpr_cpu_current_cpu_type gpr_cpu_current_cpu_import; -gpr_join_host_port_type gpr_join_host_port_import; -gpr_split_host_port_type gpr_split_host_port_import; gpr_log_severity_string_type gpr_log_severity_string_import; gpr_log_type gpr_log_import; gpr_log_message_type gpr_log_message_import; @@ -234,11 +215,6 @@ gpr_set_log_function_type gpr_set_log_function_import; gpr_format_message_type gpr_format_message_import; gpr_strdup_type gpr_strdup_import; gpr_asprintf_type gpr_asprintf_import; -gpr_subprocess_binary_extension_type gpr_subprocess_binary_extension_import; -gpr_subprocess_create_type gpr_subprocess_create_import; -gpr_subprocess_destroy_type gpr_subprocess_destroy_import; -gpr_subprocess_join_type gpr_subprocess_join_import; -gpr_subprocess_interrupt_type gpr_subprocess_interrupt_import; gpr_mu_init_type gpr_mu_init_import; gpr_mu_destroy_type gpr_mu_destroy_import; gpr_mu_lock_type gpr_mu_lock_import; @@ -263,14 +239,7 @@ gpr_ref_is_unique_type gpr_ref_is_unique_import; gpr_stats_init_type gpr_stats_init_import; gpr_stats_inc_type gpr_stats_inc_import; gpr_stats_read_type gpr_stats_read_import; -gpr_thd_new_type gpr_thd_new_import; -gpr_thd_options_default_type gpr_thd_options_default_import; -gpr_thd_options_set_detached_type gpr_thd_options_set_detached_import; -gpr_thd_options_set_joinable_type gpr_thd_options_set_joinable_import; -gpr_thd_options_is_detached_type gpr_thd_options_is_detached_import; -gpr_thd_options_is_joinable_type gpr_thd_options_is_joinable_import; gpr_thd_currentid_type gpr_thd_currentid_import; -gpr_thd_join_type gpr_thd_join_import; gpr_time_0_type gpr_time_0_import; gpr_inf_future_type gpr_inf_future_import; gpr_inf_past_type gpr_inf_past_import; @@ -294,16 +263,15 @@ gpr_sleep_until_type gpr_sleep_until_import; gpr_timespec_to_micros_type gpr_timespec_to_micros_import; void grpc_rb_load_imports(HMODULE library) { + grpc_compression_algorithm_is_message_import = (grpc_compression_algorithm_is_message_type) GetProcAddress(library, "grpc_compression_algorithm_is_message"); + grpc_compression_algorithm_is_stream_import = (grpc_compression_algorithm_is_stream_type) GetProcAddress(library, "grpc_compression_algorithm_is_stream"); grpc_compression_algorithm_parse_import = (grpc_compression_algorithm_parse_type) GetProcAddress(library, "grpc_compression_algorithm_parse"); grpc_compression_algorithm_name_import = (grpc_compression_algorithm_name_type) GetProcAddress(library, "grpc_compression_algorithm_name"); - grpc_stream_compression_algorithm_name_import = (grpc_stream_compression_algorithm_name_type) GetProcAddress(library, "grpc_stream_compression_algorithm_name"); grpc_compression_algorithm_for_level_import = (grpc_compression_algorithm_for_level_type) GetProcAddress(library, "grpc_compression_algorithm_for_level"); - grpc_stream_compression_algorithm_for_level_import = (grpc_stream_compression_algorithm_for_level_type) GetProcAddress(library, "grpc_stream_compression_algorithm_for_level"); grpc_compression_options_init_import = (grpc_compression_options_init_type) GetProcAddress(library, "grpc_compression_options_init"); grpc_compression_options_enable_algorithm_import = (grpc_compression_options_enable_algorithm_type) GetProcAddress(library, "grpc_compression_options_enable_algorithm"); grpc_compression_options_disable_algorithm_import = (grpc_compression_options_disable_algorithm_type) GetProcAddress(library, "grpc_compression_options_disable_algorithm"); grpc_compression_options_is_algorithm_enabled_import = (grpc_compression_options_is_algorithm_enabled_type) GetProcAddress(library, "grpc_compression_options_is_algorithm_enabled"); - grpc_compression_options_is_stream_compression_algorithm_enabled_import = (grpc_compression_options_is_stream_compression_algorithm_enabled_type) GetProcAddress(library, "grpc_compression_options_is_stream_compression_algorithm_enabled"); grpc_metadata_array_init_import = (grpc_metadata_array_init_type) GetProcAddress(library, "grpc_metadata_array_init"); grpc_metadata_array_destroy_import = (grpc_metadata_array_destroy_type) GetProcAddress(library, "grpc_metadata_array_destroy"); grpc_call_details_init_import = (grpc_call_details_init_type) GetProcAddress(library, "grpc_call_details_init"); @@ -323,10 +291,6 @@ void grpc_rb_load_imports(HMODULE library) { grpc_completion_queue_destroy_import = (grpc_completion_queue_destroy_type) GetProcAddress(library, "grpc_completion_queue_destroy"); grpc_completion_queue_thread_local_cache_init_import = (grpc_completion_queue_thread_local_cache_init_type) GetProcAddress(library, "grpc_completion_queue_thread_local_cache_init"); grpc_completion_queue_thread_local_cache_flush_import = (grpc_completion_queue_thread_local_cache_flush_type) GetProcAddress(library, "grpc_completion_queue_thread_local_cache_flush"); - grpc_alarm_create_import = (grpc_alarm_create_type) GetProcAddress(library, "grpc_alarm_create"); - grpc_alarm_set_import = (grpc_alarm_set_type) GetProcAddress(library, "grpc_alarm_set"); - grpc_alarm_cancel_import = (grpc_alarm_cancel_type) GetProcAddress(library, "grpc_alarm_cancel"); - grpc_alarm_destroy_import = (grpc_alarm_destroy_type) GetProcAddress(library, "grpc_alarm_destroy"); grpc_channel_check_connectivity_state_import = (grpc_channel_check_connectivity_state_type) GetProcAddress(library, "grpc_channel_check_connectivity_state"); grpc_channel_num_external_connectivity_watchers_import = (grpc_channel_num_external_connectivity_watchers_type) GetProcAddress(library, "grpc_channel_num_external_connectivity_watchers"); grpc_channel_watch_connectivity_state_import = (grpc_channel_watch_connectivity_state_type) GetProcAddress(library, "grpc_channel_watch_connectivity_state"); @@ -345,6 +309,8 @@ void grpc_rb_load_imports(HMODULE library) { grpc_insecure_channel_create_import = (grpc_insecure_channel_create_type) GetProcAddress(library, "grpc_insecure_channel_create"); grpc_lame_client_channel_create_import = (grpc_lame_client_channel_create_type) GetProcAddress(library, "grpc_lame_client_channel_create"); grpc_channel_destroy_import = (grpc_channel_destroy_type) GetProcAddress(library, "grpc_channel_destroy"); + grpc_channel_get_trace_import = (grpc_channel_get_trace_type) GetProcAddress(library, "grpc_channel_get_trace"); + grpc_channel_get_uuid_import = (grpc_channel_get_uuid_type) GetProcAddress(library, "grpc_channel_get_uuid"); grpc_call_cancel_import = (grpc_call_cancel_type) GetProcAddress(library, "grpc_call_cancel"); grpc_call_cancel_with_status_import = (grpc_call_cancel_with_status_type) GetProcAddress(library, "grpc_call_cancel_with_status"); grpc_call_ref_import = (grpc_call_ref_type) GetProcAddress(library, "grpc_call_ref"); @@ -383,6 +349,9 @@ void grpc_rb_load_imports(HMODULE library) { grpc_auth_context_add_property_import = (grpc_auth_context_add_property_type) GetProcAddress(library, "grpc_auth_context_add_property"); grpc_auth_context_add_cstring_property_import = (grpc_auth_context_add_cstring_property_type) GetProcAddress(library, "grpc_auth_context_add_cstring_property"); grpc_auth_context_set_peer_identity_property_name_import = (grpc_auth_context_set_peer_identity_property_name_type) GetProcAddress(library, "grpc_auth_context_set_peer_identity_property_name"); + grpc_ssl_session_cache_create_lru_import = (grpc_ssl_session_cache_create_lru_type) GetProcAddress(library, "grpc_ssl_session_cache_create_lru"); + grpc_ssl_session_cache_destroy_import = (grpc_ssl_session_cache_destroy_type) GetProcAddress(library, "grpc_ssl_session_cache_destroy"); + grpc_ssl_session_cache_create_channel_arg_import = (grpc_ssl_session_cache_create_channel_arg_type) GetProcAddress(library, "grpc_ssl_session_cache_create_channel_arg"); grpc_channel_credentials_release_import = (grpc_channel_credentials_release_type) GetProcAddress(library, "grpc_channel_credentials_release"); grpc_google_default_credentials_create_import = (grpc_google_default_credentials_create_type) GetProcAddress(library, "grpc_google_default_credentials_create"); grpc_set_ssl_roots_override_callback_import = (grpc_set_ssl_roots_override_callback_type) GetProcAddress(library, "grpc_set_ssl_roots_override_callback"); @@ -476,27 +445,8 @@ void grpc_rb_load_imports(HMODULE library) { gpr_free_aligned_import = (gpr_free_aligned_type) GetProcAddress(library, "gpr_free_aligned"); gpr_set_allocation_functions_import = (gpr_set_allocation_functions_type) GetProcAddress(library, "gpr_set_allocation_functions"); gpr_get_allocation_functions_import = (gpr_get_allocation_functions_type) GetProcAddress(library, "gpr_get_allocation_functions"); - gpr_avl_create_import = (gpr_avl_create_type) GetProcAddress(library, "gpr_avl_create"); - gpr_avl_ref_import = (gpr_avl_ref_type) GetProcAddress(library, "gpr_avl_ref"); - gpr_avl_unref_import = (gpr_avl_unref_type) GetProcAddress(library, "gpr_avl_unref"); - gpr_avl_add_import = (gpr_avl_add_type) GetProcAddress(library, "gpr_avl_add"); - gpr_avl_remove_import = (gpr_avl_remove_type) GetProcAddress(library, "gpr_avl_remove"); - gpr_avl_get_import = (gpr_avl_get_type) GetProcAddress(library, "gpr_avl_get"); - gpr_avl_maybe_get_import = (gpr_avl_maybe_get_type) GetProcAddress(library, "gpr_avl_maybe_get"); - gpr_avl_is_empty_import = (gpr_avl_is_empty_type) GetProcAddress(library, "gpr_avl_is_empty"); - gpr_cmdline_create_import = (gpr_cmdline_create_type) GetProcAddress(library, "gpr_cmdline_create"); - gpr_cmdline_add_int_import = (gpr_cmdline_add_int_type) GetProcAddress(library, "gpr_cmdline_add_int"); - gpr_cmdline_add_flag_import = (gpr_cmdline_add_flag_type) GetProcAddress(library, "gpr_cmdline_add_flag"); - gpr_cmdline_add_string_import = (gpr_cmdline_add_string_type) GetProcAddress(library, "gpr_cmdline_add_string"); - gpr_cmdline_on_extra_arg_import = (gpr_cmdline_on_extra_arg_type) GetProcAddress(library, "gpr_cmdline_on_extra_arg"); - gpr_cmdline_set_survive_failure_import = (gpr_cmdline_set_survive_failure_type) GetProcAddress(library, "gpr_cmdline_set_survive_failure"); - gpr_cmdline_parse_import = (gpr_cmdline_parse_type) GetProcAddress(library, "gpr_cmdline_parse"); - gpr_cmdline_destroy_import = (gpr_cmdline_destroy_type) GetProcAddress(library, "gpr_cmdline_destroy"); - gpr_cmdline_usage_string_import = (gpr_cmdline_usage_string_type) GetProcAddress(library, "gpr_cmdline_usage_string"); gpr_cpu_num_cores_import = (gpr_cpu_num_cores_type) GetProcAddress(library, "gpr_cpu_num_cores"); gpr_cpu_current_cpu_import = (gpr_cpu_current_cpu_type) GetProcAddress(library, "gpr_cpu_current_cpu"); - gpr_join_host_port_import = (gpr_join_host_port_type) GetProcAddress(library, "gpr_join_host_port"); - gpr_split_host_port_import = (gpr_split_host_port_type) GetProcAddress(library, "gpr_split_host_port"); gpr_log_severity_string_import = (gpr_log_severity_string_type) GetProcAddress(library, "gpr_log_severity_string"); gpr_log_import = (gpr_log_type) GetProcAddress(library, "gpr_log"); gpr_log_message_import = (gpr_log_message_type) GetProcAddress(library, "gpr_log_message"); @@ -506,11 +456,6 @@ void grpc_rb_load_imports(HMODULE library) { gpr_format_message_import = (gpr_format_message_type) GetProcAddress(library, "gpr_format_message"); gpr_strdup_import = (gpr_strdup_type) GetProcAddress(library, "gpr_strdup"); gpr_asprintf_import = (gpr_asprintf_type) GetProcAddress(library, "gpr_asprintf"); - gpr_subprocess_binary_extension_import = (gpr_subprocess_binary_extension_type) GetProcAddress(library, "gpr_subprocess_binary_extension"); - gpr_subprocess_create_import = (gpr_subprocess_create_type) GetProcAddress(library, "gpr_subprocess_create"); - gpr_subprocess_destroy_import = (gpr_subprocess_destroy_type) GetProcAddress(library, "gpr_subprocess_destroy"); - gpr_subprocess_join_import = (gpr_subprocess_join_type) GetProcAddress(library, "gpr_subprocess_join"); - gpr_subprocess_interrupt_import = (gpr_subprocess_interrupt_type) GetProcAddress(library, "gpr_subprocess_interrupt"); gpr_mu_init_import = (gpr_mu_init_type) GetProcAddress(library, "gpr_mu_init"); gpr_mu_destroy_import = (gpr_mu_destroy_type) GetProcAddress(library, "gpr_mu_destroy"); gpr_mu_lock_import = (gpr_mu_lock_type) GetProcAddress(library, "gpr_mu_lock"); @@ -535,14 +480,7 @@ void grpc_rb_load_imports(HMODULE library) { gpr_stats_init_import = (gpr_stats_init_type) GetProcAddress(library, "gpr_stats_init"); gpr_stats_inc_import = (gpr_stats_inc_type) GetProcAddress(library, "gpr_stats_inc"); gpr_stats_read_import = (gpr_stats_read_type) GetProcAddress(library, "gpr_stats_read"); - gpr_thd_new_import = (gpr_thd_new_type) GetProcAddress(library, "gpr_thd_new"); - gpr_thd_options_default_import = (gpr_thd_options_default_type) GetProcAddress(library, "gpr_thd_options_default"); - gpr_thd_options_set_detached_import = (gpr_thd_options_set_detached_type) GetProcAddress(library, "gpr_thd_options_set_detached"); - gpr_thd_options_set_joinable_import = (gpr_thd_options_set_joinable_type) GetProcAddress(library, "gpr_thd_options_set_joinable"); - gpr_thd_options_is_detached_import = (gpr_thd_options_is_detached_type) GetProcAddress(library, "gpr_thd_options_is_detached"); - gpr_thd_options_is_joinable_import = (gpr_thd_options_is_joinable_type) GetProcAddress(library, "gpr_thd_options_is_joinable"); gpr_thd_currentid_import = (gpr_thd_currentid_type) GetProcAddress(library, "gpr_thd_currentid"); - gpr_thd_join_import = (gpr_thd_join_type) GetProcAddress(library, "gpr_thd_join"); gpr_time_0_import = (gpr_time_0_type) GetProcAddress(library, "gpr_time_0"); gpr_inf_future_import = (gpr_inf_future_type) GetProcAddress(library, "gpr_inf_future"); gpr_inf_past_import = (gpr_inf_past_type) GetProcAddress(library, "gpr_inf_past"); diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.h b/src/ruby/ext/grpc/rb_grpc_imports.generated.h index 62223fda5b..089cb8a61a 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.h +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.h @@ -33,33 +33,29 @@ #include <grpc/slice.h> #include <grpc/slice_buffer.h> #include <grpc/support/alloc.h> -#include <grpc/support/avl.h> -#include <grpc/support/cmdline.h> #include <grpc/support/cpu.h> -#include <grpc/support/host_port.h> #include <grpc/support/log.h> #include <grpc/support/log_windows.h> #include <grpc/support/string_util.h> -#include <grpc/support/subprocess.h> #include <grpc/support/sync.h> -#include <grpc/support/thd.h> +#include <grpc/support/thd_id.h> #include <grpc/support/time.h> +typedef int(*grpc_compression_algorithm_is_message_type)(grpc_compression_algorithm algorithm); +extern grpc_compression_algorithm_is_message_type grpc_compression_algorithm_is_message_import; +#define grpc_compression_algorithm_is_message grpc_compression_algorithm_is_message_import +typedef int(*grpc_compression_algorithm_is_stream_type)(grpc_compression_algorithm algorithm); +extern grpc_compression_algorithm_is_stream_type grpc_compression_algorithm_is_stream_import; +#define grpc_compression_algorithm_is_stream grpc_compression_algorithm_is_stream_import typedef int(*grpc_compression_algorithm_parse_type)(grpc_slice value, grpc_compression_algorithm* algorithm); extern grpc_compression_algorithm_parse_type grpc_compression_algorithm_parse_import; #define grpc_compression_algorithm_parse grpc_compression_algorithm_parse_import typedef int(*grpc_compression_algorithm_name_type)(grpc_compression_algorithm algorithm, const char** name); extern grpc_compression_algorithm_name_type grpc_compression_algorithm_name_import; #define grpc_compression_algorithm_name grpc_compression_algorithm_name_import -typedef int(*grpc_stream_compression_algorithm_name_type)(grpc_stream_compression_algorithm algorithm, const char** name); -extern grpc_stream_compression_algorithm_name_type grpc_stream_compression_algorithm_name_import; -#define grpc_stream_compression_algorithm_name grpc_stream_compression_algorithm_name_import typedef grpc_compression_algorithm(*grpc_compression_algorithm_for_level_type)(grpc_compression_level level, uint32_t accepted_encodings); extern grpc_compression_algorithm_for_level_type grpc_compression_algorithm_for_level_import; #define grpc_compression_algorithm_for_level grpc_compression_algorithm_for_level_import -typedef grpc_stream_compression_algorithm(*grpc_stream_compression_algorithm_for_level_type)(grpc_stream_compression_level level, uint32_t accepted_stream_encodings); -extern grpc_stream_compression_algorithm_for_level_type grpc_stream_compression_algorithm_for_level_import; -#define grpc_stream_compression_algorithm_for_level grpc_stream_compression_algorithm_for_level_import typedef void(*grpc_compression_options_init_type)(grpc_compression_options* opts); extern grpc_compression_options_init_type grpc_compression_options_init_import; #define grpc_compression_options_init grpc_compression_options_init_import @@ -72,9 +68,6 @@ extern grpc_compression_options_disable_algorithm_type grpc_compression_options_ typedef int(*grpc_compression_options_is_algorithm_enabled_type)(const grpc_compression_options* opts, grpc_compression_algorithm algorithm); extern grpc_compression_options_is_algorithm_enabled_type grpc_compression_options_is_algorithm_enabled_import; #define grpc_compression_options_is_algorithm_enabled grpc_compression_options_is_algorithm_enabled_import -typedef int(*grpc_compression_options_is_stream_compression_algorithm_enabled_type)(const grpc_compression_options* opts, grpc_stream_compression_algorithm algorithm); -extern grpc_compression_options_is_stream_compression_algorithm_enabled_type grpc_compression_options_is_stream_compression_algorithm_enabled_import; -#define grpc_compression_options_is_stream_compression_algorithm_enabled grpc_compression_options_is_stream_compression_algorithm_enabled_import typedef void(*grpc_metadata_array_init_type)(grpc_metadata_array* array); extern grpc_metadata_array_init_type grpc_metadata_array_init_import; #define grpc_metadata_array_init grpc_metadata_array_init_import @@ -132,18 +125,6 @@ extern grpc_completion_queue_thread_local_cache_init_type grpc_completion_queue_ typedef int(*grpc_completion_queue_thread_local_cache_flush_type)(grpc_completion_queue* cq, void** tag, int* ok); extern grpc_completion_queue_thread_local_cache_flush_type grpc_completion_queue_thread_local_cache_flush_import; #define grpc_completion_queue_thread_local_cache_flush grpc_completion_queue_thread_local_cache_flush_import -typedef grpc_alarm*(*grpc_alarm_create_type)(void* reserved); -extern grpc_alarm_create_type grpc_alarm_create_import; -#define grpc_alarm_create grpc_alarm_create_import -typedef void(*grpc_alarm_set_type)(grpc_alarm* alarm, grpc_completion_queue* cq, gpr_timespec deadline, void* tag, void* reserved); -extern grpc_alarm_set_type grpc_alarm_set_import; -#define grpc_alarm_set grpc_alarm_set_import -typedef void(*grpc_alarm_cancel_type)(grpc_alarm* alarm, void* reserved); -extern grpc_alarm_cancel_type grpc_alarm_cancel_import; -#define grpc_alarm_cancel grpc_alarm_cancel_import -typedef void(*grpc_alarm_destroy_type)(grpc_alarm* alarm, void* reserved); -extern grpc_alarm_destroy_type grpc_alarm_destroy_import; -#define grpc_alarm_destroy grpc_alarm_destroy_import typedef grpc_connectivity_state(*grpc_channel_check_connectivity_state_type)(grpc_channel* channel, int try_to_connect); extern grpc_channel_check_connectivity_state_type grpc_channel_check_connectivity_state_import; #define grpc_channel_check_connectivity_state grpc_channel_check_connectivity_state_import @@ -198,6 +179,12 @@ extern grpc_lame_client_channel_create_type grpc_lame_client_channel_create_impo typedef void(*grpc_channel_destroy_type)(grpc_channel* channel); extern grpc_channel_destroy_type grpc_channel_destroy_import; #define grpc_channel_destroy grpc_channel_destroy_import +typedef char*(*grpc_channel_get_trace_type)(grpc_channel* channel); +extern grpc_channel_get_trace_type grpc_channel_get_trace_import; +#define grpc_channel_get_trace grpc_channel_get_trace_import +typedef intptr_t(*grpc_channel_get_uuid_type)(grpc_channel* channel); +extern grpc_channel_get_uuid_type grpc_channel_get_uuid_import; +#define grpc_channel_get_uuid grpc_channel_get_uuid_import typedef grpc_call_error(*grpc_call_cancel_type)(grpc_call* call, void* reserved); extern grpc_call_cancel_type grpc_call_cancel_import; #define grpc_call_cancel grpc_call_cancel_import @@ -312,6 +299,15 @@ extern grpc_auth_context_add_cstring_property_type grpc_auth_context_add_cstring typedef int(*grpc_auth_context_set_peer_identity_property_name_type)(grpc_auth_context* ctx, const char* name); extern grpc_auth_context_set_peer_identity_property_name_type grpc_auth_context_set_peer_identity_property_name_import; #define grpc_auth_context_set_peer_identity_property_name grpc_auth_context_set_peer_identity_property_name_import +typedef grpc_ssl_session_cache*(*grpc_ssl_session_cache_create_lru_type)(size_t capacity); +extern grpc_ssl_session_cache_create_lru_type grpc_ssl_session_cache_create_lru_import; +#define grpc_ssl_session_cache_create_lru grpc_ssl_session_cache_create_lru_import +typedef void(*grpc_ssl_session_cache_destroy_type)(grpc_ssl_session_cache* cache); +extern grpc_ssl_session_cache_destroy_type grpc_ssl_session_cache_destroy_import; +#define grpc_ssl_session_cache_destroy grpc_ssl_session_cache_destroy_import +typedef grpc_arg(*grpc_ssl_session_cache_create_channel_arg_type)(grpc_ssl_session_cache* cache); +extern grpc_ssl_session_cache_create_channel_arg_type grpc_ssl_session_cache_create_channel_arg_import; +#define grpc_ssl_session_cache_create_channel_arg grpc_ssl_session_cache_create_channel_arg_import typedef void(*grpc_channel_credentials_release_type)(grpc_channel_credentials* creds); extern grpc_channel_credentials_release_type grpc_channel_credentials_release_import; #define grpc_channel_credentials_release grpc_channel_credentials_release_import @@ -558,7 +554,7 @@ extern grpc_slice_buffer_move_first_type grpc_slice_buffer_move_first_import; typedef void(*grpc_slice_buffer_move_first_no_ref_type)(grpc_slice_buffer* src, size_t n, grpc_slice_buffer* dst); extern grpc_slice_buffer_move_first_no_ref_type grpc_slice_buffer_move_first_no_ref_import; #define grpc_slice_buffer_move_first_no_ref grpc_slice_buffer_move_first_no_ref_import -typedef void(*grpc_slice_buffer_move_first_into_buffer_type)(grpc_exec_ctx* exec_ctx, grpc_slice_buffer* src, size_t n, void* dst); +typedef void(*grpc_slice_buffer_move_first_into_buffer_type)(grpc_slice_buffer* src, size_t n, void* dst); extern grpc_slice_buffer_move_first_into_buffer_type grpc_slice_buffer_move_first_into_buffer_import; #define grpc_slice_buffer_move_first_into_buffer grpc_slice_buffer_move_first_into_buffer_import typedef grpc_slice(*grpc_slice_buffer_take_first_type)(grpc_slice_buffer* src); @@ -579,7 +575,7 @@ extern gpr_free_type gpr_free_import; typedef void*(*gpr_realloc_type)(void* p, size_t size); extern gpr_realloc_type gpr_realloc_import; #define gpr_realloc gpr_realloc_import -typedef void*(*gpr_malloc_aligned_type)(size_t size, size_t alignment_log); +typedef void*(*gpr_malloc_aligned_type)(size_t size, size_t alignment); extern gpr_malloc_aligned_type gpr_malloc_aligned_import; #define gpr_malloc_aligned gpr_malloc_aligned_import typedef void(*gpr_free_aligned_type)(void* ptr); @@ -591,69 +587,12 @@ extern gpr_set_allocation_functions_type gpr_set_allocation_functions_import; typedef gpr_allocation_functions(*gpr_get_allocation_functions_type)(void); extern gpr_get_allocation_functions_type gpr_get_allocation_functions_import; #define gpr_get_allocation_functions gpr_get_allocation_functions_import -typedef gpr_avl(*gpr_avl_create_type)(const gpr_avl_vtable* vtable); -extern gpr_avl_create_type gpr_avl_create_import; -#define gpr_avl_create gpr_avl_create_import -typedef gpr_avl(*gpr_avl_ref_type)(gpr_avl avl, void* user_data); -extern gpr_avl_ref_type gpr_avl_ref_import; -#define gpr_avl_ref gpr_avl_ref_import -typedef void(*gpr_avl_unref_type)(gpr_avl avl, void* user_data); -extern gpr_avl_unref_type gpr_avl_unref_import; -#define gpr_avl_unref gpr_avl_unref_import -typedef gpr_avl(*gpr_avl_add_type)(gpr_avl avl, void* key, void* value, void* user_data); -extern gpr_avl_add_type gpr_avl_add_import; -#define gpr_avl_add gpr_avl_add_import -typedef gpr_avl(*gpr_avl_remove_type)(gpr_avl avl, void* key, void* user_data); -extern gpr_avl_remove_type gpr_avl_remove_import; -#define gpr_avl_remove gpr_avl_remove_import -typedef void*(*gpr_avl_get_type)(gpr_avl avl, void* key, void* user_data); -extern gpr_avl_get_type gpr_avl_get_import; -#define gpr_avl_get gpr_avl_get_import -typedef int(*gpr_avl_maybe_get_type)(gpr_avl avl, void* key, void** value, void* user_data); -extern gpr_avl_maybe_get_type gpr_avl_maybe_get_import; -#define gpr_avl_maybe_get gpr_avl_maybe_get_import -typedef int(*gpr_avl_is_empty_type)(gpr_avl avl); -extern gpr_avl_is_empty_type gpr_avl_is_empty_import; -#define gpr_avl_is_empty gpr_avl_is_empty_import -typedef gpr_cmdline*(*gpr_cmdline_create_type)(const char* description); -extern gpr_cmdline_create_type gpr_cmdline_create_import; -#define gpr_cmdline_create gpr_cmdline_create_import -typedef void(*gpr_cmdline_add_int_type)(gpr_cmdline* cl, const char* name, const char* help, int* value); -extern gpr_cmdline_add_int_type gpr_cmdline_add_int_import; -#define gpr_cmdline_add_int gpr_cmdline_add_int_import -typedef void(*gpr_cmdline_add_flag_type)(gpr_cmdline* cl, const char* name, const char* help, int* value); -extern gpr_cmdline_add_flag_type gpr_cmdline_add_flag_import; -#define gpr_cmdline_add_flag gpr_cmdline_add_flag_import -typedef void(*gpr_cmdline_add_string_type)(gpr_cmdline* cl, const char* name, const char* help, const char** value); -extern gpr_cmdline_add_string_type gpr_cmdline_add_string_import; -#define gpr_cmdline_add_string gpr_cmdline_add_string_import -typedef void(*gpr_cmdline_on_extra_arg_type)(gpr_cmdline* cl, const char* name, const char* help, void (*on_extra_arg)(void* user_data, const char* arg), void* user_data); -extern gpr_cmdline_on_extra_arg_type gpr_cmdline_on_extra_arg_import; -#define gpr_cmdline_on_extra_arg gpr_cmdline_on_extra_arg_import -typedef void(*gpr_cmdline_set_survive_failure_type)(gpr_cmdline* cl); -extern gpr_cmdline_set_survive_failure_type gpr_cmdline_set_survive_failure_import; -#define gpr_cmdline_set_survive_failure gpr_cmdline_set_survive_failure_import -typedef int(*gpr_cmdline_parse_type)(gpr_cmdline* cl, int argc, char** argv); -extern gpr_cmdline_parse_type gpr_cmdline_parse_import; -#define gpr_cmdline_parse gpr_cmdline_parse_import -typedef void(*gpr_cmdline_destroy_type)(gpr_cmdline* cl); -extern gpr_cmdline_destroy_type gpr_cmdline_destroy_import; -#define gpr_cmdline_destroy gpr_cmdline_destroy_import -typedef char*(*gpr_cmdline_usage_string_type)(gpr_cmdline* cl, const char* argv0); -extern gpr_cmdline_usage_string_type gpr_cmdline_usage_string_import; -#define gpr_cmdline_usage_string gpr_cmdline_usage_string_import typedef unsigned(*gpr_cpu_num_cores_type)(void); extern gpr_cpu_num_cores_type gpr_cpu_num_cores_import; #define gpr_cpu_num_cores gpr_cpu_num_cores_import typedef unsigned(*gpr_cpu_current_cpu_type)(void); extern gpr_cpu_current_cpu_type gpr_cpu_current_cpu_import; #define gpr_cpu_current_cpu gpr_cpu_current_cpu_import -typedef int(*gpr_join_host_port_type)(char** out, const char* host, int port); -extern gpr_join_host_port_type gpr_join_host_port_import; -#define gpr_join_host_port gpr_join_host_port_import -typedef int(*gpr_split_host_port_type)(const char* name, char** host, char** port); -extern gpr_split_host_port_type gpr_split_host_port_import; -#define gpr_split_host_port gpr_split_host_port_import typedef const char*(*gpr_log_severity_string_type)(gpr_log_severity severity); extern gpr_log_severity_string_type gpr_log_severity_string_import; #define gpr_log_severity_string gpr_log_severity_string_import @@ -681,21 +620,6 @@ extern gpr_strdup_type gpr_strdup_import; typedef int(*gpr_asprintf_type)(char** strp, const char* format, ...) GPR_PRINT_FORMAT_CHECK(2, 3); extern gpr_asprintf_type gpr_asprintf_import; #define gpr_asprintf gpr_asprintf_import -typedef const char*(*gpr_subprocess_binary_extension_type)(); -extern gpr_subprocess_binary_extension_type gpr_subprocess_binary_extension_import; -#define gpr_subprocess_binary_extension gpr_subprocess_binary_extension_import -typedef gpr_subprocess*(*gpr_subprocess_create_type)(int argc, const char** argv); -extern gpr_subprocess_create_type gpr_subprocess_create_import; -#define gpr_subprocess_create gpr_subprocess_create_import -typedef void(*gpr_subprocess_destroy_type)(gpr_subprocess* p); -extern gpr_subprocess_destroy_type gpr_subprocess_destroy_import; -#define gpr_subprocess_destroy gpr_subprocess_destroy_import -typedef int(*gpr_subprocess_join_type)(gpr_subprocess* p); -extern gpr_subprocess_join_type gpr_subprocess_join_import; -#define gpr_subprocess_join gpr_subprocess_join_import -typedef void(*gpr_subprocess_interrupt_type)(gpr_subprocess* p); -extern gpr_subprocess_interrupt_type gpr_subprocess_interrupt_import; -#define gpr_subprocess_interrupt gpr_subprocess_interrupt_import typedef void(*gpr_mu_init_type)(gpr_mu* mu); extern gpr_mu_init_type gpr_mu_init_import; #define gpr_mu_init gpr_mu_init_import @@ -768,30 +692,9 @@ extern gpr_stats_inc_type gpr_stats_inc_import; typedef intptr_t(*gpr_stats_read_type)(const gpr_stats_counter* c); extern gpr_stats_read_type gpr_stats_read_import; #define gpr_stats_read gpr_stats_read_import -typedef int(*gpr_thd_new_type)(gpr_thd_id* t, void (*thd_body)(void* arg), void* arg, const gpr_thd_options* options); -extern gpr_thd_new_type gpr_thd_new_import; -#define gpr_thd_new gpr_thd_new_import -typedef gpr_thd_options(*gpr_thd_options_default_type)(void); -extern gpr_thd_options_default_type gpr_thd_options_default_import; -#define gpr_thd_options_default gpr_thd_options_default_import -typedef void(*gpr_thd_options_set_detached_type)(gpr_thd_options* options); -extern gpr_thd_options_set_detached_type gpr_thd_options_set_detached_import; -#define gpr_thd_options_set_detached gpr_thd_options_set_detached_import -typedef void(*gpr_thd_options_set_joinable_type)(gpr_thd_options* options); -extern gpr_thd_options_set_joinable_type gpr_thd_options_set_joinable_import; -#define gpr_thd_options_set_joinable gpr_thd_options_set_joinable_import -typedef int(*gpr_thd_options_is_detached_type)(const gpr_thd_options* options); -extern gpr_thd_options_is_detached_type gpr_thd_options_is_detached_import; -#define gpr_thd_options_is_detached gpr_thd_options_is_detached_import -typedef int(*gpr_thd_options_is_joinable_type)(const gpr_thd_options* options); -extern gpr_thd_options_is_joinable_type gpr_thd_options_is_joinable_import; -#define gpr_thd_options_is_joinable gpr_thd_options_is_joinable_import typedef gpr_thd_id(*gpr_thd_currentid_type)(void); extern gpr_thd_currentid_type gpr_thd_currentid_import; #define gpr_thd_currentid gpr_thd_currentid_import -typedef void(*gpr_thd_join_type)(gpr_thd_id t); -extern gpr_thd_join_type gpr_thd_join_import; -#define gpr_thd_join gpr_thd_join_import typedef gpr_timespec(*gpr_time_0_type)(gpr_clock_type type); extern gpr_time_0_type gpr_time_0_import; #define gpr_time_0 gpr_time_0_import diff --git a/src/ruby/ext/grpc/rb_server.c b/src/ruby/ext/grpc/rb_server.c index 160c1533ba..88e6a0cfd5 100644 --- a/src/ruby/ext/grpc/rb_server.c +++ b/src/ruby/ext/grpc/rb_server.c @@ -46,21 +46,38 @@ typedef struct grpc_rb_server { /* The actual server */ grpc_server* wrapped; grpc_completion_queue* queue; - gpr_atm shutdown_started; + int shutdown_and_notify_done; + int destroy_done; } grpc_rb_server; -static void destroy_server(grpc_rb_server* server, gpr_timespec deadline) { +static void grpc_rb_server_maybe_shutdown_and_notify(grpc_rb_server* server, + gpr_timespec deadline) { grpc_event ev; - // This can be started by app or implicitly by GC. Avoid a race between these. - if (gpr_atm_full_fetch_add(&server->shutdown_started, (gpr_atm)1) == 0) { + void* tag = &ev; + if (!server->shutdown_and_notify_done) { + server->shutdown_and_notify_done = 1; if (server->wrapped != NULL) { - grpc_server_shutdown_and_notify(server->wrapped, server->queue, NULL); - ev = rb_completion_queue_pluck(server->queue, NULL, deadline, NULL); + grpc_server_shutdown_and_notify(server->wrapped, server->queue, tag); + ev = rb_completion_queue_pluck(server->queue, tag, deadline, NULL); if (ev.type == GRPC_QUEUE_TIMEOUT) { grpc_server_cancel_all_calls(server->wrapped); - rb_completion_queue_pluck(server->queue, NULL, - gpr_inf_future(GPR_CLOCK_REALTIME), NULL); + ev = rb_completion_queue_pluck( + server->queue, tag, gpr_inf_future(GPR_CLOCK_REALTIME), NULL); + } + if (ev.type != GRPC_OP_COMPLETE) { + gpr_log(GPR_INFO, + "GRPC_RUBY: bad grpc_server_shutdown_and_notify result:%d", + ev.type); } + } + } +} + +static void grpc_rb_server_maybe_destroy(grpc_rb_server* server) { + // This can be started by app or implicitly by GC. Avoid a race between these. + if (!server->destroy_done) { + server->destroy_done = 1; + if (server->wrapped != NULL) { grpc_server_destroy(server->wrapped); grpc_rb_completion_queue_destroy(server->queue); server->wrapped = NULL; @@ -81,7 +98,8 @@ static void grpc_rb_server_free(void* p) { deadline = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(2, GPR_TIMESPAN)); - destroy_server(svr, deadline); + grpc_rb_server_maybe_shutdown_and_notify(svr, deadline); + grpc_rb_server_maybe_destroy(svr); xfree(p); } @@ -107,7 +125,8 @@ static const rb_data_type_t grpc_rb_server_data_type = { static VALUE grpc_rb_server_alloc(VALUE cls) { grpc_rb_server* wrapper = ALLOC(grpc_rb_server); wrapper->wrapped = NULL; - wrapper->shutdown_started = (gpr_atm)0; + wrapper->destroy_done = 0; + wrapper->shutdown_and_notify_done = 0; return TypedData_Wrap_Struct(cls, &grpc_rb_server_data_type, wrapper); } @@ -232,25 +251,10 @@ static VALUE grpc_rb_server_start(VALUE self) { return Qnil; } -/* - call-seq: - server = Server.new({'arg1': 'value1'}) - ... // do stuff with server - ... - ... // to shutdown the server - server.destroy() - - ... // to shutdown the server with a timeout - server.destroy(timeout) - - Destroys server instances. */ -static VALUE grpc_rb_server_destroy(int argc, VALUE* argv, VALUE self) { - VALUE timeout = Qnil; +static VALUE grpc_rb_server_shutdown_and_notify(VALUE self, VALUE timeout) { gpr_timespec deadline; grpc_rb_server* s = NULL; - /* "01" == 0 mandatory args, 1 (timeout) is optional */ - rb_scan_args(argc, argv, "01", &timeout); TypedData_Get_Struct(self, grpc_rb_server, &grpc_rb_server_data_type, s); if (TYPE(timeout) == T_NIL) { deadline = gpr_inf_future(GPR_CLOCK_REALTIME); @@ -258,8 +262,26 @@ static VALUE grpc_rb_server_destroy(int argc, VALUE* argv, VALUE self) { deadline = grpc_rb_time_timeval(timeout, /* absolute time*/ 0); } - destroy_server(s, deadline); + grpc_rb_server_maybe_shutdown_and_notify(s, deadline); + + return Qnil; +} + +/* + call-seq: + server = Server.new({'arg1': 'value1'}) + ... // do stuff with server + ... + ... // initiate server shutdown + server.shutdown_and_notify(timeout) + ... // to shutdown the server + server.destroy() + Destroys server instances. */ +static VALUE grpc_rb_server_destroy(VALUE self) { + grpc_rb_server* s = NULL; + TypedData_Get_Struct(self, grpc_rb_server, &grpc_rb_server_data_type, s); + grpc_rb_server_maybe_destroy(s); return Qnil; } @@ -326,7 +348,9 @@ void Init_grpc_server() { rb_define_method(grpc_rb_cServer, "request_call", grpc_rb_server_request_call, 0); rb_define_method(grpc_rb_cServer, "start", grpc_rb_server_start, 0); - rb_define_method(grpc_rb_cServer, "destroy", grpc_rb_server_destroy, -1); + rb_define_method(grpc_rb_cServer, "shutdown_and_notify", + grpc_rb_server_shutdown_and_notify, 1); + rb_define_method(grpc_rb_cServer, "destroy", grpc_rb_server_destroy, 0); rb_define_alias(grpc_rb_cServer, "close", "destroy"); rb_define_method(grpc_rb_cServer, "add_http2_port", grpc_rb_server_add_http2_port, 2); diff --git a/src/ruby/lib/grpc/core/time_consts.rb b/src/ruby/lib/grpc/core/time_consts.rb index 92cd323fa8..896b720780 100644 --- a/src/ruby/lib/grpc/core/time_consts.rb +++ b/src/ruby/lib/grpc/core/time_consts.rb @@ -32,7 +32,7 @@ module GRPC # * timish == 0 => TimeConsts.ZERO # # @param timeish [Number|TimeSpec] - # @return timeish [Number|TimeSpec] + # @return [Number|TimeSpec] def from_relative_time(timeish) if timeish.is_a? TimeSpec timeish diff --git a/src/ruby/lib/grpc/generic/bidi_call.rb b/src/ruby/lib/grpc/generic/bidi_call.rb index 3bdcc0062e..086455db0b 100644 --- a/src/ruby/lib/grpc/generic/bidi_call.rb +++ b/src/ruby/lib/grpc/generic/bidi_call.rb @@ -64,7 +64,7 @@ module GRPC # @param requests the Enumerable of requests to send # @param set_input_stream_done [Proc] called back when we're done # reading the input stream - # @param set_input_stream_done [Proc] called back when we're done + # @param set_output_stream_done [Proc] called back when we're done # sending data on the output stream # @return an Enumerator of requests to yield def run_on_client(requests, diff --git a/src/ruby/lib/grpc/generic/client_stub.rb b/src/ruby/lib/grpc/generic/client_stub.rb index 9a50f8a99d..b193f5c4e1 100644 --- a/src/ruby/lib/grpc/generic/client_stub.rb +++ b/src/ruby/lib/grpc/generic/client_stub.rb @@ -58,8 +58,8 @@ module GRPC # Minimally, a stub is created with the just the host of the gRPC service # it wishes to access, e.g., # - # my_stub = ClientStub.new(example.host.com:50505, - # :this_channel_is_insecure) + # my_stub = ClientStub.new(example.host.com:50505, + # :this_channel_is_insecure) # # If a channel_override argument is passed, it will be used as the # underlying channel. Otherwise, the channel_args argument will be used @@ -376,7 +376,7 @@ module GRPC # This is a blocking call. # # * the call completes when the next call to provided block returns - # * [False] + # false # # * the execution block parameters are two objects for sending and # receiving responses, each of which blocks waiting for flow control. @@ -398,13 +398,9 @@ module GRPC # responses by throwing StopIteration, but can only happen either # if bidi_call#writes_done is called. # - # To terminate the RPC correctly the block: - # - # * must call bidi#writes_done and then - # - # * either return false as soon as there is no need for other responses - # - # * loop on responses#next until no further responses are available + # To properly terminate the RPC, the responses should be completely iterated + # through; one way to do this is to loop on responses#next until no further + # responses are available. # # == Errors == # An RuntimeError is raised if diff --git a/src/ruby/lib/grpc/generic/interceptors.rb b/src/ruby/lib/grpc/generic/interceptors.rb index 24482f3451..56d3cecaad 100644 --- a/src/ruby/lib/grpc/generic/interceptors.rb +++ b/src/ruby/lib/grpc/generic/interceptors.rb @@ -153,7 +153,7 @@ module GRPC # class InterceptionContext ## - # @param [Array<GRPC::Interceptor>] + # @param interceptors [Array<GRPC::Interceptor>] # def initialize(interceptors = []) @interceptors = interceptors.dup diff --git a/src/ruby/lib/grpc/generic/rpc_server.rb b/src/ruby/lib/grpc/generic/rpc_server.rb index c80c7fcd32..31ab6a302b 100644 --- a/src/ruby/lib/grpc/generic/rpc_server.rb +++ b/src/ruby/lib/grpc/generic/rpc_server.rb @@ -204,7 +204,7 @@ module GRPC # * connect_md_proc: # when non-nil is a proc for determining metadata to to send back the client # on receiving an invocation req. The proc signature is: - # {key: val, ..} func(method_name, {key: val, ...}) + # {key: val, ..} func(method_name, {key: val, ...}) # # * server_args: # A server arguments hash to be passed down to the underlying core server @@ -244,9 +244,9 @@ module GRPC fail 'Cannot stop before starting' if @running_state == :not_started return if @running_state != :running transition_running_state(:stopping) + deadline = from_relative_time(@poll_period) + @server.shutdown_and_notify(deadline) end - deadline = from_relative_time(@poll_period) - @server.close(deadline) @pool.stop end @@ -283,7 +283,7 @@ module GRPC # If run has not been called, this returns immediately. # # @param timeout [Numeric] number of seconds to wait - # @result [true, false] true if the server is running, false otherwise + # @return [true, false] true if the server is running, false otherwise def wait_till_running(timeout = nil) @run_mutex.synchronize do @run_cond.wait(@run_mutex, timeout) if @running_state == :not_started @@ -416,8 +416,11 @@ module GRPC end end # @running_state should be :stopping here - @run_mutex.synchronize { transition_running_state(:stopped) } - GRPC.logger.info("stopped: #{self}") + @run_mutex.synchronize do + transition_running_state(:stopped) + GRPC.logger.info("stopped: #{self}") + @server.close + end end def new_active_server_call(an_rpc) diff --git a/src/ruby/lib/grpc/version.rb b/src/ruby/lib/grpc/version.rb index be1412511a..256a543a9f 100644 --- a/src/ruby/lib/grpc/version.rb +++ b/src/ruby/lib/grpc/version.rb @@ -14,5 +14,5 @@ # GRPC contains the General RPC module. module GRPC - VERSION = '1.9.0.dev' + VERSION = '1.11.0.dev' end diff --git a/src/ruby/pb/test/client.rb b/src/ruby/pb/test/client.rb index a110fec960..63959d9b14 100755 --- a/src/ruby/pb/test/client.rb +++ b/src/ruby/pb/test/client.rb @@ -707,7 +707,7 @@ Args = Struct.new(:default_service_account, :host, :host_override, :oauth_scope, :port, :secure, :test_case, :use_test_ca) -# validates the the command line options, returning them as a Hash. +# validates the command line options, returning them as a Hash. def parse_args args = Args.new args.host_override = 'foo.test.google.fr' diff --git a/src/ruby/pb/test/server.rb b/src/ruby/pb/test/server.rb index f3257d3d2d..1c82ba0b9a 100755 --- a/src/ruby/pb/test/server.rb +++ b/src/ruby/pb/test/server.rb @@ -211,7 +211,7 @@ class TestTarget < Grpc::Testing::TestService::Service end end -# validates the the command line options, returning them as a Hash. +# validates the command line options, returning them as a Hash. def parse_options options = { 'port' => nil, diff --git a/src/ruby/spec/channel_connection_spec.rb b/src/ruby/spec/channel_connection_spec.rb index ce3e3b1c93..5c31f41065 100644 --- a/src/ruby/spec/channel_connection_spec.rb +++ b/src/ruby/spec/channel_connection_spec.rb @@ -16,9 +16,10 @@ require 'timeout' include Timeout include GRPC::Core +include GRPC::Spec::Helpers def start_server(port = 0) - @srv = GRPC::RpcServer.new(pool_size: 1) + @srv = new_rpc_server_for_testing(pool_size: 1) server_port = @srv.add_http2_port("localhost:#{port}", :this_port_is_insecure) @srv.handle(EchoService) @server_thd = Thread.new { @srv.run } diff --git a/src/ruby/spec/client_auth_spec.rb b/src/ruby/spec/client_auth_spec.rb index 79c9192aa5..b955ad231e 100644 --- a/src/ruby/spec/client_auth_spec.rb +++ b/src/ruby/spec/client_auth_spec.rb @@ -95,7 +95,7 @@ describe 'client-server auth' do server_opts = { poll_period: 1 } - @srv = RpcServer.new(**server_opts) + @srv = new_rpc_server_for_testing(**server_opts) port = @srv.add_http2_port('0.0.0.0:0', create_server_creds) @srv.handle(SslTestService) @srv_thd = Thread.new { @srv.run } diff --git a/src/ruby/spec/client_server_spec.rb b/src/ruby/spec/client_server_spec.rb index adab8c9d14..afbfb0bc43 100644 --- a/src/ruby/spec/client_server_spec.rb +++ b/src/ruby/spec/client_server_spec.rb @@ -542,7 +542,7 @@ end describe 'the http client/server' do before(:example) do server_host = '0.0.0.0:0' - @server = GRPC::Core::Server.new(nil) + @server = new_core_server_for_testing(nil) server_port = @server.add_http2_port(server_host, :this_port_is_insecure) @server.start @ch = Channel.new("0.0.0.0:#{server_port}", nil, :this_channel_is_insecure) @@ -550,7 +550,8 @@ describe 'the http client/server' do after(:example) do @ch.close - @server.close(deadline) + @server.shutdown_and_notify(deadline) + @server.close end it_behaves_like 'basic GRPC message delivery is OK' do @@ -574,7 +575,7 @@ describe 'the secure http client/server' do server_host = '0.0.0.0:0' server_creds = GRPC::Core::ServerCredentials.new( nil, [{ private_key: certs[1], cert_chain: certs[2] }], false) - @server = GRPC::Core::Server.new(nil) + @server = new_core_server_for_testing(nil) server_port = @server.add_http2_port(server_host, server_creds) @server.start args = { Channel::SSL_TARGET => 'foo.test.google.fr' } @@ -583,7 +584,8 @@ describe 'the secure http client/server' do end after(:example) do - @server.close(deadline) + @server.shutdown_and_notify(deadline) + @server.close end it_behaves_like 'basic GRPC message delivery is OK' do diff --git a/src/ruby/spec/generic/active_call_spec.rb b/src/ruby/spec/generic/active_call_spec.rb index 120acc35af..6b44b22acf 100644 --- a/src/ruby/spec/generic/active_call_spec.rb +++ b/src/ruby/spec/generic/active_call_spec.rb @@ -40,7 +40,7 @@ describe GRPC::ActiveCall do before(:each) do @pass_through = proc { |x| x } host = '0.0.0.0:0' - @server = GRPC::Core::Server.new(nil) + @server = new_core_server_for_testing(nil) server_port = @server.add_http2_port(host, :this_port_is_insecure) @server.start @ch = GRPC::Core::Channel.new("0.0.0.0:#{server_port}", nil, @@ -48,7 +48,8 @@ describe GRPC::ActiveCall do end after(:each) do - @server.close(deadline) + @server.shutdown_and_notify(deadline) + @server.close end describe 'restricted view methods' do diff --git a/src/ruby/spec/generic/client_stub_spec.rb b/src/ruby/spec/generic/client_stub_spec.rb index 9539e56c0f..d858c4e3fe 100644 --- a/src/ruby/spec/generic/client_stub_spec.rb +++ b/src/ruby/spec/generic/client_stub_spec.rb @@ -83,7 +83,12 @@ def sanity_check_values_of_accessors(op_view, op_view.deadline.is_a?(Time)).to be(true) end -describe 'ClientStub' do +def close_active_server_call(active_server_call) + active_server_call.send(:set_input_stream_done) + active_server_call.send(:set_output_stream_done) +end + +describe 'ClientStub' do # rubocop:disable Metrics/BlockLength let(:noop) { proc { |x| x } } before(:each) do @@ -96,7 +101,10 @@ describe 'ClientStub' do end after(:each) do - @server.close(from_relative_time(2)) unless @server.nil? + unless @server.nil? + @server.shutdown_and_notify(from_relative_time(2)) + @server.close + end end describe '#new' do @@ -228,9 +236,17 @@ describe 'ClientStub' do th.join end - it 'should receive UNAUTHENTICATED if call credentials plugin fails' do + it 'should receive UNAVAILABLE if call credentials plugin fails' do server_port = create_secure_test_server - th = run_request_response(@sent_msg, @resp, @pass) + server_started_notifier = GRPC::Notifier.new + th = Thread.new do + @server.start + server_started_notifier.notify(nil) + # Poll on the server so that the client connection can proceed. + # We don't expect the server to actually accept a call though. + expect { @server.request_call }.to raise_error(GRPC::Core::CallError) + end + server_started_notifier.wait certs = load_test_certs secure_channel_creds = GRPC::Core::ChannelCredentials.new( @@ -249,17 +265,18 @@ describe 'ClientStub' do end creds = GRPC::Core::CallCredentials.new(failing_auth) - unauth_error_occured = false + unavailable_error_occured = false begin get_response(stub, credentials: creds) - rescue GRPC::Unauthenticated => e - unauth_error_occured = true + rescue GRPC::Unavailable => e + unavailable_error_occured = true expect(e.details.include?(error_message)).to be true end - expect(unauth_error_occured).to eq(true) + expect(unavailable_error_occured).to eq(true) - # Kill the server thread so tests can complete - th.kill + @server.shutdown_and_notify(Time.now + 3) + th.join + @server.close end it 'should raise ArgumentError if metadata contains invalid values' do @@ -493,6 +510,7 @@ describe 'ClientStub' do p 'remote_send failed (allowed because call expected to cancel)' ensure c.send_status(OK, 'OK', true) + close_active_server_call(c) end end end @@ -659,6 +677,7 @@ describe 'ClientStub' do end # can't fail since initial metadata already sent server_call.send_status(@pass, 'OK', true) + close_active_server_call(server_call) end def verify_error_from_write_thread(stub, requests_to_push, @@ -809,6 +828,7 @@ describe 'ClientStub' do replys.each { |r| c.remote_send(r) } c.send_status(status, status == @pass ? 'OK' : 'NOK', true, metadata: server_trailing_md) + close_active_server_call(c) end end @@ -819,6 +839,7 @@ describe 'ClientStub' do expected_inputs.each { |i| expect(c.remote_read).to eq(i) } replys.each { |r| c.remote_send(r) } c.send_status(status, status == @pass ? 'OK' : 'NOK', true) + close_active_server_call(c) end end @@ -844,6 +865,7 @@ describe 'ClientStub' do end c.send_status(status, status == @pass ? 'OK' : 'NOK', true, metadata: server_trailing_md) + close_active_server_call(c) end end @@ -862,6 +884,7 @@ describe 'ClientStub' do c.remote_send(resp) c.send_status(status, status == @pass ? 'OK' : 'NOK', true, metadata: server_trailing_md) + close_active_server_call(c) end end @@ -880,6 +903,7 @@ describe 'ClientStub' do c.remote_send(resp) c.send_status(status, status == @pass ? 'OK' : 'NOK', true, metadata: server_trailing_md) + close_active_server_call(c) end end @@ -888,12 +912,12 @@ describe 'ClientStub' do secure_credentials = GRPC::Core::ServerCredentials.new( nil, [{ private_key: certs[1], cert_chain: certs[2] }], false) - @server = GRPC::Core::Server.new(nil) + @server = new_core_server_for_testing(nil) @server.add_http2_port('0.0.0.0:0', secure_credentials) end def create_test_server - @server = GRPC::Core::Server.new(nil) + @server = new_core_server_for_testing(nil) @server.add_http2_port('0.0.0.0:0', :this_port_is_insecure) end diff --git a/src/ruby/spec/generic/interceptor_registry_spec.rb b/src/ruby/spec/generic/interceptor_registry_spec.rb index f93f5cec09..eb75d1e0b2 100644 --- a/src/ruby/spec/generic/interceptor_registry_spec.rb +++ b/src/ruby/spec/generic/interceptor_registry_spec.rb @@ -14,7 +14,7 @@ require 'spec_helper' describe GRPC::InterceptorRegistry do - let(:server) { RpcServer.new } + let(:server) { new_rpc_server_for_testing } let(:interceptor) { TestServerInterceptor.new } let(:interceptors) { [interceptor] } let(:registry) { described_class.new(interceptors) } diff --git a/src/ruby/spec/generic/rpc_server_spec.rb b/src/ruby/spec/generic/rpc_server_spec.rb index 05059fbecf..e072d0c45f 100644 --- a/src/ruby/spec/generic/rpc_server_spec.rb +++ b/src/ruby/spec/generic/rpc_server_spec.rb @@ -172,7 +172,7 @@ describe GRPC::RpcServer do it 'can be created with just some args' do opts = { server_args: { a_channel_arg: 'an_arg' } } blk = proc do - RpcServer.new(**opts) + new_rpc_server_for_testing(**opts) end expect(&blk).not_to raise_error end @@ -183,7 +183,7 @@ describe GRPC::RpcServer do server_args: { a_channel_arg: 'an_arg' }, creds: Object.new } - RpcServer.new(**opts) + new_rpc_server_for_testing(**opts) end expect(&blk).to raise_error end @@ -192,7 +192,7 @@ describe GRPC::RpcServer do describe '#stopped?' do before(:each) do opts = { server_args: { a_channel_arg: 'an_arg' }, poll_period: 1.5 } - @srv = RpcServer.new(**opts) + @srv = new_rpc_server_for_testing(**opts) @srv.add_http2_port('0.0.0.0:0', :this_port_is_insecure) end @@ -224,7 +224,7 @@ describe GRPC::RpcServer do opts = { server_args: { a_channel_arg: 'an_arg' } } - r = RpcServer.new(**opts) + r = new_rpc_server_for_testing(**opts) expect(r.running?).to be(false) end @@ -233,7 +233,7 @@ describe GRPC::RpcServer do server_args: { a_channel_arg: 'an_arg' }, poll_period: 2 } - r = RpcServer.new(**opts) + r = new_rpc_server_for_testing(**opts) r.add_http2_port('0.0.0.0:0', :this_port_is_insecure) expect { r.run }.to raise_error(RuntimeError) end @@ -243,7 +243,7 @@ describe GRPC::RpcServer do server_args: { a_channel_arg: 'an_arg' }, poll_period: 2.5 } - r = RpcServer.new(**opts) + r = new_rpc_server_for_testing(**opts) r.add_http2_port('0.0.0.0:0', :this_port_is_insecure) r.handle(EchoService) t = Thread.new { r.run } @@ -257,7 +257,7 @@ describe GRPC::RpcServer do describe '#handle' do before(:each) do @opts = { server_args: { a_channel_arg: 'an_arg' }, poll_period: 1 } - @srv = RpcServer.new(**@opts) + @srv = new_rpc_server_for_testing(**@opts) @srv.add_http2_port('0.0.0.0:0', :this_port_is_insecure) end @@ -303,7 +303,7 @@ describe GRPC::RpcServer do server_opts = { poll_period: 1 } - @srv = RpcServer.new(**server_opts) + @srv = new_rpc_server_for_testing(**server_opts) server_port = @srv.add_http2_port('0.0.0.0:0', :this_port_is_insecure) @host = "localhost:#{server_port}" @ch = GRPC::Core::Channel.new(@host, nil, :this_channel_is_insecure) @@ -474,7 +474,7 @@ describe GRPC::RpcServer do poll_period: 1, max_waiting_requests: 1 } - alt_srv = RpcServer.new(**opts) + alt_srv = new_rpc_server_for_testing(**opts) alt_srv.handle(SlowService) alt_port = alt_srv.add_http2_port('0.0.0.0:0', :this_port_is_insecure) alt_host = "0.0.0.0:#{alt_port}" @@ -538,7 +538,7 @@ describe GRPC::RpcServer do poll_period: 1, connect_md_proc: test_md_proc } - @srv = RpcServer.new(**server_opts) + @srv = new_rpc_server_for_testing(**server_opts) alt_port = @srv.add_http2_port('0.0.0.0:0', :this_port_is_insecure) @alt_host = "0.0.0.0:#{alt_port}" end @@ -573,7 +573,7 @@ describe GRPC::RpcServer do server_opts = { poll_period: 1 } - @srv = RpcServer.new(**server_opts) + @srv = new_rpc_server_for_testing(**server_opts) alt_port = @srv.add_http2_port('0.0.0.0:0', :this_port_is_insecure) @alt_host = "0.0.0.0:#{alt_port}" end @@ -624,7 +624,7 @@ describe GRPC::RpcServer do server_opts = { poll_period: 1 } - @srv = RpcServer.new(**server_opts) + @srv = new_rpc_server_for_testing(**server_opts) alt_port = @srv.add_http2_port('0.0.0.0:0', :this_port_is_insecure) @alt_host = "0.0.0.0:#{alt_port}" diff --git a/src/ruby/spec/google_rpc_status_utils_spec.rb b/src/ruby/spec/google_rpc_status_utils_spec.rb index 6f2a06b1d9..3263589b6a 100644 --- a/src/ruby/spec/google_rpc_status_utils_spec.rb +++ b/src/ruby/spec/google_rpc_status_utils_spec.rb @@ -19,6 +19,7 @@ require_relative '../pb/src/proto/grpc/testing/messages_pb' require 'google/protobuf/well_known_types' include GRPC::Core +include GRPC::Spec::Helpers describe 'conversion from a status struct to a google protobuf status' do it 'fails if the input is not a status struct' do @@ -150,7 +151,7 @@ GoogleRpcStatusTestStub = GoogleRpcStatusTestService.rpc_stub_class describe 'receving a google rpc status from a remote endpoint' do def start_server(encoded_rpc_status) - @srv = GRPC::RpcServer.new(pool_size: 1) + @srv = new_rpc_server_for_testing(pool_size: 1) @server_port = @srv.add_http2_port('localhost:0', :this_port_is_insecure) @srv.handle(GoogleRpcStatusTestService.new(encoded_rpc_status)) @@ -238,7 +239,7 @@ NoStatusDetailsBinTestServiceStub = NoStatusDetailsBinTestService.rpc_stub_class describe 'when the endpoint doesnt send grpc-status-details-bin' do def start_server - @srv = GRPC::RpcServer.new(pool_size: 1) + @srv = new_rpc_server_for_testing(pool_size: 1) @server_port = @srv.add_http2_port('localhost:0', :this_port_is_insecure) @srv.handle(NoStatusDetailsBinTestService) diff --git a/src/ruby/spec/pb/health/checker_spec.rb b/src/ruby/spec/pb/health/checker_spec.rb index c79ccfd2e0..58a602327c 100644 --- a/src/ruby/spec/pb/health/checker_spec.rb +++ b/src/ruby/spec/pb/health/checker_spec.rb @@ -192,7 +192,7 @@ describe Grpc::Health::Checker do server_opts = { poll_period: 1 } - @srv = RpcServer.new(**server_opts) + @srv = new_rpc_server_for_testing(**server_opts) server_port = @srv.add_http2_port(server_host, :this_port_is_insecure) @host = "localhost:#{server_port}" @ch = GRPC::Core::Channel.new(@host, nil, :this_channel_is_insecure) diff --git a/src/ruby/spec/server_spec.rb b/src/ruby/spec/server_spec.rb index c0a59572b1..6eaac5ded1 100644 --- a/src/ruby/spec/server_spec.rb +++ b/src/ruby/spec/server_spec.rb @@ -30,51 +30,66 @@ describe Server do describe '#start' do it 'runs without failing' do - blk = proc { Server.new(nil).start } + blk = proc { new_core_server_for_testing(nil).start } expect(&blk).to_not raise_error end it 'fails if the server is closed' do - s = Server.new(nil) + s = new_core_server_for_testing(nil) + s.shutdown_and_notify(nil) s.close expect { s.start }.to raise_error(RuntimeError) end end - describe '#destroy' do + describe '#shutdown_and_notify and #destroy' do it 'destroys a server ok' do s = start_a_server - blk = proc { s.destroy } + blk = proc do + s.shutdown_and_notify(nil) + s.destroy + end expect(&blk).to_not raise_error end it 'can be called more than once without error' do s = start_a_server begin - blk = proc { s.destroy } + blk = proc do + s.shutdown_and_notify(nil) + s.destroy + end expect(&blk).to_not raise_error blk.call expect(&blk).to_not raise_error ensure + s.shutdown_and_notify(nil) s.close end end end - describe '#close' do + describe '#shutdown_and_notify and #close' do it 'closes a server ok' do s = start_a_server begin - blk = proc { s.close } + blk = proc do + s.shutdown_and_notify(nil) + s.close + end expect(&blk).to_not raise_error ensure - s.close(@cq) + s.shutdown_and_notify(nil) + s.close end end it 'can be called more than once without error' do s = start_a_server - blk = proc { s.close } + blk = proc do + s.shutdown_and_notify(nil) + s.close + end expect(&blk).to_not raise_error blk.call expect(&blk).to_not raise_error @@ -85,15 +100,17 @@ describe Server do describe 'for insecure servers' do it 'runs without failing' do blk = proc do - s = Server.new(nil) + s = new_core_server_for_testing(nil) s.add_http2_port('localhost:0', :this_port_is_insecure) + s.shutdown_and_notify(nil) s.close end expect(&blk).to_not raise_error end it 'fails if the server is closed' do - s = Server.new(nil) + s = new_core_server_for_testing(nil) + s.shutdown_and_notify(nil) s.close blk = proc do s.add_http2_port('localhost:0', :this_port_is_insecure) @@ -106,15 +123,17 @@ describe Server do let(:cert) { create_test_cert } it 'runs without failing' do blk = proc do - s = Server.new(nil) + s = new_core_server_for_testing(nil) s.add_http2_port('localhost:0', cert) + s.shutdown_and_notify(nil) s.close end expect(&blk).to_not raise_error end it 'fails if the server is closed' do - s = Server.new(nil) + s = new_core_server_for_testing(nil) + s.shutdown_and_notify(nil) s.close blk = proc { s.add_http2_port('localhost:0', cert) } expect(&blk).to raise_error(RuntimeError) @@ -124,7 +143,7 @@ describe Server do shared_examples '#new' do it 'takes nil channel args' do - expect { Server.new(nil) }.to_not raise_error + expect { new_core_server_for_testing(nil) }.to_not raise_error end it 'does not take a hash with bad keys as channel args' do @@ -175,14 +194,14 @@ describe Server do describe '#new with an insecure channel' do def construct_with_args(a) - proc { Server.new(a) } + proc { new_core_server_for_testing(a) } end it_behaves_like '#new' end def start_a_server - s = Server.new(nil) + s = new_core_server_for_testing(nil) s.add_http2_port('0.0.0.0:0', :this_port_is_insecure) s.start s diff --git a/src/ruby/spec/support/helpers.rb b/src/ruby/spec/support/helpers.rb index 65fffff9e7..29028df8b7 100644 --- a/src/ruby/spec/support/helpers.rb +++ b/src/ruby/spec/support/helpers.rb @@ -31,7 +31,7 @@ module GRPC # def build_rpc_server(server_opts: {}, client_opts: {}) - @server = RpcServer.new({ poll_period: 1 }.merge(server_opts)) + @server = new_rpc_server_for_testing({ poll_period: 1 }.merge(server_opts)) @port = @server.add_http2_port('0.0.0.0:0', :this_port_is_insecure) @host = "0.0.0.0:#{@port}" @client_opts = client_opts @@ -68,6 +68,40 @@ module GRPC opts ||= @client_opts klass.new(host, :this_channel_is_insecure, **opts) end + + ## + # Build an RPCServer for use in tests. Adds args + # that are useful for all tests. + # + # @param [Hash] server_opts + # + def new_rpc_server_for_testing(server_opts = {}) + server_opts[:server_args] ||= {} + update_server_args_hash(server_opts[:server_args]) + RpcServer.new(**server_opts) + end + + ## + # Build an GRPC::Core::Server for use in tests. Adds args + # that are useful for all tests. + # + # @param [Hash] server_args + # + def new_core_server_for_testing(server_args) + server_args.nil? && server_args = {} + update_server_args_hash(server_args) + GRPC::Core::Server.new(server_args) + end + + def update_server_args_hash(server_args) + so_reuseport_arg = 'grpc.so_reuseport' + unless server_args[so_reuseport_arg].nil? + fail 'Unexpected. grpc.so_reuseport already set.' + end + # Run tests without so_reuseport to eliminate the chance of + # cross-talk. + server_args[so_reuseport_arg] = 0 + end end end end diff --git a/src/ruby/tools/version.rb b/src/ruby/tools/version.rb index 48aad39e08..8dc1623d6f 100644 --- a/src/ruby/tools/version.rb +++ b/src/ruby/tools/version.rb @@ -14,6 +14,6 @@ module GRPC module Tools - VERSION = '1.9.0.dev' + VERSION = '1.11.0.dev' end end |