grpc 1.74.0.pre2-x86_64-linux-gnu
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/etc/roots.pem +4337 -0
- data/grpc_c.32-msvcrt.ruby +0 -0
- data/grpc_c.64-ucrt.ruby +0 -0
- data/src/ruby/bin/math_client.rb +140 -0
- data/src/ruby/bin/math_pb.rb +19 -0
- data/src/ruby/bin/math_server.rb +191 -0
- data/src/ruby/bin/math_services_pb.rb +51 -0
- data/src/ruby/bin/noproto_client.rb +93 -0
- data/src/ruby/bin/noproto_server.rb +97 -0
- data/src/ruby/ext/grpc/ext-export-truffleruby-with-ruby-abi-version.clang +2 -0
- data/src/ruby/ext/grpc/ext-export-truffleruby-with-ruby-abi-version.gcc +7 -0
- data/src/ruby/ext/grpc/ext-export-with-ruby-abi-version.clang +2 -0
- data/src/ruby/ext/grpc/ext-export-with-ruby-abi-version.gcc +7 -0
- data/src/ruby/ext/grpc/ext-export.clang +1 -0
- data/src/ruby/ext/grpc/ext-export.gcc +6 -0
- data/src/ruby/ext/grpc/extconf.rb +269 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.c +65 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.h +35 -0
- data/src/ruby/ext/grpc/rb_call.c +1075 -0
- data/src/ruby/ext/grpc/rb_call.h +57 -0
- data/src/ruby/ext/grpc/rb_call_credentials.c +347 -0
- data/src/ruby/ext/grpc/rb_call_credentials.h +32 -0
- data/src/ruby/ext/grpc/rb_channel.c +391 -0
- data/src/ruby/ext/grpc/rb_channel.h +32 -0
- data/src/ruby/ext/grpc/rb_channel_args.c +174 -0
- data/src/ruby/ext/grpc/rb_channel_args.h +42 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.c +285 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.h +36 -0
- data/src/ruby/ext/grpc/rb_completion_queue.c +95 -0
- data/src/ruby/ext/grpc/rb_completion_queue.h +36 -0
- data/src/ruby/ext/grpc/rb_compression_options.c +469 -0
- data/src/ruby/ext/grpc/rb_compression_options.h +29 -0
- data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
- data/src/ruby/ext/grpc/rb_event_thread.c +167 -0
- data/src/ruby/ext/grpc/rb_event_thread.h +22 -0
- data/src/ruby/ext/grpc/rb_grpc.c +500 -0
- data/src/ruby/ext/grpc/rb_grpc.h +88 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +597 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +902 -0
- data/src/ruby/ext/grpc/rb_loader.c +57 -0
- data/src/ruby/ext/grpc/rb_loader.h +25 -0
- data/src/ruby/ext/grpc/rb_server.c +406 -0
- data/src/ruby/ext/grpc/rb_server.h +32 -0
- data/src/ruby/ext/grpc/rb_server_credentials.c +259 -0
- data/src/ruby/ext/grpc/rb_server_credentials.h +37 -0
- data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +217 -0
- data/src/ruby/ext/grpc/rb_xds_channel_credentials.h +36 -0
- data/src/ruby/ext/grpc/rb_xds_server_credentials.c +170 -0
- data/src/ruby/ext/grpc/rb_xds_server_credentials.h +37 -0
- data/src/ruby/lib/grpc/3.1/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/3.2/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/3.3/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/3.4/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
- data/src/ruby/lib/grpc/core/time_consts.rb +56 -0
- data/src/ruby/lib/grpc/errors.rb +277 -0
- data/src/ruby/lib/grpc/generic/active_call.rb +679 -0
- data/src/ruby/lib/grpc/generic/bidi_call.rb +237 -0
- data/src/ruby/lib/grpc/generic/client_stub.rb +503 -0
- data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
- data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
- data/src/ruby/lib/grpc/generic/rpc_desc.rb +204 -0
- data/src/ruby/lib/grpc/generic/rpc_server.rb +551 -0
- data/src/ruby/lib/grpc/generic/service.rb +211 -0
- data/src/ruby/lib/grpc/google_rpc_status_utils.rb +40 -0
- data/src/ruby/lib/grpc/grpc.rb +24 -0
- data/src/ruby/lib/grpc/logconfig.rb +57 -0
- data/src/ruby/lib/grpc/notifier.rb +45 -0
- data/src/ruby/lib/grpc/structs.rb +15 -0
- data/src/ruby/lib/grpc/version.rb +18 -0
- data/src/ruby/lib/grpc.rb +37 -0
- data/src/ruby/pb/README.md +42 -0
- data/src/ruby/pb/generate_proto_ruby.sh +46 -0
- data/src/ruby/pb/grpc/health/checker.rb +75 -0
- data/src/ruby/pb/grpc/health/v1/health_pb.rb +21 -0
- data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +62 -0
- data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +44 -0
- data/src/ruby/pb/grpc/testing/metrics_pb.rb +19 -0
- data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +49 -0
- data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +17 -0
- data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +50 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +19 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +174 -0
- data/src/ruby/pb/test/client.rb +785 -0
- data/src/ruby/pb/test/server.rb +252 -0
- data/src/ruby/pb/test/xds_client.rb +415 -0
- data/src/ruby/spec/call_credentials_spec.rb +42 -0
- data/src/ruby/spec/call_spec.rb +193 -0
- data/src/ruby/spec/channel_connection_spec.rb +126 -0
- data/src/ruby/spec/channel_credentials_spec.rb +124 -0
- data/src/ruby/spec/channel_spec.rb +209 -0
- data/src/ruby/spec/client_auth_spec.rb +152 -0
- data/src/ruby/spec/client_server_spec.rb +317 -0
- data/src/ruby/spec/compression_options_spec.rb +149 -0
- data/src/ruby/spec/core_spec.rb +22 -0
- data/src/ruby/spec/debug_message_spec.rb +134 -0
- data/src/ruby/spec/error_sanity_spec.rb +49 -0
- data/src/ruby/spec/errors_spec.rb +142 -0
- data/src/ruby/spec/generic/active_call_spec.rb +670 -0
- data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
- data/src/ruby/spec/generic/client_stub_spec.rb +1079 -0
- data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
- data/src/ruby/spec/generic/rpc_desc_spec.rb +374 -0
- data/src/ruby/spec/generic/rpc_server_pool_spec.rb +127 -0
- data/src/ruby/spec/generic/rpc_server_spec.rb +773 -0
- data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
- data/src/ruby/spec/generic/service_spec.rb +263 -0
- data/src/ruby/spec/google_rpc_status_utils_spec.rb +282 -0
- data/src/ruby/spec/logconfig_spec.rb +30 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options.proto +28 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import2.proto +23 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +41 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto +27 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto +29 -0
- data/src/ruby/spec/pb/codegen/package_option_spec.rb +98 -0
- data/src/ruby/spec/pb/duplicate/codegen_spec.rb +57 -0
- data/src/ruby/spec/pb/health/checker_spec.rb +236 -0
- data/src/ruby/spec/server_credentials_spec.rb +104 -0
- data/src/ruby/spec/server_spec.rb +231 -0
- data/src/ruby/spec/spec_helper.rb +61 -0
- data/src/ruby/spec/support/helpers.rb +107 -0
- data/src/ruby/spec/support/services.rb +163 -0
- data/src/ruby/spec/testdata/README +1 -0
- data/src/ruby/spec/testdata/ca.pem +20 -0
- data/src/ruby/spec/testdata/client.key +28 -0
- data/src/ruby/spec/testdata/client.pem +20 -0
- data/src/ruby/spec/testdata/server1.key +28 -0
- data/src/ruby/spec/testdata/server1.pem +22 -0
- data/src/ruby/spec/time_consts_spec.rb +74 -0
- data/src/ruby/spec/user_agent_spec.rb +74 -0
- metadata +411 -0
@@ -0,0 +1,134 @@
|
|
1
|
+
# Copyright 2015 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'spec_helper'
|
16
|
+
|
17
|
+
TEST_DEBUG_MESSAGE = 'raised by test server'.freeze
|
18
|
+
|
19
|
+
# a test service that checks the cert of its peer
|
20
|
+
class DebugMessageTestService
|
21
|
+
include GRPC::GenericService
|
22
|
+
rpc :an_rpc_raises_abort, EchoMsg, EchoMsg
|
23
|
+
rpc :an_rpc_raises_standarderror, EchoMsg, EchoMsg
|
24
|
+
|
25
|
+
def an_rpc_raises_abort(_req, _call)
|
26
|
+
fail GRPC::Aborted.new(
|
27
|
+
'aborted',
|
28
|
+
{},
|
29
|
+
TEST_DEBUG_MESSAGE)
|
30
|
+
end
|
31
|
+
|
32
|
+
def an_rpc_raises_standarderror(_req, _call)
|
33
|
+
fail(StandardError, TEST_DEBUG_MESSAGE)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
DebugMessageTestServiceStub = DebugMessageTestService.rpc_stub_class
|
38
|
+
|
39
|
+
describe 'surfacing and transmitting of debug messages' do
|
40
|
+
RpcServer = GRPC::RpcServer
|
41
|
+
|
42
|
+
before(:all) do
|
43
|
+
server_opts = {
|
44
|
+
poll_period: 1
|
45
|
+
}
|
46
|
+
@srv = new_rpc_server_for_testing(**server_opts)
|
47
|
+
@port = @srv.add_http2_port('0.0.0.0:0', :this_port_is_insecure)
|
48
|
+
@srv.handle(DebugMessageTestService)
|
49
|
+
@srv_thd = Thread.new { @srv.run }
|
50
|
+
@srv.wait_till_running
|
51
|
+
end
|
52
|
+
|
53
|
+
after(:all) do
|
54
|
+
expect(@srv.stopped?).to be(false)
|
55
|
+
@srv.stop
|
56
|
+
@srv_thd.join
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'debug error message is not present BadStatus exceptions that dont set it' do
|
60
|
+
exception_message = ''
|
61
|
+
begin
|
62
|
+
fail GRPC::Unavailable('unavailable', {})
|
63
|
+
rescue StandardError => e
|
64
|
+
p "Got exception: #{e.message}"
|
65
|
+
exception_message = e.message
|
66
|
+
end
|
67
|
+
expect(exception_message.empty?).to be(false)
|
68
|
+
expect(exception_message.include?('debug_error_string')).to be(false)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'debug error message is present in locally generated errors' do
|
72
|
+
# Create a secure channel. This is just one way to force a
|
73
|
+
# connection handshake error, which shoud result in C-core
|
74
|
+
# generating a status and error message and surfacing them up.
|
75
|
+
test_root = File.join(File.dirname(__FILE__), 'testdata')
|
76
|
+
files = ['ca.pem', 'client.key', 'client.pem']
|
77
|
+
creds = files.map { |f| File.open(File.join(test_root, f)).read }
|
78
|
+
creds = GRPC::Core::ChannelCredentials.new(creds[0], creds[1], creds[2])
|
79
|
+
stub = DebugMessageTestServiceStub.new(
|
80
|
+
"localhost:#{@port}", creds)
|
81
|
+
begin
|
82
|
+
stub.an_rpc_raises_abort(EchoMsg.new)
|
83
|
+
rescue StandardError => e
|
84
|
+
p "Got exception: #{e.message}"
|
85
|
+
exception_message = e.message
|
86
|
+
# check that the RPC did actually result in a BadStatus exception
|
87
|
+
expect(e.is_a?(GRPC::BadStatus)).to be(true)
|
88
|
+
end
|
89
|
+
# just check that the debug_error_string is non-empty (we know that
|
90
|
+
# it's a JSON object, so the first character is '{').
|
91
|
+
expect(exception_message.include?('. debug_error_string:{')).to be(true)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'debug message is not transmitted from server to client' do
|
95
|
+
# in order to not accidentally leak internal details about a
|
96
|
+
# server to untrusted clients, avoid including the debug_error_string
|
97
|
+
# field of a BadStatusException raised at a server in the
|
98
|
+
# RPC status that it sends to clients.
|
99
|
+
stub = DebugMessageTestServiceStub.new(
|
100
|
+
"localhost:#{@port}", :this_channel_is_insecure)
|
101
|
+
exception_message = ''
|
102
|
+
begin
|
103
|
+
stub.an_rpc_raises_abort(EchoMsg.new)
|
104
|
+
rescue StandardError => e
|
105
|
+
p "Got exception: #{e.message}"
|
106
|
+
exception_message = e.message
|
107
|
+
# check that the status was aborted is an indirect way to
|
108
|
+
# tell that the RPC did actually get handled by the server
|
109
|
+
expect(e.is_a?(GRPC::Aborted)).to be(true)
|
110
|
+
end
|
111
|
+
# just assert that the contents of the server-side BadStatus
|
112
|
+
# debug_error_string field were *not* propagated to the client.
|
113
|
+
expect(exception_message.include?('. debug_error_string:{')).to be(true)
|
114
|
+
expect(exception_message.include?(TEST_DEBUG_MESSAGE)).to be(false)
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'standard_error messages are transmitted from server to client' do
|
118
|
+
# this test exists mostly in order to understand the test case
|
119
|
+
# above, by comparison.
|
120
|
+
stub = DebugMessageTestServiceStub.new(
|
121
|
+
"localhost:#{@port}", :this_channel_is_insecure)
|
122
|
+
exception_message = ''
|
123
|
+
begin
|
124
|
+
stub.an_rpc_raises_standarderror(EchoMsg.new)
|
125
|
+
rescue StandardError => e
|
126
|
+
p "Got exception: #{e.message}"
|
127
|
+
exception_message = e.message
|
128
|
+
expect(e.is_a?(GRPC::BadStatus)).to be(true)
|
129
|
+
end
|
130
|
+
# assert that the contents of the StandardError exception message
|
131
|
+
# are propagated to the client.
|
132
|
+
expect(exception_message.include?(TEST_DEBUG_MESSAGE)).to be(true)
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# Copyright 2015 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'spec_helper'
|
16
|
+
|
17
|
+
StatusCodes = GRPC::Core::StatusCodes
|
18
|
+
|
19
|
+
describe StatusCodes do
|
20
|
+
# convert upper snake-case to camel case.
|
21
|
+
# e.g., DEADLINE_EXCEEDED -> DeadlineExceeded
|
22
|
+
def upper_snake_to_camel(name)
|
23
|
+
name.to_s.split('_').map(&:downcase).map(&:capitalize).join('')
|
24
|
+
end
|
25
|
+
|
26
|
+
StatusCodes.constants.each do |status_name|
|
27
|
+
it 'there is a subclass of BadStatus corresponding to StatusCode: ' \
|
28
|
+
"#{status_name} that has code: #{StatusCodes.const_get(status_name)}" do
|
29
|
+
camel_case = upper_snake_to_camel(status_name)
|
30
|
+
error_class = GRPC.const_get(camel_case)
|
31
|
+
# expect the error class to be a subclass of BadStatus
|
32
|
+
expect(error_class < GRPC::BadStatus)
|
33
|
+
|
34
|
+
error_object = error_class.new
|
35
|
+
# check that the code matches the int value of the error's constant
|
36
|
+
status_code = StatusCodes.const_get(status_name)
|
37
|
+
expect(error_object.code).to eq(status_code)
|
38
|
+
|
39
|
+
# check default parameters
|
40
|
+
expect(error_object.details).to eq('unknown cause')
|
41
|
+
expect(error_object.metadata).to eq({})
|
42
|
+
|
43
|
+
# check that the BadStatus factory for creates the correct
|
44
|
+
# exception too
|
45
|
+
from_factory = GRPC::BadStatus.new_status_exception(status_code)
|
46
|
+
expect(from_factory.is_a?(error_class)).to be(true)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
# Copyright 2015 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'spec_helper'
|
16
|
+
require 'google/protobuf/well_known_types'
|
17
|
+
require 'google/rpc/status_pb'
|
18
|
+
require_relative '../pb/src/proto/grpc/testing/messages_pb'
|
19
|
+
|
20
|
+
describe GRPC::BadStatus do
|
21
|
+
describe :attributes do
|
22
|
+
it 'has attributes' do
|
23
|
+
code = 1
|
24
|
+
details = 'details'
|
25
|
+
metadata = { 'key' => 'val' }
|
26
|
+
|
27
|
+
exception = GRPC::BadStatus.new(code, details, metadata)
|
28
|
+
|
29
|
+
expect(exception.code).to eq code
|
30
|
+
expect(exception.details).to eq details
|
31
|
+
expect(exception.metadata).to eq metadata
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe :new_status_exception do
|
36
|
+
let(:codes_and_classes) do
|
37
|
+
[
|
38
|
+
[GRPC::Core::StatusCodes::OK, GRPC::Ok],
|
39
|
+
[GRPC::Core::StatusCodes::CANCELLED, GRPC::Cancelled],
|
40
|
+
[GRPC::Core::StatusCodes::UNKNOWN, GRPC::Unknown],
|
41
|
+
[GRPC::Core::StatusCodes::INVALID_ARGUMENT, GRPC::InvalidArgument],
|
42
|
+
[GRPC::Core::StatusCodes::DEADLINE_EXCEEDED, GRPC::DeadlineExceeded],
|
43
|
+
[GRPC::Core::StatusCodes::NOT_FOUND, GRPC::NotFound],
|
44
|
+
[GRPC::Core::StatusCodes::ALREADY_EXISTS, GRPC::AlreadyExists],
|
45
|
+
[GRPC::Core::StatusCodes::PERMISSION_DENIED, GRPC::PermissionDenied],
|
46
|
+
[GRPC::Core::StatusCodes::UNAUTHENTICATED, GRPC::Unauthenticated],
|
47
|
+
[GRPC::Core::StatusCodes::RESOURCE_EXHAUSTED, GRPC::ResourceExhausted],
|
48
|
+
[GRPC::Core::StatusCodes::FAILED_PRECONDITION, GRPC::FailedPrecondition],
|
49
|
+
[GRPC::Core::StatusCodes::ABORTED, GRPC::Aborted],
|
50
|
+
[GRPC::Core::StatusCodes::OUT_OF_RANGE, GRPC::OutOfRange],
|
51
|
+
[GRPC::Core::StatusCodes::UNIMPLEMENTED, GRPC::Unimplemented],
|
52
|
+
[GRPC::Core::StatusCodes::INTERNAL, GRPC::Internal],
|
53
|
+
[GRPC::Core::StatusCodes::UNAVAILABLE, GRPC::Unavailable],
|
54
|
+
[GRPC::Core::StatusCodes::DATA_LOSS, GRPC::DataLoss],
|
55
|
+
[99, GRPC::BadStatus] # Unknown codes default to BadStatus
|
56
|
+
]
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'maps codes to the correct error class' do
|
60
|
+
codes_and_classes.each do |code, grpc_error_class|
|
61
|
+
exception = GRPC::BadStatus.new_status_exception(code)
|
62
|
+
|
63
|
+
expect(exception).to be_a grpc_error_class
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe :to_status do
|
69
|
+
it 'gets status' do
|
70
|
+
code = 1
|
71
|
+
details = 'details'
|
72
|
+
metadata = { 'key' => 'val' }
|
73
|
+
|
74
|
+
exception = GRPC::BadStatus.new(code, details, metadata)
|
75
|
+
status = Struct::Status.new(code, details, metadata)
|
76
|
+
|
77
|
+
expect(exception.to_status).to eq status
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe :to_rpc_status do
|
82
|
+
let(:simple_request_any) do
|
83
|
+
Google::Protobuf::Any.new.tap do |any|
|
84
|
+
any.pack(
|
85
|
+
Grpc::Testing::SimpleRequest.new(
|
86
|
+
payload: Grpc::Testing::Payload.new(body: 'request')
|
87
|
+
)
|
88
|
+
)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
let(:simple_response_any) do
|
92
|
+
Google::Protobuf::Any.new.tap do |any|
|
93
|
+
any.pack(
|
94
|
+
Grpc::Testing::SimpleResponse.new(
|
95
|
+
payload: Grpc::Testing::Payload.new(body: 'response')
|
96
|
+
)
|
97
|
+
)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
let(:payload_any) do
|
101
|
+
Google::Protobuf::Any.new.tap do |any|
|
102
|
+
any.pack(Grpc::Testing::Payload.new(body: 'payload'))
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'decodes proto values' do
|
107
|
+
rpc_status = Google::Rpc::Status.new(
|
108
|
+
code: 1,
|
109
|
+
message: 'matching message',
|
110
|
+
details: [simple_request_any, simple_response_any, payload_any]
|
111
|
+
)
|
112
|
+
rpc_status_proto = Google::Rpc::Status.encode(rpc_status)
|
113
|
+
|
114
|
+
code = 1
|
115
|
+
details = 'details'
|
116
|
+
metadata = { 'grpc-status-details-bin' => rpc_status_proto }
|
117
|
+
|
118
|
+
exception = GRPC::BadStatus.new(code, details, metadata)
|
119
|
+
|
120
|
+
expect(exception.to_rpc_status).to eq rpc_status
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'does not raise when decoding a bad proto' do
|
124
|
+
code = 1
|
125
|
+
details = 'details'
|
126
|
+
metadata = { 'grpc-status-details-bin' => 'notavalidprotostream' }
|
127
|
+
|
128
|
+
exception = GRPC::BadStatus.new(code, details, metadata)
|
129
|
+
|
130
|
+
expect(exception.to_rpc_status).to be nil
|
131
|
+
|
132
|
+
error_msg = 'parse error: to_rpc_status failed'
|
133
|
+
error_desc = '<Google::Protobuf::ParseError> ' \
|
134
|
+
'Error occurred during parsing'
|
135
|
+
|
136
|
+
# Check that the parse error was logged correctly
|
137
|
+
log_contents = @log_output.read
|
138
|
+
expect(log_contents).to include "WARN GRPC : #{error_msg}"
|
139
|
+
expect(log_contents).to include "WARN GRPC : #{error_desc}"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|