Removes the dependency on Minitest

- replaces it with a simple assertion function
pull/2954/head
Tim Emiola 10 years ago
parent f4ee961bed
commit 19e436dac4
  1. 3
      src/ruby/grpc.gemspec
  2. 128
      src/ruby/pb/test/client.rb

@ -29,9 +29,8 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY s.platform = Gem::Platform::RUBY
s.add_dependency 'google-protobuf', '~> 3.0.0alpha.1.1' s.add_dependency 'google-protobuf', '~> 3.0.0alpha.1.1'
s.add_dependency 'googleauth', '~> 0.4' # reqd for interop tests s.add_dependency 'googleauth', '~> 0.4'
s.add_dependency 'logging', '~> 2.0' s.add_dependency 'logging', '~> 2.0'
s.add_dependency 'minitest', '~> 5.4' # reqd for interop tests
s.add_development_dependency 'simplecov', '~> 0.9' s.add_development_dependency 'simplecov', '~> 0.9'
s.add_development_dependency 'bundler', '~> 1.9' s.add_development_dependency 'bundler', '~> 1.9'

@ -46,8 +46,6 @@ $LOAD_PATH.unshift(pb_dir) unless $LOAD_PATH.include?(pb_dir)
$LOAD_PATH.unshift(this_dir) unless $LOAD_PATH.include?(this_dir) $LOAD_PATH.unshift(this_dir) unless $LOAD_PATH.include?(this_dir)
require 'optparse' require 'optparse'
require 'minitest'
require 'minitest/assertions'
require 'grpc' require 'grpc'
require 'googleauth' require 'googleauth'
@ -61,6 +59,15 @@ require 'signet/ssl_config'
AUTH_ENV = Google::Auth::CredentialsLoader::ENV_VAR AUTH_ENV = Google::Auth::CredentialsLoader::ENV_VAR
# AssertionError is use to indicate interop test failures.
class AssertionError < RuntimeError; end
# Fails with AssertionError if the block does evaluate to true
def assert(msg = 'unknown cause')
fail 'No assertion block provided' unless block_given?
fail AssertionError, msg unless yield
end
# loads the certificates used to access the test server securely. # loads the certificates used to access the test server securely.
def load_test_certs def load_test_certs
this_dir = File.expand_path(File.dirname(__FILE__)) this_dir = File.expand_path(File.dirname(__FILE__))
@ -141,10 +148,8 @@ end
# a PingPongPlayer implements the ping pong bidi test. # a PingPongPlayer implements the ping pong bidi test.
class PingPongPlayer class PingPongPlayer
include Minitest::Assertions
include Grpc::Testing include Grpc::Testing
include Grpc::Testing::PayloadType include Grpc::Testing::PayloadType
attr_accessor :assertions # required by Minitest::Assertions
attr_accessor :queue attr_accessor :queue
attr_accessor :canceller_op attr_accessor :canceller_op
@ -152,7 +157,6 @@ class PingPongPlayer
def initialize(msg_sizes) def initialize(msg_sizes)
@queue = Queue.new @queue = Queue.new
@msg_sizes = msg_sizes @msg_sizes = msg_sizes
@assertions = 0 # required by Minitest::Assertions
@canceller_op = nil # used to cancel after the first response @canceller_op = nil # used to cancel after the first response
end end
@ -167,9 +171,10 @@ class PingPongPlayer
response_parameters: [p_cls.new(size: resp_size)]) response_parameters: [p_cls.new(size: resp_size)])
yield req yield req
resp = @queue.pop resp = @queue.pop
assert_equal(:COMPRESSABLE, resp.payload.type, 'payload type is wrong') assert('payload type is wrong') { :COMPRESSABLE == resp.payload.type }
assert_equal(resp_size, resp.payload.body.length, assert("payload body #{count} has the wrong length") do
"payload body #{count} has the wrong length") resp_size == resp.payload.body.length
end
p "OK: ping_pong #{count}" p "OK: ping_pong #{count}"
count += 1 count += 1
unless @canceller_op.nil? unless @canceller_op.nil?
@ -182,20 +187,17 @@ end
# defines methods corresponding to each interop test case. # defines methods corresponding to each interop test case.
class NamedTests class NamedTests
include Minitest::Assertions
include Grpc::Testing include Grpc::Testing
include Grpc::Testing::PayloadType include Grpc::Testing::PayloadType
attr_accessor :assertions # required by Minitest::Assertions
def initialize(stub, args) def initialize(stub, args)
@assertions = 0 # required by Minitest::Assertions
@stub = stub @stub = stub
@args = args @args = args
end end
def empty_unary def empty_unary
resp = @stub.empty_call(Empty.new) resp = @stub.empty_call(Empty.new)
assert resp.is_a?(Empty), 'empty_unary: invalid response' assert('empty_unary: invalid response') { resp.is_a?(Empty) }
p 'OK: empty_unary' p 'OK: empty_unary'
end end
@ -214,28 +216,28 @@ class NamedTests
wanted_email = MultiJson.load(json_key)['client_email'] wanted_email = MultiJson.load(json_key)['client_email']
resp = perform_large_unary(fill_username: true, resp = perform_large_unary(fill_username: true,
fill_oauth_scope: true) fill_oauth_scope: true)
assert_equal(wanted_email, resp.username, assert("#{__callee__}: bad username") { wanted_email == resp.username }
'service_account_creds: incorrect username') assert("#{__callee__}: bad oauth scope") do
assert(@args.oauth_scope.include?(resp.oauth_scope), @args.oauth_scope.include?(resp.oauth_scope)
'service_account_creds: incorrect oauth_scope') end
p 'OK: service_account_creds' p "OK: #{__callee__}"
end end
def jwt_token_creds def jwt_token_creds
json_key = File.read(ENV[AUTH_ENV]) json_key = File.read(ENV[AUTH_ENV])
wanted_email = MultiJson.load(json_key)['client_email'] wanted_email = MultiJson.load(json_key)['client_email']
resp = perform_large_unary(fill_username: true) resp = perform_large_unary(fill_username: true)
assert_equal(wanted_email, resp.username, assert("#{__callee__}: bad username") { wanted_email == resp.username }
'service_account_creds: incorrect username') p "OK: #{__callee__}"
p 'OK: jwt_token_creds'
end end
def compute_engine_creds def compute_engine_creds
resp = perform_large_unary(fill_username: true, resp = perform_large_unary(fill_username: true,
fill_oauth_scope: true) fill_oauth_scope: true)
assert_equal(@args.default_service_account, resp.username, assert("#{__callee__}: bad username") do
'compute_engine_creds: incorrect username') @args.default_service_account == resp.username
p 'OK: compute_engine_creds' end
p "OK: #{__callee__}"
end end
def oauth2_auth_token def oauth2_auth_token
@ -243,10 +245,10 @@ class NamedTests
fill_oauth_scope: true) fill_oauth_scope: true)
json_key = File.read(ENV[AUTH_ENV]) json_key = File.read(ENV[AUTH_ENV])
wanted_email = MultiJson.load(json_key)['client_email'] wanted_email = MultiJson.load(json_key)['client_email']
assert_equal(wanted_email, resp.username, assert("#{__callee__}: bad username") { wanted_email == resp.username }
"#{__callee__}: incorrect username") assert("#{__callee__}: bad oauth scope") do
assert(@args.oauth_scope.include?(resp.oauth_scope), @args.oauth_scope.include?(resp.oauth_scope)
"#{__callee__}: incorrect oauth_scope") end
p "OK: #{__callee__}" p "OK: #{__callee__}"
end end
@ -258,10 +260,10 @@ class NamedTests
**kw) **kw)
json_key = File.read(ENV[AUTH_ENV]) json_key = File.read(ENV[AUTH_ENV])
wanted_email = MultiJson.load(json_key)['client_email'] wanted_email = MultiJson.load(json_key)['client_email']
assert_equal(wanted_email, resp.username, assert("#{__callee__}: bad username") { wanted_email == resp.username }
"#{__callee__}: incorrect username") assert("#{__callee__}: bad oauth scope") do
assert(@args.oauth_scope.include?(resp.oauth_scope), @args.oauth_scope.include?(resp.oauth_scope)
"#{__callee__}: incorrect oauth_scope") end
p "OK: #{__callee__}" p "OK: #{__callee__}"
end end
@ -273,9 +275,10 @@ class NamedTests
StreamingInputCallRequest.new(payload: req) StreamingInputCallRequest.new(payload: req)
end end
resp = @stub.streaming_input_call(reqs) resp = @stub.streaming_input_call(reqs)
assert_equal(wanted_aggregate_size, resp.aggregated_payload_size, assert("#{__callee__}: aggregate payload size is incorrect") do
'client_streaming: aggregate payload size is incorrect') wanted_aggregate_size == resp.aggregated_payload_size
p 'OK: client_streaming' end
p "OK: #{__callee__}"
end end
def server_streaming def server_streaming
@ -285,13 +288,15 @@ class NamedTests
response_parameters: response_spec) response_parameters: response_spec)
resps = @stub.streaming_output_call(req) resps = @stub.streaming_output_call(req)
resps.each_with_index do |r, i| resps.each_with_index do |r, i|
assert i < msg_sizes.length, 'too many responses' assert("#{__callee__}: too many responses") { i < msg_sizes.length }
assert_equal(:COMPRESSABLE, r.payload.type, assert("#{__callee__}: payload body #{i} has the wrong length") do
'payload type is wrong') msg_sizes[i] == r.payload.body.length
assert_equal(msg_sizes[i], r.payload.body.length, end
'payload body #{i} has the wrong length') assert("#{__callee__}: payload type is wrong") do
:COMPRESSABLE == r.payload.type
end
end end
p 'OK: server_streaming' p "OK: #{__callee__}"
end end
def ping_pong def ping_pong
@ -299,7 +304,7 @@ class NamedTests
ppp = PingPongPlayer.new(msg_sizes) ppp = PingPongPlayer.new(msg_sizes)
resps = @stub.full_duplex_call(ppp.each_item) resps = @stub.full_duplex_call(ppp.each_item)
resps.each { |r| ppp.queue.push(r) } resps.each { |r| ppp.queue.push(r) }
p 'OK: ping_pong' p "OK: #{__callee__}"
end end
def timeout_on_sleeping_server def timeout_on_sleeping_server
@ -309,7 +314,9 @@ class NamedTests
resps.each { |r| ppp.queue.push(r) } resps.each { |r| ppp.queue.push(r) }
fail 'Should have raised GRPC::BadStatus(DEADLINE_EXCEEDED)' fail 'Should have raised GRPC::BadStatus(DEADLINE_EXCEEDED)'
rescue GRPC::BadStatus => e rescue GRPC::BadStatus => e
assert_equal(e.code, GRPC::Core::StatusCodes::DEADLINE_EXCEEDED) assert("#{__callee__}: status was wrong") do
e.code == GRPC::Core::StatusCodes::DEADLINE_EXCEEDED
end
p "OK: #{__callee__}" p "OK: #{__callee__}"
end end
@ -321,8 +328,10 @@ class NamedTests
ppp.queue.push(r) ppp.queue.push(r)
count += 1 count += 1
end end
assert_equal(0, count, 'too many responses, expect 0') assert("#{__callee__}: too many responses expected 0") do
p 'OK: empty_stream' count == 0
end
p "OK: #{__callee__}"
end end
def cancel_after_begin def cancel_after_begin
@ -333,9 +342,11 @@ class NamedTests
end end
op = @stub.streaming_input_call(reqs, return_op: true) op = @stub.streaming_input_call(reqs, return_op: true)
op.cancel op.cancel
assert_raises(GRPC::Cancelled) { op.execute } op.execute
assert(op.cancelled, 'call operation should be CANCELLED') fail 'Should have raised GRPC:Cancelled'
p 'OK: cancel_after_begin' rescue GRPC::Cancelled
assert("#{__callee__}: call operation should be CANCELLED") { op.cancelled }
p "OK: #{__callee__}"
end end
def cancel_after_first_response def cancel_after_first_response
@ -343,10 +354,12 @@ class NamedTests
ppp = PingPongPlayer.new(msg_sizes) ppp = PingPongPlayer.new(msg_sizes)
op = @stub.full_duplex_call(ppp.each_item, return_op: true) op = @stub.full_duplex_call(ppp.each_item, return_op: true)
ppp.canceller_op = op # causes ppp to cancel after the 1st message ppp.canceller_op = op # causes ppp to cancel after the 1st message
assert_raises(GRPC::Cancelled) { op.execute.each { |r| ppp.queue.push(r) } } op.execute.each { |r| ppp.queue.push(r) }
fail 'Should have raised GRPC:Cancelled'
rescue GRPC::Cancelled
assert("#{__callee__}: call operation should be CANCELLED") { op.cancelled }
op.wait op.wait
assert(op.cancelled, 'call operation was not CANCELLED') p "OK: #{__callee__}"
p 'OK: cancel_after_first_response'
end end
def all def all
@ -369,12 +382,15 @@ class NamedTests
req.fill_username = fill_username req.fill_username = fill_username
req.fill_oauth_scope = fill_oauth_scope req.fill_oauth_scope = fill_oauth_scope
resp = @stub.unary_call(req, **kw) resp = @stub.unary_call(req, **kw)
assert_equal(:COMPRESSABLE, resp.payload.type, assert('payload type is wrong') do
'large_unary: payload had the wrong type') :COMPRESSABLE == resp.payload.type
assert_equal(wanted_response_size, resp.payload.body.length, end
'large_unary: payload had the wrong length') assert('payload body has the wrong length') do
assert_equal(nulls(wanted_response_size), resp.payload.body, wanted_response_size == resp.payload.body.length
'large_unary: payload content is invalid') end
assert('payload body is invalid') do
nulls(wanted_response_size) == resp.payload.body
end
resp resp
end end
end end

Loading…
Cancel
Save