diff options
Diffstat (limited to 'src/ruby')
47 files changed, 419 insertions, 775 deletions
diff --git a/src/ruby/bin/apis/google/protobuf/empty.rb b/src/ruby/bin/apis/google/protobuf/empty.rb deleted file mode 100644 index 4743bded3d..0000000000 --- a/src/ruby/bin/apis/google/protobuf/empty.rb +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2015 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. - -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: google/protobuf/empty.proto - -require 'google/protobuf' - -Google::Protobuf::DescriptorPool.generated_pool.build do - add_message "google.protobuf.Empty" do - end -end - -module Google - module Protobuf - Empty = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Empty").msgclass - end -end diff --git a/src/ruby/bin/apis/pubsub_demo.rb b/src/ruby/bin/apis/pubsub_demo.rb deleted file mode 100755 index c565771d45..0000000000 --- a/src/ruby/bin/apis/pubsub_demo.rb +++ /dev/null @@ -1,241 +0,0 @@ -#!/usr/bin/env ruby - -# Copyright 2015 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. - -# pubsub_demo demos accesses the Google PubSub API via its gRPC interface -# -# $ GOOGLE_APPLICATION_CREDENTIALS=<path_to_service_account_key_file> \ -# path/to/pubsub_demo.rb \ -# [--action=<chosen_demo_action> ] -# -# There are options related to the chosen action, see #parse_args below. -# - the possible actions are given by the method names of NamedAction class -# - the default action is list_some_topics - -this_dir = File.expand_path(File.dirname(__FILE__)) -lib_dir = File.join(File.dirname(File.dirname(this_dir)), 'lib') -$LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir) -$LOAD_PATH.unshift(this_dir) unless $LOAD_PATH.include?(this_dir) - -require 'optparse' - -require 'grpc' -require 'googleauth' -require 'google/protobuf' - -require 'google/protobuf/empty' -require 'tech/pubsub/proto/pubsub' -require 'tech/pubsub/proto/pubsub_services' - -# creates a SSL Credentials from the production certificates. -def ssl_creds - GRPC::Core::ChannelCredentials.new() -end - -# Builds the metadata authentication update proc. -def auth_proc(opts) - auth_creds = Google::Auth.get_application_default - return auth_creds.updater_proc -end - -# Creates a stub for accessing the publisher service. -def publisher_stub(opts) - address = "#{opts.host}:#{opts.port}" - stub_clz = Tech::Pubsub::PublisherService::Stub # shorter - GRPC.logger.info("... access PublisherService at #{address}") - call_creds = GRPC::Core::CallCredentials.new(auth_proc(opts)) - combined_creds = ssl_creds.compose(call_creds) - stub_clz.new(address, creds: combined_creds, - GRPC::Core::Channel::SSL_TARGET => opts.host) -end - -# Creates a stub for accessing the subscriber service. -def subscriber_stub(opts) - address = "#{opts.host}:#{opts.port}" - stub_clz = Tech::Pubsub::SubscriberService::Stub # shorter - GRPC.logger.info("... access SubscriberService at #{address}") - call_creds = GRPC::Core::CallCredentials.new(auth_proc(opts)) - combined_creds = ssl_creds.compose(call_creds) - stub_clz.new(address, creds: combined_creds, - GRPC::Core::Channel::SSL_TARGET => opts.host) -end - -# defines methods corresponding to each interop test case. -class NamedActions - include Tech::Pubsub - - # Initializes NamedActions - # - # @param pub [Stub] a stub for accessing the publisher service - # @param sub [Stub] a stub for accessing the publisher service - # @param args [Args] provides access to the command line - def initialize(pub, sub, args) - @pub = pub - @sub = sub - @args = args - end - - # Removes the test topic if it exists - def remove_topic - name = test_topic_name - p "... removing Topic #{name}" - @pub.delete_topic(DeleteTopicRequest.new(topic: name)) - p "removed Topic: #{name} OK" - rescue GRPC::BadStatus => e - p "Could not delete a topics: rpc failed with '#{e}'" - end - - # Creates a test topic - def create_topic - name = test_topic_name - p "... creating Topic #{name}" - resp = @pub.create_topic(Topic.new(name: name)) - p "created Topic: #{resp.name} OK" - rescue GRPC::BadStatus => e - p "Could not create a topics: rpc failed with '#{e}'" - end - - # Lists topics in the project - def list_some_topics - p 'Listing topics' - p '-------------_' - list_project_topics.topic.each { |t| p t.name } - rescue GRPC::BadStatus => e - p "Could not list topics: rpc failed with '#{e}'" - end - - # Checks if a topics exists in a project - def check_exists - name = test_topic_name - p "... checking for topic #{name}" - exists = topic_exists?(name) - p "#{name} is a topic" if exists - p "#{name} is not a topic" unless exists - rescue GRPC::BadStatus => e - p "Could not check for a topics: rpc failed with '#{e}'" - end - - # Publishes some messages - def random_pub_sub - topic_name, sub_name = test_topic_name, test_sub_name - create_topic_if_needed(topic_name) - @sub.create_subscription(Subscription.new(name: sub_name, - topic: topic_name)) - msg_count = rand(10..30) - msg_count.times do |x| - msg = PubsubMessage.new(data: "message #{x}") - @pub.publish(PublishRequest.new(topic: topic_name, message: msg)) - end - p "Sent #{msg_count} messages to #{topic_name}, checking for them now." - batch = @sub.pull_batch(PullBatchRequest.new(subscription: sub_name, - max_events: msg_count)) - ack_ids = batch.pull_responses.map { |x| x.ack_id } - p "Got #{ack_ids.size} messages; acknowledging them.." - @sub.acknowledge(AcknowledgeRequest.new(subscription: sub_name, - ack_id: ack_ids)) - p "Test messages were acknowledged OK, deleting the subscription" - del_req = DeleteSubscriptionRequest.new(subscription: sub_name) - @sub.delete_subscription(del_req) - rescue GRPC::BadStatus => e - p "Could not do random pub sub: rpc failed with '#{e}'" - end - - private - - # test_topic_name is the topic name to use in this test. - def test_topic_name - unless @args.topic_name.nil? - return "/topics/#{@args.project_id}/#{@args.topic_name}" - end - now_text = Time.now.utc.strftime('%Y%m%d%H%M%S%L') - "/topics/#{@args.project_id}/#{ENV['USER']}-#{now_text}" - end - - # test_sub_name is the subscription name to use in this test. - def test_sub_name - unless @args.sub_name.nil? - return "/subscriptions/#{@args.project_id}/#{@args.sub_name}" - end - now_text = Time.now.utc.strftime('%Y%m%d%H%M%S%L') - "/subscriptions/#{@args.project_id}/#{ENV['USER']}-#{now_text}" - end - - # determines if the topic name exists - def topic_exists?(name) - topics = list_project_topics.topic.map { |t| t.name } - topics.include?(name) - end - - def create_topic_if_needed(name) - return if topic_exists?(name) - @pub.create_topic(Topic.new(name: name)) - end - - def list_project_topics - q = "cloud.googleapis.com/project in (/projects/#{@args.project_id})" - @pub.list_topics(ListTopicsRequest.new(query: q)) - end -end - -# Args is used to hold the command line info. -Args = Struct.new(:host, :port, :action, :project_id, :topic_name, - :sub_name) - -# 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') - OptionParser.new do |opts| - opts.on('--server_host SERVER_HOST', 'server hostname') do |v| - args.host = v - end - opts.on('--server_port SERVER_PORT', 'server port') do |v| - args.port = v - end - - # instance_methods(false) gives only the methods defined in that class. - scenes = NamedActions.instance_methods(false).map { |t| t.to_s } - scene_list = scenes.join(',') - opts.on("--action CODE", scenes, {}, 'pick a demo action', - " (#{scene_list})") do |v| - args.action = v - end - - # Set the remaining values. - %w(project_id topic_name sub_name).each do |o| - opts.on("--#{o} VALUE", "#{o}") do |v| - args[o] = v - end - end - end.parse! - _check_args(args) -end - -def _check_args(args) - %w(host port action).each do |a| - if args[a].nil? - raise OptionParser::MissingArgument.new("please specify --#{a}") - end - end - args -end - -def main - args = parse_args - pub, sub = publisher_stub(args), subscriber_stub(args) - NamedActions.new(pub, sub, args).method(args.action).call -end - -main diff --git a/src/ruby/bin/apis/tech/pubsub/proto/pubsub.rb b/src/ruby/bin/apis/tech/pubsub/proto/pubsub.rb deleted file mode 100644 index 73a0d5d9e4..0000000000 --- a/src/ruby/bin/apis/tech/pubsub/proto/pubsub.rb +++ /dev/null @@ -1,159 +0,0 @@ -# Copyright 2015 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. - -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: tech/pubsub/proto/pubsub.proto - -require 'google/protobuf' - -require 'google/protobuf/empty' -Google::Protobuf::DescriptorPool.generated_pool.build do - add_message "tech.pubsub.Topic" do - optional :name, :string, 1 - end - add_message "tech.pubsub.PubsubMessage" do - optional :data, :string, 1 - optional :message_id, :string, 3 - end - add_message "tech.pubsub.GetTopicRequest" do - optional :topic, :string, 1 - end - add_message "tech.pubsub.PublishRequest" do - optional :topic, :string, 1 - optional :message, :message, 2, "tech.pubsub.PubsubMessage" - end - add_message "tech.pubsub.PublishBatchRequest" do - optional :topic, :string, 1 - repeated :messages, :message, 2, "tech.pubsub.PubsubMessage" - end - add_message "tech.pubsub.PublishBatchResponse" do - repeated :message_ids, :string, 1 - end - add_message "tech.pubsub.ListTopicsRequest" do - optional :query, :string, 1 - optional :max_results, :int32, 2 - optional :page_token, :string, 3 - end - add_message "tech.pubsub.ListTopicsResponse" do - repeated :topic, :message, 1, "tech.pubsub.Topic" - optional :next_page_token, :string, 2 - end - add_message "tech.pubsub.DeleteTopicRequest" do - optional :topic, :string, 1 - end - add_message "tech.pubsub.Subscription" do - optional :name, :string, 1 - optional :topic, :string, 2 - optional :query, :string, 3 - optional :truncation_policy, :message, 4, "tech.pubsub.Subscription.TruncationPolicy" - optional :push_config, :message, 5, "tech.pubsub.PushConfig" - optional :ack_deadline_seconds, :int32, 6 - optional :garbage_collect_seconds, :int64, 7 - end - add_message "tech.pubsub.Subscription.TruncationPolicy" do - optional :max_bytes, :int64, 1 - optional :max_age_seconds, :int64, 2 - end - add_message "tech.pubsub.PushConfig" do - optional :push_endpoint, :string, 1 - end - add_message "tech.pubsub.PubsubEvent" do - optional :subscription, :string, 1 - optional :message, :message, 2, "tech.pubsub.PubsubMessage" - optional :truncated, :bool, 3 - optional :deleted, :bool, 4 - end - add_message "tech.pubsub.GetSubscriptionRequest" do - optional :subscription, :string, 1 - end - add_message "tech.pubsub.ListSubscriptionsRequest" do - optional :query, :string, 1 - optional :max_results, :int32, 3 - optional :page_token, :string, 4 - end - add_message "tech.pubsub.ListSubscriptionsResponse" do - repeated :subscription, :message, 1, "tech.pubsub.Subscription" - optional :next_page_token, :string, 2 - end - add_message "tech.pubsub.TruncateSubscriptionRequest" do - optional :subscription, :string, 1 - end - add_message "tech.pubsub.DeleteSubscriptionRequest" do - optional :subscription, :string, 1 - end - add_message "tech.pubsub.ModifyPushConfigRequest" do - optional :subscription, :string, 1 - optional :push_config, :message, 2, "tech.pubsub.PushConfig" - end - add_message "tech.pubsub.PullRequest" do - optional :subscription, :string, 1 - optional :return_immediately, :bool, 2 - end - add_message "tech.pubsub.PullResponse" do - optional :ack_id, :string, 1 - optional :pubsub_event, :message, 2, "tech.pubsub.PubsubEvent" - end - add_message "tech.pubsub.PullBatchRequest" do - optional :subscription, :string, 1 - optional :return_immediately, :bool, 2 - optional :max_events, :int32, 3 - end - add_message "tech.pubsub.PullBatchResponse" do - repeated :pull_responses, :message, 2, "tech.pubsub.PullResponse" - end - add_message "tech.pubsub.ModifyAckDeadlineRequest" do - optional :subscription, :string, 1 - optional :ack_id, :string, 2 - optional :ack_deadline_seconds, :int32, 3 - end - add_message "tech.pubsub.AcknowledgeRequest" do - optional :subscription, :string, 1 - repeated :ack_id, :string, 2 - end - add_message "tech.pubsub.NackRequest" do - optional :subscription, :string, 1 - repeated :ack_id, :string, 2 - end -end - -module Tech - module Pubsub - Topic = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.Topic").msgclass - PubsubMessage = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.PubsubMessage").msgclass - GetTopicRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.GetTopicRequest").msgclass - PublishRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.PublishRequest").msgclass - PublishBatchRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.PublishBatchRequest").msgclass - PublishBatchResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.PublishBatchResponse").msgclass - ListTopicsRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.ListTopicsRequest").msgclass - ListTopicsResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.ListTopicsResponse").msgclass - DeleteTopicRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.DeleteTopicRequest").msgclass - Subscription = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.Subscription").msgclass - Subscription::TruncationPolicy = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.Subscription.TruncationPolicy").msgclass - PushConfig = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.PushConfig").msgclass - PubsubEvent = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.PubsubEvent").msgclass - GetSubscriptionRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.GetSubscriptionRequest").msgclass - ListSubscriptionsRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.ListSubscriptionsRequest").msgclass - ListSubscriptionsResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.ListSubscriptionsResponse").msgclass - TruncateSubscriptionRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.TruncateSubscriptionRequest").msgclass - DeleteSubscriptionRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.DeleteSubscriptionRequest").msgclass - ModifyPushConfigRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.ModifyPushConfigRequest").msgclass - PullRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.PullRequest").msgclass - PullResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.PullResponse").msgclass - PullBatchRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.PullBatchRequest").msgclass - PullBatchResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.PullBatchResponse").msgclass - ModifyAckDeadlineRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.ModifyAckDeadlineRequest").msgclass - AcknowledgeRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.AcknowledgeRequest").msgclass - NackRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("tech.pubsub.NackRequest").msgclass - end -end diff --git a/src/ruby/bin/apis/tech/pubsub/proto/pubsub_services.rb b/src/ruby/bin/apis/tech/pubsub/proto/pubsub_services.rb deleted file mode 100644 index b34db57b44..0000000000 --- a/src/ruby/bin/apis/tech/pubsub/proto/pubsub_services.rb +++ /dev/null @@ -1,88 +0,0 @@ -# Copyright 2015 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. - -# Generated by the protocol buffer compiler. DO NOT EDIT! -# Source: tech/pubsub/proto/pubsub.proto for package 'tech.pubsub' - -require 'grpc' -require 'google/protobuf/empty' -require 'tech/pubsub/proto/pubsub' - -module Tech - module Pubsub - module PublisherService - - # TODO: add proto service documentation here - class Service - - include GRPC::GenericService - - self.marshal_class_method = :encode - self.unmarshal_class_method = :decode - self.service_name = 'tech.pubsub.PublisherService' - - rpc :CreateTopic, Topic, Topic - rpc :Publish, PublishRequest, Google::Protobuf::Empty - rpc :PublishBatch, PublishBatchRequest, PublishBatchResponse - rpc :GetTopic, GetTopicRequest, Topic - rpc :ListTopics, ListTopicsRequest, ListTopicsResponse - rpc :DeleteTopic, DeleteTopicRequest, Google::Protobuf::Empty - end - - Stub = Service.rpc_stub_class - end - module SubscriberService - - # TODO: add proto service documentation here - class Service - - include GRPC::GenericService - - self.marshal_class_method = :encode - self.unmarshal_class_method = :decode - self.service_name = 'tech.pubsub.SubscriberService' - - rpc :CreateSubscription, Subscription, Subscription - rpc :GetSubscription, GetSubscriptionRequest, Subscription - rpc :ListSubscriptions, ListSubscriptionsRequest, ListSubscriptionsResponse - rpc :DeleteSubscription, DeleteSubscriptionRequest, Google::Protobuf::Empty - rpc :TruncateSubscription, TruncateSubscriptionRequest, Google::Protobuf::Empty - rpc :ModifyPushConfig, ModifyPushConfigRequest, Google::Protobuf::Empty - rpc :Pull, PullRequest, PullResponse - rpc :PullBatch, PullBatchRequest, PullBatchResponse - rpc :ModifyAckDeadline, ModifyAckDeadlineRequest, Google::Protobuf::Empty - rpc :Acknowledge, AcknowledgeRequest, Google::Protobuf::Empty - rpc :Nack, NackRequest, Google::Protobuf::Empty - end - - Stub = Service.rpc_stub_class - end - module PushEndpointService - - # TODO: add proto service documentation here - class Service - - include GRPC::GenericService - - self.marshal_class_method = :encode - self.unmarshal_class_method = :decode - self.service_name = 'tech.pubsub.PushEndpointService' - - rpc :HandlePubsubEvent, PubsubEvent, Google::Protobuf::Empty - end - - Stub = Service.rpc_stub_class - end - end -end diff --git a/src/ruby/bin/math_client.rb b/src/ruby/bin/math_client.rb index 15120c0c0d..66717d8bf3 100755 --- a/src/ruby/bin/math_client.rb +++ b/src/ruby/bin/math_client.rb @@ -27,15 +27,26 @@ $LOAD_PATH.unshift(this_dir) unless $LOAD_PATH.include?(this_dir) require 'grpc' require 'math_services_pb' require 'optparse' +require 'logger' include GRPC::Core::TimeConsts +module StdoutLogger + def logger + LOGGER + end + + LOGGER = Logger.new(STDOUT) +end + +GRPC.extend(StdoutLogger) + def do_div(stub) GRPC.logger.info('request_response') GRPC.logger.info('----------------') req = Math::DivArgs.new(dividend: 7, divisor: 3) GRPC.logger.info("div(7/3): req=#{req.inspect}") - resp = stub.div(req, timeout: INFINITE_FUTURE) + resp = stub.div(req) GRPC.logger.info("Answer: #{resp.inspect}") GRPC.logger.info('----------------') end @@ -56,7 +67,7 @@ def do_fib(stub) GRPC.logger.info('----------------') req = Math::FibArgs.new(limit: 11) GRPC.logger.info("fib(11): req=#{req.inspect}") - resp = stub.fib(req, timeout: INFINITE_FUTURE) + resp = stub.fib(req) resp.each do |r| GRPC.logger.info("Answer: #{r.inspect}") end @@ -71,7 +82,7 @@ def do_div_many(stub) reqs << Math::DivArgs.new(dividend: 5, divisor: 2) reqs << Math::DivArgs.new(dividend: 7, divisor: 2) GRPC.logger.info("div(7/3), div(5/2), div(7/2): reqs=#{reqs.inspect}") - resp = stub.div_many(reqs, timeout: INFINITE_FUTURE) + resp = stub.div_many(reqs) resp.each do |r| GRPC.logger.info("Answer: #{r.inspect}") end @@ -107,19 +118,16 @@ def main # The Math::Math:: module occurs because the service has the same name as its # package. That practice should be avoided by defining real services. - - p options if options['secure'] stub_opts = { :creds => test_creds, - GRPC::Core::Channel::SSL_TARGET => 'foo.test.google.fr' + GRPC::Core::Channel::SSL_TARGET => 'foo.test.google.fr', + timeout: INFINITE_FUTURE, } - p stub_opts - p options['host'] stub = Math::Math::Stub.new(options['host'], **stub_opts) GRPC.logger.info("... connecting securely on #{options['host']}") else - stub = Math::Math::Stub.new(options['host']) + stub = Math::Math::Stub.new(options['host'], :this_channel_is_insecure, timeout: INFINITE_FUTURE) GRPC.logger.info("... connecting insecurely on #{options['host']}") end diff --git a/src/ruby/end2end/multiple_killed_watching_threads_driver.rb b/src/ruby/end2end/multiple_killed_watching_threads_driver.rb index 8ec2073d98..7b39f5a347 100755 --- a/src/ruby/end2end/multiple_killed_watching_threads_driver.rb +++ b/src/ruby/end2end/multiple_killed_watching_threads_driver.rb @@ -58,10 +58,6 @@ def main run_multiple_killed_watches(10, 0.1) STDERR.puts '1000 iterations, sleep 0.001 before killing thread' run_multiple_killed_watches(1000, 0.001) - STDERR.puts '10000 iterations, sleep 0.00001 before killing thread' - run_multiple_killed_watches(10_000, 0.00001) - STDERR.puts '20000 iterations, sleep 0.00001 before killing thread' - run_multiple_killed_watches(20_000, 0.00001) end main diff --git a/src/ruby/end2end/package_with_underscore_checker.rb b/src/ruby/end2end/package_with_underscore_checker.rb new file mode 100644 index 0000000000..27ea00ffa7 --- /dev/null +++ b/src/ruby/end2end/package_with_underscore_checker.rb @@ -0,0 +1,54 @@ +# 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 'open3' +require 'tmpdir' + +def main + root_dir = File.join(File.dirname(__FILE__), '..', '..', '..') + pb_dir = File.join(root_dir, 'src', 'ruby', 'end2end', 'protos') + + fail 'CONFIG env variable unexpectedly unset' unless ENV['CONFIG'] + bins_sub_dir = ENV['CONFIG'] + bins_dir = File.join(root_dir, 'bins', bins_sub_dir) + + plugin = File.join(bins_dir, 'grpc_ruby_plugin') + protoc = File.join(bins_dir, 'protobuf', 'protoc') + + got = nil + + Dir.mktmpdir do |tmp_dir| + gen_out = File.join(tmp_dir, 'package_with_underscore', 'service_services_pb.rb') + + pid = spawn( + protoc, + "--proto_path=#{pb_dir}", + 'package_with_underscore/service.proto', + "--grpc_out=#{tmp_dir}", + "--plugin=protoc-gen-grpc=#{plugin}" + ) + Process.waitpid2(pid) + File.open(gen_out) { |f| got = f.read } + end + + correct_modularized_rpc = 'rpc :TestOne, ' \ + 'Grpc::Testing::PackageWithUnderscore::Data::Request, ' \ + 'Grpc::Testing::PackageWithUnderscore::Data::Response' + + return if got.include?(correct_modularized_rpc) + + fail 'generated file does not match with correct_modularized_rpc' +end + +main diff --git a/src/ruby/spec/pb/package_with_underscore/data.proto b/src/ruby/end2end/protos/package_with_underscore/data.proto index 2706f1d7be..2706f1d7be 100644 --- a/src/ruby/spec/pb/package_with_underscore/data.proto +++ b/src/ruby/end2end/protos/package_with_underscore/data.proto diff --git a/src/ruby/spec/pb/package_with_underscore/service.proto b/src/ruby/end2end/protos/package_with_underscore/service.proto index 814c7898cd..814c7898cd 100644 --- a/src/ruby/spec/pb/package_with_underscore/service.proto +++ b/src/ruby/end2end/protos/package_with_underscore/service.proto diff --git a/src/ruby/ext/grpc/extconf.rb b/src/ruby/ext/grpc/extconf.rb index 4760f33e38..505357021e 100644 --- a/src/ruby/ext/grpc/extconf.rb +++ b/src/ruby/ext/grpc/extconf.rb @@ -15,31 +15,6 @@ require 'etc' require 'mkmf' -LIBDIR = RbConfig::CONFIG['libdir'] -INCLUDEDIR = RbConfig::CONFIG['includedir'] - -HEADER_DIRS = [ - # Search /opt/local (Mac source install) - '/opt/local/include', - - # Search /usr/local (Source install) - '/usr/local/include', - - # Check the ruby install locations - INCLUDEDIR -] - -LIB_DIRS = [ - # Search /opt/local (Mac source install) - '/opt/local/lib', - - # Search /usr/local (Source install) - '/usr/local/lib', - - # Check the ruby install locations - LIBDIR -] - windows = RUBY_PLATFORM =~ /mingw|mswin/ bsd = RUBY_PLATFORM =~ /bsd/ @@ -110,7 +85,7 @@ if grpc_config == 'opt' o.puts i end o.puts - o.puts 'strip:' + o.puts 'strip: $(DLLIB)' o.puts "\t$(ECHO) Stripping $(DLLIB)" o.puts "\t$(Q) #{strip_tool} $(DLLIB)" end diff --git a/src/ruby/ext/grpc/rb_call.c b/src/ruby/ext/grpc/rb_call.c index b6c0791469..fc641dae80 100644 --- a/src/ruby/ext/grpc/rb_call.c +++ b/src/ruby/ext/grpc/rb_call.c @@ -819,6 +819,7 @@ static VALUE grpc_rb_call_run_batch(VALUE self, VALUE ops_hash) { unsigned write_flag = 0; void* tag = (void*)&st; + grpc_ruby_fork_guard(); if (RTYPEDDATA_DATA(self) == NULL) { rb_raise(grpc_rb_eCallError, "Cannot run batch on closed call"); return Qnil; diff --git a/src/ruby/ext/grpc/rb_channel.c b/src/ruby/ext/grpc/rb_channel.c index 3f0dc530cf..6d4b2293a2 100644 --- a/src/ruby/ext/grpc/rb_channel.c +++ b/src/ruby/ext/grpc/rb_channel.c @@ -217,6 +217,7 @@ static VALUE grpc_rb_channel_init(int argc, VALUE* argv, VALUE self) { MEMZERO(&args, grpc_channel_args, 1); grpc_ruby_once_init(); + grpc_ruby_fork_guard(); rb_thread_call_without_gvl( wait_until_channel_polling_thread_started_no_gil, &stop_waiting_for_thread_start, @@ -374,6 +375,7 @@ static VALUE grpc_rb_channel_watch_connectivity_state(VALUE self, watch_state_stack stack; void* op_success = 0; + grpc_ruby_fork_guard(); TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper); if (wrapper->bg_wrapped == NULL) { @@ -415,6 +417,7 @@ static VALUE grpc_rb_channel_create_call(VALUE self, VALUE parent, VALUE mask, grpc_slice* host_slice_ptr = NULL; char* tmp_str = NULL; + grpc_ruby_fork_guard(); if (host != Qnil) { host_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(host), RSTRING_LEN(host)); diff --git a/src/ruby/ext/grpc/rb_channel_credentials.c b/src/ruby/ext/grpc/rb_channel_credentials.c index b23a32caf1..178224c6e0 100644 --- a/src/ruby/ext/grpc/rb_channel_credentials.c +++ b/src/ruby/ext/grpc/rb_channel_credentials.c @@ -159,12 +159,12 @@ static VALUE grpc_rb_channel_credentials_init(int argc, VALUE* argv, pem_root_certs_cstr = RSTRING_PTR(pem_root_certs); } if (pem_private_key == Qnil && pem_cert_chain == Qnil) { - creds = grpc_ssl_credentials_create(pem_root_certs_cstr, NULL, NULL); + creds = grpc_ssl_credentials_create(pem_root_certs_cstr, NULL, NULL, NULL); } else { key_cert_pair.private_key = RSTRING_PTR(pem_private_key); key_cert_pair.cert_chain = RSTRING_PTR(pem_cert_chain); - creds = - grpc_ssl_credentials_create(pem_root_certs_cstr, &key_cert_pair, NULL); + creds = grpc_ssl_credentials_create(pem_root_certs_cstr, &key_cert_pair, + NULL, NULL); } if (creds == NULL) { rb_raise(rb_eRuntimeError, "could not create a credentials, not sure why"); diff --git a/src/ruby/ext/grpc/rb_grpc.c b/src/ruby/ext/grpc/rb_grpc.c index f065a857db..872aed0cfc 100644 --- a/src/ruby/ext/grpc/rb_grpc.c +++ b/src/ruby/ext/grpc/rb_grpc.c @@ -23,9 +23,13 @@ #include <math.h> #include <ruby/vm.h> +#include <stdbool.h> #include <sys/time.h> +#include <sys/types.h> +#include <unistd.h> #include <grpc/grpc.h> +#include <grpc/support/log.h> #include <grpc/support/time.h> #include "rb_call.h" #include "rb_call_credentials.h" @@ -255,7 +259,26 @@ static void Init_grpc_time_consts() { id_tv_nsec = rb_intern("tv_nsec"); } -static void grpc_rb_shutdown(void) { grpc_shutdown(); } +#if GPR_WINDOWS +static void grpc_ruby_set_init_pid(void) {} +static bool grpc_ruby_forked_after_init(void) { return false; } +#else +static pid_t grpc_init_pid; + +static void grpc_ruby_set_init_pid(void) { + GPR_ASSERT(grpc_init_pid == 0); + grpc_init_pid = getpid(); +} + +static bool grpc_ruby_forked_after_init(void) { + GPR_ASSERT(grpc_init_pid != 0); + return grpc_init_pid != getpid(); +} +#endif + +static void grpc_rb_shutdown(void) { + if (!grpc_ruby_forked_after_init()) grpc_shutdown(); +} /* Initialize the GRPC module structs */ @@ -276,10 +299,17 @@ VALUE sym_metadata = Qundef; static gpr_once g_once_init = GPR_ONCE_INIT; static void grpc_ruby_once_init_internal() { + grpc_ruby_set_init_pid(); grpc_init(); atexit(grpc_rb_shutdown); } +void grpc_ruby_fork_guard() { + if (grpc_ruby_forked_after_init()) { + rb_raise(rb_eRuntimeError, "grpc cannot be used before and after forking"); + } +} + static VALUE bg_thread_init_rb_mu = Qundef; static int bg_thread_init_done = 0; diff --git a/src/ruby/ext/grpc/rb_grpc.h b/src/ruby/ext/grpc/rb_grpc.h index 577902319e..4118435ecf 100644 --- a/src/ruby/ext/grpc/rb_grpc.h +++ b/src/ruby/ext/grpc/rb_grpc.h @@ -69,4 +69,6 @@ gpr_timespec grpc_rb_time_timeval(VALUE time, int interval); void grpc_ruby_once_init(); +void grpc_ruby_fork_guard(); + #endif /* GRPC_RB_H_ */ diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.c b/src/ruby/ext/grpc/rb_grpc_imports.generated.c index 02f84c0b96..1e7d7f687f 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.c +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.c @@ -38,11 +38,13 @@ grpc_call_details_destroy_type grpc_call_details_destroy_import; grpc_register_plugin_type grpc_register_plugin_import; grpc_init_type grpc_init_import; grpc_shutdown_type grpc_shutdown_import; +grpc_is_initialized_type grpc_is_initialized_import; grpc_version_string_type grpc_version_string_import; grpc_g_stands_for_type grpc_g_stands_for_import; grpc_completion_queue_factory_lookup_type grpc_completion_queue_factory_lookup_import; grpc_completion_queue_create_for_next_type grpc_completion_queue_create_for_next_import; grpc_completion_queue_create_for_pluck_type grpc_completion_queue_create_for_pluck_import; +grpc_completion_queue_create_for_callback_type grpc_completion_queue_create_for_callback_import; grpc_completion_queue_create_type grpc_completion_queue_create_import; grpc_completion_queue_next_type grpc_completion_queue_next_import; grpc_completion_queue_pluck_type grpc_completion_queue_pluck_import; @@ -65,11 +67,10 @@ grpc_census_call_set_context_type grpc_census_call_set_context_import; grpc_census_call_get_context_type grpc_census_call_get_context_import; grpc_channel_get_target_type grpc_channel_get_target_import; grpc_channel_get_info_type grpc_channel_get_info_import; +grpc_channel_reset_connect_backoff_type grpc_channel_reset_connect_backoff_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; @@ -93,7 +94,13 @@ grpc_resource_quota_create_type grpc_resource_quota_create_import; grpc_resource_quota_ref_type grpc_resource_quota_ref_import; grpc_resource_quota_unref_type grpc_resource_quota_unref_import; grpc_resource_quota_resize_type grpc_resource_quota_resize_import; +grpc_resource_quota_set_max_threads_type grpc_resource_quota_set_max_threads_import; grpc_resource_quota_arg_vtable_type grpc_resource_quota_arg_vtable_import; +grpc_channelz_get_top_channels_type grpc_channelz_get_top_channels_import; +grpc_channelz_get_servers_type grpc_channelz_get_servers_import; +grpc_channelz_get_channel_type grpc_channelz_get_channel_import; +grpc_channelz_get_subchannel_type grpc_channelz_get_subchannel_import; +grpc_channelz_get_socket_type grpc_channelz_get_socket_import; grpc_insecure_channel_create_from_fd_type grpc_insecure_channel_create_from_fd_import; grpc_server_add_insecure_channel_from_fd_type grpc_server_add_insecure_channel_from_fd_import; grpc_use_signal_type grpc_use_signal_import; @@ -144,6 +151,8 @@ grpc_alts_credentials_client_options_add_target_service_account_type grpc_alts_c grpc_alts_credentials_options_destroy_type grpc_alts_credentials_options_destroy_import; grpc_alts_credentials_create_type grpc_alts_credentials_create_import; grpc_alts_server_credentials_create_type grpc_alts_server_credentials_create_import; +grpc_local_credentials_create_type grpc_local_credentials_create_import; +grpc_local_server_credentials_create_type grpc_local_server_credentials_create_import; grpc_raw_byte_buffer_create_type grpc_raw_byte_buffer_create_import; grpc_raw_compressed_byte_buffer_create_type grpc_raw_compressed_byte_buffer_create_import; grpc_byte_buffer_copy_type grpc_byte_buffer_copy_import; @@ -154,6 +163,13 @@ grpc_byte_buffer_reader_destroy_type grpc_byte_buffer_reader_destroy_import; grpc_byte_buffer_reader_next_type grpc_byte_buffer_reader_next_import; grpc_byte_buffer_reader_readall_type grpc_byte_buffer_reader_readall_import; grpc_raw_byte_buffer_from_reader_type grpc_raw_byte_buffer_from_reader_import; +gpr_log_severity_string_type gpr_log_severity_string_import; +gpr_log_type gpr_log_import; +gpr_should_log_type gpr_should_log_import; +gpr_log_message_type gpr_log_message_import; +gpr_set_log_verbosity_type gpr_set_log_verbosity_import; +gpr_log_verbosity_init_type gpr_log_verbosity_init_import; +gpr_set_log_function_type gpr_set_log_function_import; grpc_slice_ref_type grpc_slice_ref_import; grpc_slice_unref_type grpc_slice_unref_import; grpc_slice_copy_type grpc_slice_copy_import; @@ -212,13 +228,6 @@ gpr_set_allocation_functions_type gpr_set_allocation_functions_import; gpr_get_allocation_functions_type gpr_get_allocation_functions_import; gpr_cpu_num_cores_type gpr_cpu_num_cores_import; gpr_cpu_current_cpu_type gpr_cpu_current_cpu_import; -gpr_log_severity_string_type gpr_log_severity_string_import; -gpr_log_type gpr_log_import; -gpr_should_log_type gpr_should_log_import; -gpr_log_message_type gpr_log_message_import; -gpr_set_log_verbosity_type gpr_set_log_verbosity_import; -gpr_log_verbosity_init_type gpr_log_verbosity_init_import; -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; @@ -286,11 +295,13 @@ void grpc_rb_load_imports(HMODULE library) { grpc_register_plugin_import = (grpc_register_plugin_type) GetProcAddress(library, "grpc_register_plugin"); grpc_init_import = (grpc_init_type) GetProcAddress(library, "grpc_init"); grpc_shutdown_import = (grpc_shutdown_type) GetProcAddress(library, "grpc_shutdown"); + grpc_is_initialized_import = (grpc_is_initialized_type) GetProcAddress(library, "grpc_is_initialized"); grpc_version_string_import = (grpc_version_string_type) GetProcAddress(library, "grpc_version_string"); grpc_g_stands_for_import = (grpc_g_stands_for_type) GetProcAddress(library, "grpc_g_stands_for"); grpc_completion_queue_factory_lookup_import = (grpc_completion_queue_factory_lookup_type) GetProcAddress(library, "grpc_completion_queue_factory_lookup"); grpc_completion_queue_create_for_next_import = (grpc_completion_queue_create_for_next_type) GetProcAddress(library, "grpc_completion_queue_create_for_next"); grpc_completion_queue_create_for_pluck_import = (grpc_completion_queue_create_for_pluck_type) GetProcAddress(library, "grpc_completion_queue_create_for_pluck"); + grpc_completion_queue_create_for_callback_import = (grpc_completion_queue_create_for_callback_type) GetProcAddress(library, "grpc_completion_queue_create_for_callback"); grpc_completion_queue_create_import = (grpc_completion_queue_create_type) GetProcAddress(library, "grpc_completion_queue_create"); grpc_completion_queue_next_import = (grpc_completion_queue_next_type) GetProcAddress(library, "grpc_completion_queue_next"); grpc_completion_queue_pluck_import = (grpc_completion_queue_pluck_type) GetProcAddress(library, "grpc_completion_queue_pluck"); @@ -313,11 +324,10 @@ void grpc_rb_load_imports(HMODULE library) { grpc_census_call_get_context_import = (grpc_census_call_get_context_type) GetProcAddress(library, "grpc_census_call_get_context"); grpc_channel_get_target_import = (grpc_channel_get_target_type) GetProcAddress(library, "grpc_channel_get_target"); grpc_channel_get_info_import = (grpc_channel_get_info_type) GetProcAddress(library, "grpc_channel_get_info"); + grpc_channel_reset_connect_backoff_import = (grpc_channel_reset_connect_backoff_type) GetProcAddress(library, "grpc_channel_reset_connect_backoff"); 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"); @@ -341,7 +351,13 @@ void grpc_rb_load_imports(HMODULE library) { grpc_resource_quota_ref_import = (grpc_resource_quota_ref_type) GetProcAddress(library, "grpc_resource_quota_ref"); grpc_resource_quota_unref_import = (grpc_resource_quota_unref_type) GetProcAddress(library, "grpc_resource_quota_unref"); grpc_resource_quota_resize_import = (grpc_resource_quota_resize_type) GetProcAddress(library, "grpc_resource_quota_resize"); + grpc_resource_quota_set_max_threads_import = (grpc_resource_quota_set_max_threads_type) GetProcAddress(library, "grpc_resource_quota_set_max_threads"); grpc_resource_quota_arg_vtable_import = (grpc_resource_quota_arg_vtable_type) GetProcAddress(library, "grpc_resource_quota_arg_vtable"); + grpc_channelz_get_top_channels_import = (grpc_channelz_get_top_channels_type) GetProcAddress(library, "grpc_channelz_get_top_channels"); + grpc_channelz_get_servers_import = (grpc_channelz_get_servers_type) GetProcAddress(library, "grpc_channelz_get_servers"); + grpc_channelz_get_channel_import = (grpc_channelz_get_channel_type) GetProcAddress(library, "grpc_channelz_get_channel"); + grpc_channelz_get_subchannel_import = (grpc_channelz_get_subchannel_type) GetProcAddress(library, "grpc_channelz_get_subchannel"); + grpc_channelz_get_socket_import = (grpc_channelz_get_socket_type) GetProcAddress(library, "grpc_channelz_get_socket"); grpc_insecure_channel_create_from_fd_import = (grpc_insecure_channel_create_from_fd_type) GetProcAddress(library, "grpc_insecure_channel_create_from_fd"); grpc_server_add_insecure_channel_from_fd_import = (grpc_server_add_insecure_channel_from_fd_type) GetProcAddress(library, "grpc_server_add_insecure_channel_from_fd"); grpc_use_signal_import = (grpc_use_signal_type) GetProcAddress(library, "grpc_use_signal"); @@ -392,6 +408,8 @@ void grpc_rb_load_imports(HMODULE library) { grpc_alts_credentials_options_destroy_import = (grpc_alts_credentials_options_destroy_type) GetProcAddress(library, "grpc_alts_credentials_options_destroy"); grpc_alts_credentials_create_import = (grpc_alts_credentials_create_type) GetProcAddress(library, "grpc_alts_credentials_create"); grpc_alts_server_credentials_create_import = (grpc_alts_server_credentials_create_type) GetProcAddress(library, "grpc_alts_server_credentials_create"); + grpc_local_credentials_create_import = (grpc_local_credentials_create_type) GetProcAddress(library, "grpc_local_credentials_create"); + grpc_local_server_credentials_create_import = (grpc_local_server_credentials_create_type) GetProcAddress(library, "grpc_local_server_credentials_create"); grpc_raw_byte_buffer_create_import = (grpc_raw_byte_buffer_create_type) GetProcAddress(library, "grpc_raw_byte_buffer_create"); grpc_raw_compressed_byte_buffer_create_import = (grpc_raw_compressed_byte_buffer_create_type) GetProcAddress(library, "grpc_raw_compressed_byte_buffer_create"); grpc_byte_buffer_copy_import = (grpc_byte_buffer_copy_type) GetProcAddress(library, "grpc_byte_buffer_copy"); @@ -402,6 +420,13 @@ void grpc_rb_load_imports(HMODULE library) { grpc_byte_buffer_reader_next_import = (grpc_byte_buffer_reader_next_type) GetProcAddress(library, "grpc_byte_buffer_reader_next"); grpc_byte_buffer_reader_readall_import = (grpc_byte_buffer_reader_readall_type) GetProcAddress(library, "grpc_byte_buffer_reader_readall"); grpc_raw_byte_buffer_from_reader_import = (grpc_raw_byte_buffer_from_reader_type) GetProcAddress(library, "grpc_raw_byte_buffer_from_reader"); + 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_should_log_import = (gpr_should_log_type) GetProcAddress(library, "gpr_should_log"); + gpr_log_message_import = (gpr_log_message_type) GetProcAddress(library, "gpr_log_message"); + gpr_set_log_verbosity_import = (gpr_set_log_verbosity_type) GetProcAddress(library, "gpr_set_log_verbosity"); + gpr_log_verbosity_init_import = (gpr_log_verbosity_init_type) GetProcAddress(library, "gpr_log_verbosity_init"); + gpr_set_log_function_import = (gpr_set_log_function_type) GetProcAddress(library, "gpr_set_log_function"); grpc_slice_ref_import = (grpc_slice_ref_type) GetProcAddress(library, "grpc_slice_ref"); grpc_slice_unref_import = (grpc_slice_unref_type) GetProcAddress(library, "grpc_slice_unref"); grpc_slice_copy_import = (grpc_slice_copy_type) GetProcAddress(library, "grpc_slice_copy"); @@ -460,13 +485,6 @@ void grpc_rb_load_imports(HMODULE library) { gpr_get_allocation_functions_import = (gpr_get_allocation_functions_type) GetProcAddress(library, "gpr_get_allocation_functions"); 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_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_should_log_import = (gpr_should_log_type) GetProcAddress(library, "gpr_should_log"); - gpr_log_message_import = (gpr_log_message_type) GetProcAddress(library, "gpr_log_message"); - gpr_set_log_verbosity_import = (gpr_set_log_verbosity_type) GetProcAddress(library, "gpr_set_log_verbosity"); - gpr_log_verbosity_init_import = (gpr_log_verbosity_init_type) GetProcAddress(library, "gpr_log_verbosity_init"); - gpr_set_log_function_import = (gpr_set_log_function_type) GetProcAddress(library, "gpr_set_log_function"); 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"); diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.h b/src/ruby/ext/grpc/rb_grpc_imports.generated.h index b2186a69aa..ed4b6264b0 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.h +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.h @@ -30,11 +30,11 @@ #include <grpc/grpc_posix.h> #include <grpc/grpc_security.h> #include <grpc/impl/codegen/byte_buffer.h> +#include <grpc/impl/codegen/log.h> #include <grpc/slice.h> #include <grpc/slice_buffer.h> #include <grpc/support/alloc.h> #include <grpc/support/cpu.h> -#include <grpc/support/log.h> #include <grpc/support/log_windows.h> #include <grpc/support/string_util.h> #include <grpc/support/sync.h> @@ -89,6 +89,9 @@ extern grpc_init_type grpc_init_import; typedef void(*grpc_shutdown_type)(void); extern grpc_shutdown_type grpc_shutdown_import; #define grpc_shutdown grpc_shutdown_import +typedef int(*grpc_is_initialized_type)(void); +extern grpc_is_initialized_type grpc_is_initialized_import; +#define grpc_is_initialized grpc_is_initialized_import typedef const char*(*grpc_version_string_type)(void); extern grpc_version_string_type grpc_version_string_import; #define grpc_version_string grpc_version_string_import @@ -104,6 +107,9 @@ extern grpc_completion_queue_create_for_next_type grpc_completion_queue_create_f typedef grpc_completion_queue*(*grpc_completion_queue_create_for_pluck_type)(void* reserved); extern grpc_completion_queue_create_for_pluck_type grpc_completion_queue_create_for_pluck_import; #define grpc_completion_queue_create_for_pluck grpc_completion_queue_create_for_pluck_import +typedef grpc_completion_queue*(*grpc_completion_queue_create_for_callback_type)(grpc_experimental_completion_queue_functor* shutdown_callback, void* reserved); +extern grpc_completion_queue_create_for_callback_type grpc_completion_queue_create_for_callback_import; +#define grpc_completion_queue_create_for_callback grpc_completion_queue_create_for_callback_import typedef grpc_completion_queue*(*grpc_completion_queue_create_type)(const grpc_completion_queue_factory* factory, const grpc_completion_queue_attributes* attributes, void* reserved); extern grpc_completion_queue_create_type grpc_completion_queue_create_import; #define grpc_completion_queue_create grpc_completion_queue_create_import @@ -170,6 +176,9 @@ extern grpc_channel_get_target_type grpc_channel_get_target_import; typedef void(*grpc_channel_get_info_type)(grpc_channel* channel, const grpc_channel_info* channel_info); extern grpc_channel_get_info_type grpc_channel_get_info_import; #define grpc_channel_get_info grpc_channel_get_info_import +typedef void(*grpc_channel_reset_connect_backoff_type)(grpc_channel* channel); +extern grpc_channel_reset_connect_backoff_type grpc_channel_reset_connect_backoff_import; +#define grpc_channel_reset_connect_backoff grpc_channel_reset_connect_backoff_import typedef grpc_channel*(*grpc_insecure_channel_create_type)(const char* target, const grpc_channel_args* args, void* reserved); extern grpc_insecure_channel_create_type grpc_insecure_channel_create_import; #define grpc_insecure_channel_create grpc_insecure_channel_create_import @@ -179,12 +188,6 @@ 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 @@ -254,9 +257,27 @@ extern grpc_resource_quota_unref_type grpc_resource_quota_unref_import; typedef void(*grpc_resource_quota_resize_type)(grpc_resource_quota* resource_quota, size_t new_size); extern grpc_resource_quota_resize_type grpc_resource_quota_resize_import; #define grpc_resource_quota_resize grpc_resource_quota_resize_import +typedef void(*grpc_resource_quota_set_max_threads_type)(grpc_resource_quota* resource_quota, int new_max_threads); +extern grpc_resource_quota_set_max_threads_type grpc_resource_quota_set_max_threads_import; +#define grpc_resource_quota_set_max_threads grpc_resource_quota_set_max_threads_import typedef const grpc_arg_pointer_vtable*(*grpc_resource_quota_arg_vtable_type)(void); extern grpc_resource_quota_arg_vtable_type grpc_resource_quota_arg_vtable_import; #define grpc_resource_quota_arg_vtable grpc_resource_quota_arg_vtable_import +typedef char*(*grpc_channelz_get_top_channels_type)(intptr_t start_channel_id); +extern grpc_channelz_get_top_channels_type grpc_channelz_get_top_channels_import; +#define grpc_channelz_get_top_channels grpc_channelz_get_top_channels_import +typedef char*(*grpc_channelz_get_servers_type)(intptr_t start_server_id); +extern grpc_channelz_get_servers_type grpc_channelz_get_servers_import; +#define grpc_channelz_get_servers grpc_channelz_get_servers_import +typedef char*(*grpc_channelz_get_channel_type)(intptr_t channel_id); +extern grpc_channelz_get_channel_type grpc_channelz_get_channel_import; +#define grpc_channelz_get_channel grpc_channelz_get_channel_import +typedef char*(*grpc_channelz_get_subchannel_type)(intptr_t subchannel_id); +extern grpc_channelz_get_subchannel_type grpc_channelz_get_subchannel_import; +#define grpc_channelz_get_subchannel grpc_channelz_get_subchannel_import +typedef char*(*grpc_channelz_get_socket_type)(intptr_t socket_id); +extern grpc_channelz_get_socket_type grpc_channelz_get_socket_import; +#define grpc_channelz_get_socket grpc_channelz_get_socket_import typedef grpc_channel*(*grpc_insecure_channel_create_from_fd_type)(const char* target, int fd, const grpc_channel_args* args); extern grpc_insecure_channel_create_from_fd_type grpc_insecure_channel_create_from_fd_import; #define grpc_insecure_channel_create_from_fd grpc_insecure_channel_create_from_fd_import @@ -317,7 +338,7 @@ extern grpc_google_default_credentials_create_type grpc_google_default_credentia typedef void(*grpc_set_ssl_roots_override_callback_type)(grpc_ssl_roots_override_callback cb); extern grpc_set_ssl_roots_override_callback_type grpc_set_ssl_roots_override_callback_import; #define grpc_set_ssl_roots_override_callback grpc_set_ssl_roots_override_callback_import -typedef grpc_channel_credentials*(*grpc_ssl_credentials_create_type)(const char* pem_root_certs, grpc_ssl_pem_key_cert_pair* pem_key_cert_pair, void* reserved); +typedef grpc_channel_credentials*(*grpc_ssl_credentials_create_type)(const char* pem_root_certs, grpc_ssl_pem_key_cert_pair* pem_key_cert_pair, const verify_peer_options* verify_options, void* reserved); extern grpc_ssl_credentials_create_type grpc_ssl_credentials_create_import; #define grpc_ssl_credentials_create grpc_ssl_credentials_create_import typedef void(*grpc_call_credentials_release_type)(grpc_call_credentials* creds); @@ -389,10 +410,10 @@ extern grpc_call_set_credentials_type grpc_call_set_credentials_import; typedef void(*grpc_server_credentials_set_auth_metadata_processor_type)(grpc_server_credentials* creds, grpc_auth_metadata_processor processor); extern grpc_server_credentials_set_auth_metadata_processor_type grpc_server_credentials_set_auth_metadata_processor_import; #define grpc_server_credentials_set_auth_metadata_processor grpc_server_credentials_set_auth_metadata_processor_import -typedef grpc_alts_credentials_options*(*grpc_alts_credentials_client_options_create_type)(); +typedef grpc_alts_credentials_options*(*grpc_alts_credentials_client_options_create_type)(void); extern grpc_alts_credentials_client_options_create_type grpc_alts_credentials_client_options_create_import; #define grpc_alts_credentials_client_options_create grpc_alts_credentials_client_options_create_import -typedef grpc_alts_credentials_options*(*grpc_alts_credentials_server_options_create_type)(); +typedef grpc_alts_credentials_options*(*grpc_alts_credentials_server_options_create_type)(void); extern grpc_alts_credentials_server_options_create_type grpc_alts_credentials_server_options_create_import; #define grpc_alts_credentials_server_options_create grpc_alts_credentials_server_options_create_import typedef void(*grpc_alts_credentials_client_options_add_target_service_account_type)(grpc_alts_credentials_options* options, const char* service_account); @@ -407,6 +428,12 @@ extern grpc_alts_credentials_create_type grpc_alts_credentials_create_import; typedef grpc_server_credentials*(*grpc_alts_server_credentials_create_type)(const grpc_alts_credentials_options* options); extern grpc_alts_server_credentials_create_type grpc_alts_server_credentials_create_import; #define grpc_alts_server_credentials_create grpc_alts_server_credentials_create_import +typedef grpc_channel_credentials*(*grpc_local_credentials_create_type)(grpc_local_connect_type type); +extern grpc_local_credentials_create_type grpc_local_credentials_create_import; +#define grpc_local_credentials_create grpc_local_credentials_create_import +typedef grpc_server_credentials*(*grpc_local_server_credentials_create_type)(grpc_local_connect_type type); +extern grpc_local_server_credentials_create_type grpc_local_server_credentials_create_import; +#define grpc_local_server_credentials_create grpc_local_server_credentials_create_import typedef grpc_byte_buffer*(*grpc_raw_byte_buffer_create_type)(grpc_slice* slices, size_t nslices); extern grpc_raw_byte_buffer_create_type grpc_raw_byte_buffer_create_import; #define grpc_raw_byte_buffer_create grpc_raw_byte_buffer_create_import @@ -437,6 +464,27 @@ extern grpc_byte_buffer_reader_readall_type grpc_byte_buffer_reader_readall_impo typedef grpc_byte_buffer*(*grpc_raw_byte_buffer_from_reader_type)(grpc_byte_buffer_reader* reader); extern grpc_raw_byte_buffer_from_reader_type grpc_raw_byte_buffer_from_reader_import; #define grpc_raw_byte_buffer_from_reader grpc_raw_byte_buffer_from_reader_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 +typedef void(*gpr_log_type)(const char* file, int line, gpr_log_severity severity, const char* format, ...) GPR_PRINT_FORMAT_CHECK(4, 5); +extern gpr_log_type gpr_log_import; +#define gpr_log gpr_log_import +typedef int(*gpr_should_log_type)(gpr_log_severity severity); +extern gpr_should_log_type gpr_should_log_import; +#define gpr_should_log gpr_should_log_import +typedef void(*gpr_log_message_type)(const char* file, int line, gpr_log_severity severity, const char* message); +extern gpr_log_message_type gpr_log_message_import; +#define gpr_log_message gpr_log_message_import +typedef void(*gpr_set_log_verbosity_type)(gpr_log_severity min_severity_to_print); +extern gpr_set_log_verbosity_type gpr_set_log_verbosity_import; +#define gpr_set_log_verbosity gpr_set_log_verbosity_import +typedef void(*gpr_log_verbosity_init_type)(void); +extern gpr_log_verbosity_init_type gpr_log_verbosity_init_import; +#define gpr_log_verbosity_init gpr_log_verbosity_init_import +typedef void(*gpr_set_log_function_type)(gpr_log_func func); +extern gpr_set_log_function_type gpr_set_log_function_import; +#define gpr_set_log_function gpr_set_log_function_import typedef grpc_slice(*grpc_slice_ref_type)(grpc_slice s); extern grpc_slice_ref_type grpc_slice_ref_import; #define grpc_slice_ref grpc_slice_ref_import @@ -611,27 +659,6 @@ extern gpr_cpu_num_cores_type 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 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 -typedef void(*gpr_log_type)(const char* file, int line, gpr_log_severity severity, const char* format, ...) GPR_PRINT_FORMAT_CHECK(4, 5); -extern gpr_log_type gpr_log_import; -#define gpr_log gpr_log_import -typedef int(*gpr_should_log_type)(gpr_log_severity severity); -extern gpr_should_log_type gpr_should_log_import; -#define gpr_should_log gpr_should_log_import -typedef void(*gpr_log_message_type)(const char* file, int line, gpr_log_severity severity, const char* message); -extern gpr_log_message_type gpr_log_message_import; -#define gpr_log_message gpr_log_message_import -typedef void(*gpr_set_log_verbosity_type)(gpr_log_severity min_severity_to_print); -extern gpr_set_log_verbosity_type gpr_set_log_verbosity_import; -#define gpr_set_log_verbosity gpr_set_log_verbosity_import -typedef void(*gpr_log_verbosity_init_type)(void); -extern gpr_log_verbosity_init_type gpr_log_verbosity_init_import; -#define gpr_log_verbosity_init gpr_log_verbosity_init_import -typedef void(*gpr_set_log_function_type)(gpr_log_func func); -extern gpr_set_log_function_type gpr_set_log_function_import; -#define gpr_set_log_function gpr_set_log_function_import typedef char*(*gpr_format_message_type)(int messageid); extern gpr_format_message_type gpr_format_message_import; #define gpr_format_message gpr_format_message_import diff --git a/src/ruby/ext/grpc/rb_server.c b/src/ruby/ext/grpc/rb_server.c index 88e6a0cfd5..2931f34409 100644 --- a/src/ruby/ext/grpc/rb_server.c +++ b/src/ruby/ext/grpc/rb_server.c @@ -243,6 +243,8 @@ static VALUE grpc_rb_server_request_call(VALUE self) { static VALUE grpc_rb_server_start(VALUE self) { grpc_rb_server* s = NULL; TypedData_Get_Struct(self, grpc_rb_server, &grpc_rb_server_data_type, s); + + grpc_ruby_fork_guard(); if (s->wrapped == NULL) { rb_raise(rb_eRuntimeError, "destroyed!"); } else { diff --git a/src/ruby/lib/grpc/generic/active_call.rb b/src/ruby/lib/grpc/generic/active_call.rb index 8c3aa284aa..688726ef4a 100644 --- a/src/ruby/lib/grpc/generic/active_call.rb +++ b/src/ruby/lib/grpc/generic/active_call.rb @@ -116,10 +116,11 @@ module GRPC # Sends the initial metadata that has yet to be sent. # Does nothing if metadata has already been sent for this call. - def send_initial_metadata + def send_initial_metadata(new_metadata = {}) @send_initial_md_mutex.synchronize do return if @metadata_sent - @metadata_tag = ActiveCall.client_invoke(@call, @metadata_to_send) + @metadata_to_send.merge!(new_metadata) + ActiveCall.client_invoke(@call, @metadata_to_send) @metadata_sent = true end end @@ -321,18 +322,22 @@ module GRPC # @return [Enumerator] if no block was given def each_remote_read_then_finish return enum_for(:each_remote_read_then_finish) unless block_given? - begin - loop do - resp = remote_read - if resp.nil? # the last response was received - receive_and_check_status - break + loop do + resp = + begin + remote_read + rescue GRPC::Core::CallError => e + GRPC.logger.warn("In each_remote_read_then_finish: #{e}") + nil end - yield resp - end - ensure - set_input_stream_done + + break if resp.nil? # the last response was received + yield resp end + + receive_and_check_status + ensure + set_input_stream_done end # request_response sends a request to a GRPC server, and returns the @@ -388,7 +393,7 @@ module GRPC def client_streamer(requests, metadata: {}) raise_error_if_already_executed begin - merge_metadata_and_send_if_not_already_sent(metadata) + send_initial_metadata(metadata) requests.each { |r| @call.run_batch(SEND_MESSAGE => @marshal.call(r)) } rescue GRPC::Core::CallError => e receive_and_check_status # check for Cancelled @@ -490,7 +495,7 @@ module GRPC raise_error_if_already_executed # Metadata might have already been sent if this is an operation view begin - merge_metadata_and_send_if_not_already_sent(metadata) + send_initial_metadata(metadata) rescue GRPC::Core::CallError => e batch_result = @call.run_batch(RECV_STATUS_ON_CLIENT => nil) set_input_stream_done @@ -571,15 +576,6 @@ module GRPC end end - def merge_metadata_and_send_if_not_already_sent(new_metadata = {}) - @send_initial_md_mutex.synchronize do - return if @metadata_sent - @metadata_to_send.merge!(new_metadata) - @call.run_batch(SEND_INITIAL_METADATA => @metadata_to_send) - @metadata_sent = true - end - end - def attach_peer_cert(peer_cert) @peer_cert = peer_cert end diff --git a/src/ruby/lib/grpc/generic/rpc_desc.rb b/src/ruby/lib/grpc/generic/rpc_desc.rb index 5fd1805aab..efb0e4233d 100644 --- a/src/ruby/lib/grpc/generic/rpc_desc.rb +++ b/src/ruby/lib/grpc/generic/rpc_desc.rb @@ -32,7 +32,7 @@ module GRPC # @return [Proc] { |instance| marshalled(instance) } def marshal_proc - proc { |o| o.class.method(marshal_method).call(o).to_s } + proc { |o| o.class.send(marshal_method, o).to_s } end # @param [:input, :output] target determines whether to produce the an @@ -42,9 +42,9 @@ module GRPC # @return [Proc] An unmarshal proc { |marshalled(instance)| instance } def unmarshal_proc(target) fail ArgumentError unless [:input, :output].include?(target) - unmarshal_class = method(target).call + unmarshal_class = send(target) unmarshal_class = unmarshal_class.type if unmarshal_class.is_a? Stream - proc { |o| unmarshal_class.method(unmarshal_method).call(o) } + proc { |o| unmarshal_class.send(unmarshal_method, o) } end def handle_request_response(active_call, mth, inter_ctx) diff --git a/src/ruby/lib/grpc/generic/rpc_server.rb b/src/ruby/lib/grpc/generic/rpc_server.rb index 31ab6a302b..3b5a0ce27f 100644 --- a/src/ruby/lib/grpc/generic/rpc_server.rb +++ b/src/ruby/lib/grpc/generic/rpc_server.rb @@ -136,7 +136,7 @@ module GRPC begin blk, args = worker_queue.pop blk.call(*args) - rescue StandardError => e + rescue StandardError, GRPC::Core::CallError => e GRPC.logger.warn('Error in worker thread') GRPC.logger.warn(e) end @@ -364,7 +364,8 @@ module GRPC # sent yet c = ActiveCall.new(an_rpc.call, noop, noop, an_rpc.deadline, metadata_received: true, started: false) - c.send_status(GRPC::Core::StatusCodes::RESOURCE_EXHAUSTED, '') + c.send_status(GRPC::Core::StatusCodes::RESOURCE_EXHAUSTED, + 'No free threads in thread pool') nil end diff --git a/src/ruby/lib/grpc/version.rb b/src/ruby/lib/grpc/version.rb index 15f375100a..0c3e1ef734 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.13.0.dev' + VERSION = '1.16.0.dev' end diff --git a/src/ruby/pb/test/client.rb b/src/ruby/pb/test/client.rb index 7ac12c39a5..7710d34657 100755 --- a/src/ruby/pb/test/client.rb +++ b/src/ruby/pb/test/client.rb @@ -681,13 +681,13 @@ class NamedTests # Send probing message for compressed request on the server, to see # if it's implemented. def send_probe_for_compressed_request_support(&send_probe) - bad_status_occured = false + bad_status_occurred = false begin send_probe.call rescue GRPC::BadStatus => e if e.code == GRPC::Core::StatusCodes::INVALID_ARGUMENT - bad_status_occured = true + bad_status_occurred = true else fail AssertionError, "Bad status received but code is #{e.code}" end @@ -696,7 +696,7 @@ class NamedTests end assert('CompressedRequest probe failed') do - bad_status_occured + bad_status_occurred end end diff --git a/src/ruby/spec/call_credentials_spec.rb b/src/ruby/spec/call_credentials_spec.rb index 86f30b46f1..d949ba2235 100644 --- a/src/ruby/spec/call_credentials_spec.rb +++ b/src/ruby/spec/call_credentials_spec.rb @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'grpc' +require 'spec_helper' describe GRPC::Core::CallCredentials do CallCredentials = GRPC::Core::CallCredentials diff --git a/src/ruby/spec/call_spec.rb b/src/ruby/spec/call_spec.rb index 1cc0500242..22d345f658 100644 --- a/src/ruby/spec/call_spec.rb +++ b/src/ruby/spec/call_spec.rb @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'grpc' +require 'spec_helper' include GRPC::Core::StatusCodes diff --git a/src/ruby/spec/channel_credentials_spec.rb b/src/ruby/spec/channel_credentials_spec.rb index e53f316208..b05e5aebf8 100644 --- a/src/ruby/spec/channel_credentials_spec.rb +++ b/src/ruby/spec/channel_credentials_spec.rb @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'grpc' +require 'spec_helper' describe GRPC::Core::ChannelCredentials do ChannelCredentials = GRPC::Core::ChannelCredentials diff --git a/src/ruby/spec/channel_spec.rb b/src/ruby/spec/channel_spec.rb index 5b2e355963..adba6db99c 100644 --- a/src/ruby/spec/channel_spec.rb +++ b/src/ruby/spec/channel_spec.rb @@ -12,7 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'grpc' +require 'spec_helper' +require 'English' def load_test_certs test_root = File.join(File.dirname(__FILE__), 'testdata') @@ -27,6 +28,28 @@ describe GRPC::Core::Channel do GRPC::Core::ChannelCredentials.new(load_test_certs[0]) end + def fork_with_propagated_error_message + pipe_read, pipe_write = IO.pipe + pid = fork do + pipe_read.close + begin + yield + rescue => exc + pipe_write.syswrite(exc.message) + end + pipe_write.close + end + pipe_write.close + + exc_message = pipe_read.read + Process.wait(pid) + + unless $CHILD_STATUS.success? + raise "forked process failed with #{$CHILD_STATUS}" + end + raise exc_message unless exc_message.empty? + end + shared_examples '#new' do it 'take a host name without channel args' do blk = proc do @@ -79,6 +102,14 @@ describe GRPC::Core::Channel do blk = construct_with_args(args) expect(&blk).to_not raise_error end + + it 'raises if grpc was initialized in another process' do + blk = construct_with_args({}) + expect(&blk).not_to raise_error + expect do + fork_with_propagated_error_message(&blk) + end.to raise_error(RuntimeError, 'grpc cannot be used before and after forking') + end end describe '#new for secure channels' do @@ -121,6 +152,19 @@ describe GRPC::Core::Channel do end expect(&blk).to raise_error(RuntimeError) end + + it 'raises if grpc was initialized in another process' do + ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure) + + deadline = Time.now + 5 + + blk = proc do + fork_with_propagated_error_message do + ch.create_call(nil, nil, 'dummy_method', nil, deadline) + end + end + expect(&blk).to raise_error(RuntimeError, 'grpc cannot be used before and after forking') + end end describe '#destroy' do diff --git a/src/ruby/spec/client_auth_spec.rb b/src/ruby/spec/client_auth_spec.rb index b955ad231e..5d2e6d24ec 100644 --- a/src/ruby/spec/client_auth_spec.rb +++ b/src/ruby/spec/client_auth_spec.rb @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'grpc' +require 'spec_helper' def create_channel_creds test_root = File.join(File.dirname(__FILE__), 'testdata') @@ -30,7 +30,7 @@ end def create_server_creds test_root = File.join(File.dirname(__FILE__), 'testdata') - p "test root: #{test_root}" + GRPC.logger.info("test root: #{test_root}") files = ['ca.pem', 'server1.key', 'server1.pem'] creds = files.map { |f| File.open(File.join(test_root, f)).read } GRPC::Core::ServerCredentials.new( @@ -39,17 +39,6 @@ def create_server_creds true) # force client auth end -# A test message -class EchoMsg - def self.marshal(_o) - '' - end - - def self.unmarshal(_o) - EchoMsg.new - end -end - # a test service that checks the cert of its peer class SslTestService include GRPC::GenericService @@ -70,7 +59,7 @@ class SslTestService def a_client_streaming_rpc(call) check_peer_cert(call) - call.each_remote_read.each { |r| p r } + call.each_remote_read.each { |r| GRPC.logger.info(r) } EchoMsg.new end @@ -81,7 +70,7 @@ class SslTestService def a_bidi_rpc(requests, call) check_peer_cert(call) - requests.each { |r| p r } + requests.each { |r| GRPC.logger.info(r) } [EchoMsg.new, EchoMsg.new] end end @@ -127,11 +116,11 @@ describe 'client-server auth' do it 'client-server auth with server streaming RPCs' do responses = @stub.a_server_streaming_rpc(EchoMsg.new) - responses.each { |r| p r } + responses.each { |r| GRPC.logger.info(r) } end it 'client-server auth with bidi RPCs' do responses = @stub.a_bidi_rpc([EchoMsg.new, EchoMsg.new]) - responses.each { |r| p r } + responses.each { |r| GRPC.logger.info(r) } end end diff --git a/src/ruby/spec/client_server_spec.rb b/src/ruby/spec/client_server_spec.rb index afbfb0bc43..afde5073a6 100644 --- a/src/ruby/spec/client_server_spec.rb +++ b/src/ruby/spec/client_server_spec.rb @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'grpc' +require 'spec_helper' include GRPC::Core diff --git a/src/ruby/spec/compression_options_spec.rb b/src/ruby/spec/compression_options_spec.rb index 03c3cd9f07..05318e6686 100644 --- a/src/ruby/spec/compression_options_spec.rb +++ b/src/ruby/spec/compression_options_spec.rb @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'grpc' +require 'spec_helper' describe GRPC::Core::CompressionOptions do # Note these constants should be updated diff --git a/src/ruby/spec/error_sanity_spec.rb b/src/ruby/spec/error_sanity_spec.rb index b8f0638695..c36635ea26 100644 --- a/src/ruby/spec/error_sanity_spec.rb +++ b/src/ruby/spec/error_sanity_spec.rb @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'grpc' +require 'spec_helper' StatusCodes = GRPC::Core::StatusCodes diff --git a/src/ruby/spec/generic/client_stub_spec.rb b/src/ruby/spec/generic/client_stub_spec.rb index da50f8d0c9..200139d849 100644 --- a/src/ruby/spec/generic/client_stub_spec.rb +++ b/src/ruby/spec/generic/client_stub_spec.rb @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'grpc' +require 'spec_helper' Thread.abort_on_exception = true @@ -265,14 +265,14 @@ describe 'ClientStub' do # rubocop:disable Metrics/BlockLength end creds = GRPC::Core::CallCredentials.new(failing_auth) - unavailable_error_occured = false + unavailable_error_occurred = false begin get_response(stub, credentials: creds) rescue GRPC::Unavailable => e - unavailable_error_occured = true + unavailable_error_occurred = true expect(e.details.include?(error_message)).to be true end - expect(unavailable_error_occured).to eq(true) + expect(unavailable_error_occurred).to eq(true) @server.shutdown_and_notify(Time.now + 3) th.join @@ -293,7 +293,7 @@ describe 'ClientStub' do # rubocop:disable Metrics/BlockLength describe 'without a call operation' do def get_response(stub, credentials: nil) - puts credentials.inspect + GRPC.logger.info(credentials.inspect) stub.request_response(@method, @sent_msg, noop, noop, metadata: @metadata, credentials: credentials) @@ -342,13 +342,15 @@ describe 'ClientStub' do # rubocop:disable Metrics/BlockLength it 'sends metadata to the server ok when running start_call first' do run_op_view_metadata_test(true) check_op_view_of_finished_client_call( - @op, @server_initial_md, @server_trailing_md) { |r| p r } + @op, @server_initial_md, @server_trailing_md + ) { |r| GRPC.logger.info(r) } end it 'does not crash when used after the call has been finished' do run_op_view_metadata_test(false) check_op_view_of_finished_client_call( - @op, @server_initial_md, @server_trailing_md) { |r| p r } + @op, @server_initial_md, @server_trailing_md + ) { |r| GRPC.logger.info(r) } end end end @@ -435,13 +437,15 @@ describe 'ClientStub' do # rubocop:disable Metrics/BlockLength it 'sends metadata to the server ok when running start_call first' do run_op_view_metadata_test(true) check_op_view_of_finished_client_call( - @op, @server_initial_md, @server_trailing_md) { |r| p r } + @op, @server_initial_md, @server_trailing_md + ) { |r| GRPC.logger.info(r) } end it 'does not crash when used after the call has been finished' do run_op_view_metadata_test(false) check_op_view_of_finished_client_call( - @op, @server_initial_md, @server_trailing_md) { |r| p r } + @op, @server_initial_md, @server_trailing_md + ) { |r| GRPC.logger.info(r) } end end end @@ -578,7 +582,7 @@ describe 'ClientStub' do # rubocop:disable Metrics/BlockLength run_op_view_metadata_test(true) check_op_view_of_finished_client_call( @op, @server_initial_md, @server_trailing_md) do |responses| - responses.each { |r| p r } + responses.each { |r| GRPC.logger.info(r) } end end @@ -586,9 +590,21 @@ describe 'ClientStub' do # rubocop:disable Metrics/BlockLength run_op_view_metadata_test(false) check_op_view_of_finished_client_call( @op, @server_initial_md, @server_trailing_md) do |responses| - responses.each { |r| p r } + responses.each { |r| GRPC.logger.info(r) } end end + + it 'raises GRPC::Cancelled after the call has been cancelled' do + server_port = create_test_server + host = "localhost:#{server_port}" + th = run_server_streamer(@sent_msg, @replys, @pass) + stub = GRPC::ClientStub.new(host, :this_channel_is_insecure) + resp = get_responses(stub, run_start_call_first: false) + expect(resp.next).to eq('reply_1') + @op.cancel + expect { resp.next }.to raise_error(GRPC::Cancelled) + th.join + end end end @@ -883,7 +899,7 @@ describe 'ClientStub' do # rubocop:disable Metrics/BlockLength run_op_view_metadata_test(true) check_op_view_of_finished_client_call( @op, @server_initial_md, @server_trailing_md) do |responses| - responses.each { |r| p r } + responses.each { |r| GRPC.logger.info(r) } end end @@ -891,7 +907,7 @@ describe 'ClientStub' do # rubocop:disable Metrics/BlockLength run_op_view_metadata_test(false) check_op_view_of_finished_client_call( @op, @server_initial_md, @server_trailing_md) do |responses| - responses.each { |r| p r } + responses.each { |r| GRPC.logger.info(r) } end end diff --git a/src/ruby/spec/generic/rpc_desc_spec.rb b/src/ruby/spec/generic/rpc_desc_spec.rb index 6852b9804f..b4ffe5eb92 100644 --- a/src/ruby/spec/generic/rpc_desc_spec.rb +++ b/src/ruby/spec/generic/rpc_desc_spec.rb @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'grpc' +require 'spec_helper' require 'grpc/generic/rpc_desc' describe GRPC::RpcDesc do diff --git a/src/ruby/spec/generic/rpc_server_pool_spec.rb b/src/ruby/spec/generic/rpc_server_pool_spec.rb index 27a42c82c1..0f2dac272e 100644 --- a/src/ruby/spec/generic/rpc_server_pool_spec.rb +++ b/src/ruby/spec/generic/rpc_server_pool_spec.rb @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'grpc' +require 'spec_helper' Thread.abort_on_exception = true diff --git a/src/ruby/spec/generic/rpc_server_spec.rb b/src/ruby/spec/generic/rpc_server_spec.rb index e072d0c45f..44a6134086 100644 --- a/src/ruby/spec/generic/rpc_server_spec.rb +++ b/src/ruby/spec/generic/rpc_server_spec.rb @@ -125,7 +125,7 @@ class CheckCallAfterFinishedService fail 'shouldnt reuse service' unless @server_side_call.nil? @server_side_call = call # iterate through requests so call can complete - call.each_remote_read.each { |r| p r } + call.each_remote_read.each { |r| GRPC.logger.info(r) } EchoMsg.new end @@ -138,7 +138,7 @@ class CheckCallAfterFinishedService def a_bidi_rpc(requests, call) fail 'shouldnt reuse service' unless @server_side_call.nil? @server_side_call = call - requests.each { |r| p r } + requests.each { |r| GRPC.logger.info(r) } [EchoMsg.new, EchoMsg.new] end end @@ -560,7 +560,7 @@ describe GRPC::RpcServer do 'connect_k1' => 'connect_v1' } wanted_md.each do |key, value| - puts "key: #{key}" + GRPC.logger.info("key: #{key}") expect(op.metadata[key]).to eq(value) end @srv.stop diff --git a/src/ruby/spec/generic/service_spec.rb b/src/ruby/spec/generic/service_spec.rb index ad1c268d32..57aec89ce5 100644 --- a/src/ruby/spec/generic/service_spec.rb +++ b/src/ruby/spec/generic/service_spec.rb @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'grpc' +require 'spec_helper' require 'grpc/generic/rpc_desc' require 'grpc/generic/service' diff --git a/src/ruby/spec/google_rpc_status_utils_spec.rb b/src/ruby/spec/google_rpc_status_utils_spec.rb index 3263589b6a..740c3794b6 100644 --- a/src/ruby/spec/google_rpc_status_utils_spec.rb +++ b/src/ruby/spec/google_rpc_status_utils_spec.rb @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'grpc' +require 'spec_helper' require_relative '../lib/grpc/google_rpc_status_utils' require_relative '../pb/src/proto/grpc/testing/messages_pb' require_relative '../pb/src/proto/grpc/testing/messages_pb' @@ -114,17 +114,6 @@ describe 'conversion from a status struct to a google protobuf status' do end end -# Test message -class EchoMsg - def self.marshal(_o) - '' - end - - def self.unmarshal(_o) - EchoMsg.new - end -end - # A test service that fills in the "reserved" grpc-status-details-bin trailer, # for client-side testing of GoogleRpcStatus protobuf extraction from trailers. class GoogleRpcStatusTestService diff --git a/src/ruby/spec/pb/codegen/package_option_spec.rb b/src/ruby/spec/pb/codegen/package_option_spec.rb new file mode 100644 index 0000000000..46d23cd651 --- /dev/null +++ b/src/ruby/spec/pb/codegen/package_option_spec.rb @@ -0,0 +1,53 @@ +# 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 'spec_helper' +require 'open3' +require 'tmpdir' + +describe 'Code Generation Options' do + it 'should generate and respect package options' do + fail 'CONFIG env variable unexpectedly unset' unless ENV['CONFIG'] + bins_sub_dir = ENV['CONFIG'] + + src_dir = File.join(File.dirname(__FILE__), '..', '..', '..', '..') + pb_dir = File.join(src_dir, 'proto') + bins_dir = File.join(src_dir, '..', 'bins', bins_sub_dir) + + plugin = File.join(bins_dir, 'grpc_ruby_plugin') + protoc = File.join(bins_dir, 'protobuf', 'protoc') + + # Generate the service from the proto + Dir.mktmpdir(nil, File.dirname(__FILE__)) do |tmp_dir| + gen_file = system(protoc, + '-I.', + 'grpc/testing/package_options.proto', + "--grpc_out=#{tmp_dir}", # generate the service + "--ruby_out=#{tmp_dir}", # generate the definitions + "--plugin=protoc-gen-grpc=#{plugin}", + chdir: pb_dir, + out: File::NULL) + + expect(gen_file).to be_truthy + begin + $LOAD_PATH.push(tmp_dir) + expect { Grpc::Testing::Package::Options::TestService::Service }.to raise_error(NameError) + expect(require('grpc/testing/package_options_services_pb')).to be_truthy + expect { Grpc::Testing::Package::Options::TestService::Service }.to_not raise_error + ensure + $LOAD_PATH.delete(tmp_dir) + end + end + end +end diff --git a/src/ruby/spec/pb/duplicate/codegen_spec.rb b/src/ruby/spec/pb/duplicate/codegen_spec.rb index 9f82858d15..fed7c1c8be 100644 --- a/src/ruby/spec/pb/duplicate/codegen_spec.rb +++ b/src/ruby/spec/pb/duplicate/codegen_spec.rb @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +require 'spec_helper' require 'open3' require 'tmpdir' diff --git a/src/ruby/spec/pb/health/checker_spec.rb b/src/ruby/spec/pb/health/checker_spec.rb index 58a602327c..84e63c2e54 100644 --- a/src/ruby/spec/pb/health/checker_spec.rb +++ b/src/ruby/spec/pb/health/checker_spec.rb @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'grpc' +require 'spec_helper' require 'grpc/health/v1/health_pb' require 'grpc/health/checker' require 'open3' diff --git a/src/ruby/spec/pb/package_with_underscore/checker_spec.rb b/src/ruby/spec/pb/package_with_underscore/checker_spec.rb deleted file mode 100644 index dac7c14a9a..0000000000 --- a/src/ruby/spec/pb/package_with_underscore/checker_spec.rb +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright 2016 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 'open3' -require 'tmpdir' - -describe 'Package with underscore protobuf code generation' do - it 'should have the same content as created by code generation' do - root_dir = File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..') - pb_dir = File.join(root_dir, 'src', 'ruby', 'spec', 'pb') - - fail 'CONFIG env variable unexpectedly unset' unless ENV['CONFIG'] - bins_sub_dir = ENV['CONFIG'] - bins_dir = File.join(root_dir, 'bins', bins_sub_dir) - - plugin = File.join(bins_dir, 'grpc_ruby_plugin') - protoc = File.join(bins_dir, 'protobuf', 'protoc') - - got = nil - - Dir.mktmpdir do |tmp_dir| - gen_out = File.join(tmp_dir, 'package_with_underscore', 'service_services_pb.rb') - - pid = spawn( - protoc, - '-I.', - 'package_with_underscore/service.proto', - "--grpc_out=#{tmp_dir}", - "--plugin=protoc-gen-grpc=#{plugin}", - chdir: pb_dir) - Process.waitpid2(pid) - File.open(gen_out) { |f| got = f.read } - end - - correct_modularized_rpc = 'rpc :TestOne, ' \ - 'Grpc::Testing::PackageWithUnderscore::Data::Request, ' \ - 'Grpc::Testing::PackageWithUnderscore::Data::Response' - expect(got).to include(correct_modularized_rpc) - end -end diff --git a/src/ruby/spec/server_credentials_spec.rb b/src/ruby/spec/server_credentials_spec.rb index 673d832f62..f773a5f701 100644 --- a/src/ruby/spec/server_credentials_spec.rb +++ b/src/ruby/spec/server_credentials_spec.rb @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'grpc' +require 'spec_helper' def load_test_certs test_root = File.join(File.dirname(__FILE__), 'testdata') diff --git a/src/ruby/spec/server_spec.rb b/src/ruby/spec/server_spec.rb index 6eaac5ded1..76038d8b8b 100644 --- a/src/ruby/spec/server_spec.rb +++ b/src/ruby/spec/server_spec.rb @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'grpc' +require 'spec_helper' def load_test_certs test_root = File.join(File.dirname(__FILE__), 'testdata') diff --git a/src/ruby/spec/spec_helper.rb b/src/ruby/spec/spec_helper.rb index 8fe9e6e808..8fe2c16b35 100644 --- a/src/ruby/spec/spec_helper.rb +++ b/src/ruby/spec/spec_helper.rb @@ -31,6 +31,7 @@ end if ENV['COVERAGE_NAME'] require 'rspec' require 'logging' require 'rspec/logging_helper' +require 'grpc' require_relative 'support/services' require_relative 'support/helpers' diff --git a/src/ruby/spec/support/services.rb b/src/ruby/spec/support/services.rb index 27cc8e61ac..6e693f1cde 100644 --- a/src/ruby/spec/support/services.rb +++ b/src/ruby/spec/support/services.rb @@ -13,7 +13,7 @@ # limitations under the License. # Test stubs for various scenarios -require 'grpc' +require 'spec_helper' # A test message class EchoMsg @@ -50,7 +50,9 @@ class EchoService def a_client_streaming_rpc(call) # iterate through requests so call can complete call.output_metadata.update(@trailing_metadata) - call.each_remote_read.each { |r| p r } + call.each_remote_read.each do |r| + GRPC.logger.info(r) + end EchoMsg.new end @@ -61,7 +63,9 @@ class EchoService def a_bidi_rpc(requests, call) call.output_metadata.update(@trailing_metadata) - requests.each { |r| p r } + requests.each do |r| + GRPC.logger.info(r) + end [EchoMsg.new, EchoMsg.new] end end @@ -71,35 +75,37 @@ EchoStub = EchoService.rpc_stub_class # For testing server interceptors class TestServerInterceptor < GRPC::ServerInterceptor def request_response(request:, call:, method:) - p "Received request/response call at method #{method}" \ - " with request #{request} for call #{call}" + GRPC.logger.info("Received request/response call at method #{method}" \ + " with request #{request} for call #{call}") call.output_metadata[:interc] = 'from_request_response' - p "[GRPC::Ok] (#{method.owner.name}.#{method.name})" + GRPC.logger.info("[GRPC::Ok] (#{method.owner.name}.#{method.name})") yield end def client_streamer(call:, method:) call.output_metadata[:interc] = 'from_client_streamer' call.each_remote_read.each do |r| - p "In interceptor: #{r}" + GRPC.logger.info("In interceptor: #{r}") end - p "Received client streamer call at method #{method} for call #{call}" + GRPC.logger.info( + "Received client streamer call at method #{method} for call #{call}" + ) yield end def server_streamer(request:, call:, method:) - p "Received server streamer call at method #{method} with request" \ - " #{request} for call #{call}" + GRPC.logger.info("Received server streamer call at method #{method} with request" \ + " #{request} for call #{call}") call.output_metadata[:interc] = 'from_server_streamer' yield end def bidi_streamer(requests:, call:, method:) requests.each do |r| - p "Bidi request: #{r}" + GRPC.logger.info("Bidi request: #{r}") end - p "Received bidi streamer call at method #{method} with requests" \ - " #{requests} for call #{call}" + GRPC.logger.info("Received bidi streamer call at method #{method} with requests" \ + " #{requests} for call #{call}") call.output_metadata[:interc] = 'from_bidi_streamer' yield end @@ -108,38 +114,38 @@ end # For testing client interceptors class TestClientInterceptor < GRPC::ClientInterceptor def request_response(request:, call:, method:, metadata: {}) - p "Intercepted request/response call at method #{method}" \ + GRPC.logger.info("Intercepted request/response call at method #{method}" \ " with request #{request} for call #{call}" \ - " and metadata: #{metadata}" + " and metadata: #{metadata}") metadata['foo'] = 'bar_from_request_response' yield end def client_streamer(requests:, call:, method:, metadata: {}) - p "Received client streamer call at method #{method}" \ + GRPC.logger.info("Received client streamer call at method #{method}" \ " with requests #{requests} for call #{call}" \ - " and metadata: #{metadata}" + " and metadata: #{metadata}") requests.each do |r| - p "In client interceptor: #{r}" + GRPC.logger.info("In client interceptor: #{r}") end metadata['foo'] = 'bar_from_client_streamer' yield end def server_streamer(request:, call:, method:, metadata: {}) - p "Received server streamer call at method #{method}" \ + GRPC.logger.info("Received server streamer call at method #{method}" \ " with request #{request} for call #{call}" \ - " and metadata: #{metadata}" + " and metadata: #{metadata}") metadata['foo'] = 'bar_from_server_streamer' yield end def bidi_streamer(requests:, call:, method:, metadata: {}) - p "Received bidi streamer call at method #{method}" \ + GRPC.logger.info("Received bidi streamer call at method #{method}" \ "with requests #{requests} for call #{call}" \ - " and metadata: #{metadata}" + " and metadata: #{metadata}") requests.each do |r| - p "In client interceptor: #{r}" + GRPC.logger.info("In client interceptor: #{r}") end metadata['foo'] = 'bar_from_bidi_streamer' yield diff --git a/src/ruby/spec/time_consts_spec.rb b/src/ruby/spec/time_consts_spec.rb index f7afe6b70a..41655ab106 100644 --- a/src/ruby/spec/time_consts_spec.rb +++ b/src/ruby/spec/time_consts_spec.rb @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'grpc' +require 'spec_helper' TimeConsts = GRPC::Core::TimeConsts diff --git a/src/ruby/tools/version.rb b/src/ruby/tools/version.rb index 09d5c82674..03d977c064 100644 --- a/src/ruby/tools/version.rb +++ b/src/ruby/tools/version.rb @@ -14,6 +14,6 @@ module GRPC module Tools - VERSION = '1.13.0.dev' + VERSION = '1.16.0.dev' end end |