diff options
author | Alexander Polcyn <apolcyn@google.com> | 2016-11-30 08:35:52 -0800 |
---|---|---|
committer | Alexander Polcyn <apolcyn@google.com> | 2016-11-30 10:01:39 -0800 |
commit | 174aa915bae4b379932e4887e26f2953db52b954 (patch) | |
tree | 2ca63f0c207da3f2f3832533b020a33d75a6f21c /src/ruby/spec | |
parent | acacd0d6467109e452e7375f662240c26fca004f (diff) |
change client code to use specific exceptions and throw bad status if
unkown code
Diffstat (limited to 'src/ruby/spec')
-rw-r--r-- | src/ruby/spec/error_sanity_spec.rb | 2 | ||||
-rw-r--r-- | src/ruby/spec/generic/client_stub_spec.rb | 9 | ||||
-rw-r--r-- | src/ruby/spec/generic/rpc_server_spec.rb | 5 | ||||
-rw-r--r-- | src/ruby/spec/pb/health/checker_spec.rb | 8 |
4 files changed, 11 insertions, 13 deletions
diff --git a/src/ruby/spec/error_sanity_spec.rb b/src/ruby/spec/error_sanity_spec.rb index ca2d80e685..77e94a8816 100644 --- a/src/ruby/spec/error_sanity_spec.rb +++ b/src/ruby/spec/error_sanity_spec.rb @@ -40,7 +40,7 @@ describe StatusCodes do StatusCodes.constants.each do |status_name| it 'there is a subclass of BadStatus corresponding to StatusCode: ' \ - "#{name} that has code: #{StatusCodes.const_get(status_name)}" do + "#{status_name} that has code: #{StatusCodes.const_get(status_name)}" do camel_case = upper_snake_to_camel(status_name) error_class = GRPC.const_get(camel_case) # expect the error class to be a subclass of BadStatus diff --git a/src/ruby/spec/generic/client_stub_spec.rb b/src/ruby/spec/generic/client_stub_spec.rb index 9c4e9cbd07..08a171e299 100644 --- a/src/ruby/spec/generic/client_stub_spec.rb +++ b/src/ruby/spec/generic/client_stub_spec.rb @@ -190,15 +190,14 @@ describe 'ClientStub' do end creds = GRPC::Core::CallCredentials.new(failing_auth) - error_occured = false + unauth_error_occured = false begin get_response(stub, credentials: creds) - rescue GRPC::BadStatus => e - error_occured = true - expect(e.code).to eq(GRPC::Core::StatusCodes::UNAUTHENTICATED) + rescue GRPC::Unauthenticated => e + unauth_error_occured = true expect(e.details.include?(error_message)).to be true end - expect(error_occured).to eq(true) + expect(unauth_error_occured).to eq(true) # Kill the server thread so tests can complete th.kill diff --git a/src/ruby/spec/generic/rpc_server_spec.rb b/src/ruby/spec/generic/rpc_server_spec.rb index 31157cf161..1689d2df68 100644 --- a/src/ruby/spec/generic/rpc_server_spec.rb +++ b/src/ruby/spec/generic/rpc_server_spec.rb @@ -414,9 +414,8 @@ describe GRPC::RpcServer do stub = SlowStub.new(alt_host, :this_channel_is_insecure) begin stub.an_rpc(req) - rescue GRPC::BadStatus => e - one_failed_as_unavailable = - e.code == StatusCodes::RESOURCE_EXHAUSTED + rescue GRPC::ResourceExhausted + one_failed_as_unavailable = true end end end diff --git a/src/ruby/spec/pb/health/checker_spec.rb b/src/ruby/spec/pb/health/checker_spec.rb index 1b2fa96827..2cc58f845b 100644 --- a/src/ruby/spec/pb/health/checker_spec.rb +++ b/src/ruby/spec/pb/health/checker_spec.rb @@ -119,7 +119,7 @@ describe Grpc::Health::Checker do subject.check(HCReq.new(service: t[:service]), nil) end expected_msg = /#{StatusCodes::NOT_FOUND}/ - expect(&blk).to raise_error GRPC::BadStatus, expected_msg + expect(&blk).to raise_error GRPC::NotFound, expected_msg end end end @@ -137,7 +137,7 @@ describe Grpc::Health::Checker do subject.check(HCReq.new(service: t[:service]), nil) end expected_msg = /#{StatusCodes::NOT_FOUND}/ - expect(&blk).to raise_error GRPC::BadStatus, expected_msg + expect(&blk).to raise_error GRPC::NotFound, expected_msg end end end @@ -158,7 +158,7 @@ describe Grpc::Health::Checker do subject.check(HCReq.new(service: t[:service]), nil) end expected_msg = /#{StatusCodes::NOT_FOUND}/ - expect(&blk).to raise_error GRPC::BadStatus, expected_msg + expect(&blk).to raise_error GRPC::NotFound, expected_msg end end end @@ -206,7 +206,7 @@ describe Grpc::Health::Checker do stub.check(HCReq.new(service: 'unknown')) end expected_msg = /#{StatusCodes::NOT_FOUND}/ - expect(&blk).to raise_error GRPC::BadStatus, expected_msg + expect(&blk).to raise_error GRPC::NotFound, expected_msg @srv.stop t.join end |