diff options
author | Julien Boeuf <jboeuf@google.com> | 2015-11-17 15:05:45 -0800 |
---|---|---|
committer | Julien Boeuf <jboeuf@google.com> | 2015-11-17 15:05:45 -0800 |
commit | 675b5ce861c3de2c741ee1dd71bf8cdd2662eac6 (patch) | |
tree | a63cbd38d47eea554ae5fef9ef931678689afe63 /src/ruby/pb | |
parent | b0d1e3d95f9d7764a186a25db7e16f87be027c66 (diff) | |
parent | ab88da26bad1566d0a0f9a797ec429bd96ae30e2 (diff) |
Merge branch 'master' of github.com:grpc/grpc into core_creds_api_change
Diffstat (limited to 'src/ruby/pb')
-rwxr-xr-x | src/ruby/pb/test/client.rb | 32 | ||||
-rwxr-xr-x | src/ruby/pb/test/server.rb | 62 |
2 files changed, 87 insertions, 7 deletions
diff --git a/src/ruby/pb/test/client.rb b/src/ruby/pb/test/client.rb index 800529fb08..30550d6cc0 100755 --- a/src/ruby/pb/test/client.rb +++ b/src/ruby/pb/test/client.rb @@ -46,6 +46,7 @@ $LOAD_PATH.unshift(pb_dir) unless $LOAD_PATH.include?(pb_dir) $LOAD_PATH.unshift(this_dir) unless $LOAD_PATH.include?(this_dir) require 'optparse' +require 'logger' require 'grpc' require 'googleauth' @@ -59,6 +60,22 @@ require 'signet/ssl_config' AUTH_ENV = Google::Auth::CredentialsLoader::ENV_VAR +# RubyLogger defines a logger for gRPC based on the standard ruby logger. +module RubyLogger + def logger + LOGGER + end + + LOGGER = Logger.new(STDOUT) + LOGGER.level = Logger::INFO +end + +# GRPC is the general RPC module +module GRPC + # Inject the noop #logger if no module-level logger method has been injected. + extend RubyLogger +end + # AssertionError is use to indicate interop test failures. class AssertionError < RuntimeError; end @@ -255,6 +272,12 @@ class NamedTests def per_rpc_creds auth_creds = Google::Auth.get_application_default(@args.oauth_scope) kw = auth_creds.updater_proc.call({}) + + # TODO(jtattermusch): downcase the metadata keys here to make sure + # they are not rejected by C core. This is a hotfix that should + # be addressed by introducing auto-downcasing logic. + kw = Hash[ kw.each_pair.map { |k, v| [k.downcase, v] }] + resp = perform_large_unary(fill_username: true, fill_oauth_scope: true, **kw) @@ -424,12 +447,13 @@ def parse_args test_case_list = test_cases.join(',') opts.on('--test_case CODE', test_cases, {}, 'select a test_case', " (#{test_case_list})") { |v| args['test_case'] = v } - opts.on('-s', '--use_tls', 'require a secure connection?') do |v| - args['secure'] = v + opts.on('--use_tls USE_TLS', ['false', 'true'], + 'require a secure connection?') do |v| + args['secure'] = v == 'true' end - opts.on('-t', '--use_test_ca', + opts.on('--use_test_ca USE_TEST_CA', ['false', 'true'], 'if secure, use the test certificate?') do |v| - args['use_test_ca'] = v + args['use_test_ca'] = v == 'true' end end.parse! _check_args(args) diff --git a/src/ruby/pb/test/server.rb b/src/ruby/pb/test/server.rb index 32934f70ad..67877a191f 100755 --- a/src/ruby/pb/test/server.rb +++ b/src/ruby/pb/test/server.rb @@ -45,6 +45,7 @@ $LOAD_PATH.unshift(pb_dir) unless $LOAD_PATH.include?(pb_dir) $LOAD_PATH.unshift(this_dir) unless $LOAD_PATH.include?(this_dir) require 'forwardable' +require 'logger' require 'optparse' require 'grpc' @@ -53,6 +54,60 @@ require 'test/proto/empty' require 'test/proto/messages' require 'test/proto/test_services' +# DebugIsTruncated extends the default Logger to truncate debug messages +class DebugIsTruncated < Logger + def debug(s) + super(truncate(s, 1024)) + end + + # Truncates a given +text+ after a given <tt>length</tt> if +text+ is longer than <tt>length</tt>: + # + # 'Once upon a time in a world far far away'.truncate(27) + # # => "Once upon a time in a wo..." + # + # Pass a string or regexp <tt>:separator</tt> to truncate +text+ at a natural break: + # + # 'Once upon a time in a world far far away'.truncate(27, separator: ' ') + # # => "Once upon a time in a..." + # + # 'Once upon a time in a world far far away'.truncate(27, separator: /\s/) + # # => "Once upon a time in a..." + # + # The last characters will be replaced with the <tt>:omission</tt> string (defaults to "...") + # for a total length not exceeding <tt>length</tt>: + # + # 'And they found that many people were sleeping better.'.truncate(25, omission: '... (continued)') + # # => "And they f... (continued)" + def truncate(s, truncate_at, options = {}) + return s unless s.length > truncate_at + omission = options[:omission] || '...' + with_extra_room = truncate_at - omission.length + stop = \ + if options[:separator] + rindex(options[:separator], with_extra_room) || with_extra_room + else + with_extra_room + end + "#{s[0, stop]}#{omission}" + end +end + +# RubyLogger defines a logger for gRPC based on the standard ruby logger. +module RubyLogger + def logger + LOGGER + end + + LOGGER = DebugIsTruncated.new(STDOUT) + LOGGER.level = Logger::WARN +end + +# GRPC is the general RPC module +module GRPC + # Inject the noop #logger if no module-level logger method has been injected. + extend RubyLogger +end + # loads the certificates by the test server. def load_test_certs this_dir = File.expand_path(File.dirname(__FILE__)) @@ -113,7 +168,7 @@ class TestTarget < Grpc::Testing::TestService::Service def streaming_input_call(call) sizes = call.each_remote_read.map { |x| x.payload.body.length } - sum = sizes.inject { |s, x| s + x } + sum = sizes.inject(0) { |s, x| s + x } StreamingInputCallResponse.new(aggregated_payload_size: sum) end @@ -168,8 +223,9 @@ def parse_options opts.on('--port PORT', 'server port') do |v| options['port'] = v end - opts.on('-s', '--use_tls', 'require a secure connection?') do |v| - options['secure'] = v + opts.on('--use_tls USE_TLS', ['false', 'true'], + 'require a secure connection?') do |v| + options['secure'] = v == 'true' end end.parse! |