grpc 1.42.0.pre1-arm64-darwin
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grpc might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/etc/roots.pem +4337 -0
- data/grpc_c.32.ruby +0 -0
- data/grpc_c.64.ruby +0 -0
- data/src/ruby/bin/math_client.rb +140 -0
- data/src/ruby/bin/math_pb.rb +34 -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.clang +1 -0
- data/src/ruby/ext/grpc/ext-export.gcc +6 -0
- data/src/ruby/ext/grpc/extconf.rb +123 -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 +1051 -0
- data/src/ruby/ext/grpc/rb_call.h +57 -0
- data/src/ruby/ext/grpc/rb_call_credentials.c +341 -0
- data/src/ruby/ext/grpc/rb_call_credentials.h +31 -0
- data/src/ruby/ext/grpc/rb_channel.c +846 -0
- data/src/ruby/ext/grpc/rb_channel.h +34 -0
- data/src/ruby/ext/grpc/rb_channel_args.c +155 -0
- data/src/ruby/ext/grpc/rb_channel_args.h +38 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.c +286 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.h +37 -0
- data/src/ruby/ext/grpc/rb_completion_queue.c +101 -0
- data/src/ruby/ext/grpc/rb_completion_queue.h +36 -0
- data/src/ruby/ext/grpc/rb_compression_options.c +471 -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 +145 -0
- data/src/ruby/ext/grpc/rb_event_thread.h +21 -0
- data/src/ruby/ext/grpc/rb_grpc.c +333 -0
- data/src/ruby/ext/grpc/rb_grpc.h +77 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +605 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +913 -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 +385 -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 +218 -0
- data/src/ruby/ext/grpc/rb_xds_channel_credentials.h +37 -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/2.4/grpc_c.bundle +0 -0
- data/src/ruby/lib/grpc/2.5/grpc_c.bundle +0 -0
- data/src/ruby/lib/grpc/2.6/grpc_c.bundle +0 -0
- data/src/ruby/lib/grpc/2.7/grpc_c.bundle +0 -0
- data/src/ruby/lib/grpc/3.0/grpc_c.bundle +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 +669 -0
- data/src/ruby/lib/grpc/generic/bidi_call.rb +233 -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 +44 -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 +51 -0
- data/src/ruby/pb/grpc/health/checker.rb +75 -0
- data/src/ruby/pb/grpc/health/v1/health_pb.rb +31 -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 +28 -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 +145 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +16 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +152 -0
- data/src/ruby/pb/test/client.rb +769 -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 +180 -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 +245 -0
- data/src/ruby/spec/client_auth_spec.rb +152 -0
- data/src/ruby/spec/client_server_spec.rb +664 -0
- data/src/ruby/spec/compression_options_spec.rb +149 -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 +683 -0
- data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
- data/src/ruby/spec/generic/client_stub_spec.rb +1083 -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 +748 -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/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 +160 -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 +404 -0
@@ -0,0 +1,282 @@
|
|
1
|
+
# Copyright 2017 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_relative '../lib/grpc/google_rpc_status_utils'
|
17
|
+
require_relative '../pb/src/proto/grpc/testing/messages_pb'
|
18
|
+
require_relative '../pb/src/proto/grpc/testing/messages_pb'
|
19
|
+
require 'google/protobuf/well_known_types'
|
20
|
+
|
21
|
+
include GRPC::Core
|
22
|
+
include GRPC::Spec::Helpers
|
23
|
+
|
24
|
+
describe 'conversion from a status struct to a google protobuf status' do
|
25
|
+
it 'fails if the input is not a status struct' do
|
26
|
+
begin
|
27
|
+
GRPC::GoogleRpcStatusUtils.extract_google_rpc_status('string')
|
28
|
+
rescue => e
|
29
|
+
exception = e
|
30
|
+
end
|
31
|
+
expect(exception.is_a?(ArgumentError)).to be true
|
32
|
+
expect(exception.message.include?('bad type')).to be true
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns nil if the header key is missing' do
|
36
|
+
status = Struct::Status.new(1, 'details', key: 'val')
|
37
|
+
expect(status.metadata.nil?).to be false
|
38
|
+
expect(GRPC::GoogleRpcStatusUtils.extract_google_rpc_status(
|
39
|
+
status)).to be(nil)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'fails with some error if the header key fails to deserialize' do
|
43
|
+
status = Struct::Status.new(1, 'details',
|
44
|
+
'grpc-status-details-bin' => 'string_val')
|
45
|
+
expect do
|
46
|
+
GRPC::GoogleRpcStatusUtils.extract_google_rpc_status(status)
|
47
|
+
end.to raise_error(StandardError)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'silently ignores erroneous mismatch between messages in '\
|
51
|
+
'status struct and protobuf status' do
|
52
|
+
proto = Google::Rpc::Status.new(code: 1, message: 'proto message')
|
53
|
+
encoded_proto = Google::Rpc::Status.encode(proto)
|
54
|
+
status = Struct::Status.new(1, 'struct message',
|
55
|
+
'grpc-status-details-bin' => encoded_proto)
|
56
|
+
rpc_status = GRPC::GoogleRpcStatusUtils.extract_google_rpc_status(status)
|
57
|
+
expect(rpc_status).to eq(proto)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'silently ignores erroneous mismatch between codes in status struct '\
|
61
|
+
'and protobuf status' do
|
62
|
+
proto = Google::Rpc::Status.new(code: 1, message: 'matching message')
|
63
|
+
encoded_proto = Google::Rpc::Status.encode(proto)
|
64
|
+
status = Struct::Status.new(2, 'matching message',
|
65
|
+
'grpc-status-details-bin' => encoded_proto)
|
66
|
+
rpc_status = GRPC::GoogleRpcStatusUtils.extract_google_rpc_status(status)
|
67
|
+
expect(rpc_status).to eq(proto)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'can successfully convert a status struct into a google protobuf status '\
|
71
|
+
'when there are no rpcstatus details' do
|
72
|
+
proto = Google::Rpc::Status.new(code: 1, message: 'matching message')
|
73
|
+
encoded_proto = Google::Rpc::Status.encode(proto)
|
74
|
+
status = Struct::Status.new(1, 'matching message',
|
75
|
+
'grpc-status-details-bin' => encoded_proto)
|
76
|
+
out = GRPC::GoogleRpcStatusUtils.extract_google_rpc_status(status)
|
77
|
+
expect(out.code).to eq(1)
|
78
|
+
expect(out.message).to eq('matching message')
|
79
|
+
expect(out.details).to eq([])
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'can successfully convert a status struct into a google protobuf '\
|
83
|
+
'status when there are multiple rpcstatus details' do
|
84
|
+
simple_request_any = Google::Protobuf::Any.new
|
85
|
+
simple_request = Grpc::Testing::SimpleRequest.new(
|
86
|
+
payload: Grpc::Testing::Payload.new(body: 'request'))
|
87
|
+
simple_request_any.pack(simple_request)
|
88
|
+
simple_response_any = Google::Protobuf::Any.new
|
89
|
+
simple_response = Grpc::Testing::SimpleResponse.new(
|
90
|
+
payload: Grpc::Testing::Payload.new(body: 'response'))
|
91
|
+
simple_response_any.pack(simple_response)
|
92
|
+
payload_any = Google::Protobuf::Any.new
|
93
|
+
payload = Grpc::Testing::Payload.new(body: 'payload')
|
94
|
+
payload_any.pack(payload)
|
95
|
+
proto = Google::Rpc::Status.new(code: 1,
|
96
|
+
message: 'matching message',
|
97
|
+
details: [
|
98
|
+
simple_request_any,
|
99
|
+
simple_response_any,
|
100
|
+
payload_any
|
101
|
+
])
|
102
|
+
encoded_proto = Google::Rpc::Status.encode(proto)
|
103
|
+
status = Struct::Status.new(1, 'matching message',
|
104
|
+
'grpc-status-details-bin' => encoded_proto)
|
105
|
+
out = GRPC::GoogleRpcStatusUtils.extract_google_rpc_status(status)
|
106
|
+
expect(out.code).to eq(1)
|
107
|
+
expect(out.message).to eq('matching message')
|
108
|
+
expect(out.details[0].unpack(
|
109
|
+
Grpc::Testing::SimpleRequest)).to eq(simple_request)
|
110
|
+
expect(out.details[1].unpack(
|
111
|
+
Grpc::Testing::SimpleResponse)).to eq(simple_response)
|
112
|
+
expect(out.details[2].unpack(
|
113
|
+
Grpc::Testing::Payload)).to eq(payload)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# A test service that fills in the "reserved" grpc-status-details-bin trailer,
|
118
|
+
# for client-side testing of GoogleRpcStatus protobuf extraction from trailers.
|
119
|
+
class GoogleRpcStatusTestService
|
120
|
+
include GRPC::GenericService
|
121
|
+
rpc :an_rpc, EchoMsg, EchoMsg
|
122
|
+
|
123
|
+
def initialize(encoded_rpc_status)
|
124
|
+
@encoded_rpc_status = encoded_rpc_status
|
125
|
+
end
|
126
|
+
|
127
|
+
def an_rpc(_, _)
|
128
|
+
# TODO: create a server-side utility API for sending a google rpc status.
|
129
|
+
# Applications are not expected to set the grpc-status-details-bin
|
130
|
+
# ("grpc"-fixed and reserved for library use) manually.
|
131
|
+
# Doing so here is only for testing of the client-side api for extracting
|
132
|
+
# a google rpc status, which is useful
|
133
|
+
# when the interacting with a server that does fill in this trailer.
|
134
|
+
fail GRPC::Unknown.new('test message',
|
135
|
+
'grpc-status-details-bin' => @encoded_rpc_status)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
GoogleRpcStatusTestStub = GoogleRpcStatusTestService.rpc_stub_class
|
140
|
+
|
141
|
+
describe 'receving a google rpc status from a remote endpoint' do
|
142
|
+
def start_server(encoded_rpc_status)
|
143
|
+
@srv = new_rpc_server_for_testing(pool_size: 1)
|
144
|
+
@server_port = @srv.add_http2_port('localhost:0',
|
145
|
+
:this_port_is_insecure)
|
146
|
+
@srv.handle(GoogleRpcStatusTestService.new(encoded_rpc_status))
|
147
|
+
@server_thd = Thread.new { @srv.run }
|
148
|
+
@srv.wait_till_running
|
149
|
+
end
|
150
|
+
|
151
|
+
def stop_server
|
152
|
+
expect(@srv.stopped?).to be(false)
|
153
|
+
@srv.stop
|
154
|
+
@server_thd.join
|
155
|
+
expect(@srv.stopped?).to be(true)
|
156
|
+
end
|
157
|
+
|
158
|
+
before(:each) do
|
159
|
+
simple_request_any = Google::Protobuf::Any.new
|
160
|
+
simple_request = Grpc::Testing::SimpleRequest.new(
|
161
|
+
payload: Grpc::Testing::Payload.new(body: 'request'))
|
162
|
+
simple_request_any.pack(simple_request)
|
163
|
+
simple_response_any = Google::Protobuf::Any.new
|
164
|
+
simple_response = Grpc::Testing::SimpleResponse.new(
|
165
|
+
payload: Grpc::Testing::Payload.new(body: 'response'))
|
166
|
+
simple_response_any.pack(simple_response)
|
167
|
+
payload_any = Google::Protobuf::Any.new
|
168
|
+
payload = Grpc::Testing::Payload.new(body: 'payload')
|
169
|
+
payload_any.pack(payload)
|
170
|
+
@expected_proto = Google::Rpc::Status.new(
|
171
|
+
code: StatusCodes::UNKNOWN,
|
172
|
+
message: 'test message',
|
173
|
+
details: [simple_request_any, simple_response_any, payload_any])
|
174
|
+
start_server(Google::Rpc::Status.encode(@expected_proto))
|
175
|
+
end
|
176
|
+
|
177
|
+
after(:each) do
|
178
|
+
stop_server
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'should receive be able to extract a google rpc status from the '\
|
182
|
+
'status struct taken from a BadStatus exception' do
|
183
|
+
stub = GoogleRpcStatusTestStub.new("localhost:#{@server_port}",
|
184
|
+
:this_channel_is_insecure)
|
185
|
+
begin
|
186
|
+
stub.an_rpc(EchoMsg.new)
|
187
|
+
rescue GRPC::BadStatus => e
|
188
|
+
rpc_status = GRPC::GoogleRpcStatusUtils.extract_google_rpc_status(
|
189
|
+
e.to_status)
|
190
|
+
end
|
191
|
+
expect(rpc_status).to eq(@expected_proto)
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'should receive be able to extract a google rpc status from the '\
|
195
|
+
'status struct taken from the op view of a call' do
|
196
|
+
stub = GoogleRpcStatusTestStub.new("localhost:#{@server_port}",
|
197
|
+
:this_channel_is_insecure)
|
198
|
+
op = stub.an_rpc(EchoMsg.new, return_op: true)
|
199
|
+
begin
|
200
|
+
op.execute
|
201
|
+
rescue GRPC::BadStatus => e
|
202
|
+
status_from_exception = e.to_status
|
203
|
+
end
|
204
|
+
rpc_status = GRPC::GoogleRpcStatusUtils.extract_google_rpc_status(
|
205
|
+
op.status)
|
206
|
+
expect(rpc_status).to eq(@expected_proto)
|
207
|
+
# "to_status" on the bad status should give the same result
|
208
|
+
# as "status" on the "op view".
|
209
|
+
expect(GRPC::GoogleRpcStatusUtils.extract_google_rpc_status(
|
210
|
+
status_from_exception)).to eq(rpc_status)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
# A test service that fails without explicitly setting the
|
215
|
+
# grpc-status-details-bin trailer. Tests assumptions about value
|
216
|
+
# of grpc-status-details-bin on the client side when the trailer wasn't
|
217
|
+
# set explicitly.
|
218
|
+
class NoStatusDetailsBinTestService
|
219
|
+
include GRPC::GenericService
|
220
|
+
rpc :an_rpc, EchoMsg, EchoMsg
|
221
|
+
|
222
|
+
def an_rpc(_, _)
|
223
|
+
fail GRPC::Unknown
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
NoStatusDetailsBinTestServiceStub = NoStatusDetailsBinTestService.rpc_stub_class
|
228
|
+
|
229
|
+
describe 'when the endpoint doesnt send grpc-status-details-bin' do
|
230
|
+
def start_server
|
231
|
+
@srv = new_rpc_server_for_testing(pool_size: 1)
|
232
|
+
@server_port = @srv.add_http2_port('localhost:0',
|
233
|
+
:this_port_is_insecure)
|
234
|
+
@srv.handle(NoStatusDetailsBinTestService)
|
235
|
+
@server_thd = Thread.new { @srv.run }
|
236
|
+
@srv.wait_till_running
|
237
|
+
end
|
238
|
+
|
239
|
+
def stop_server
|
240
|
+
expect(@srv.stopped?).to be(false)
|
241
|
+
@srv.stop
|
242
|
+
@server_thd.join
|
243
|
+
expect(@srv.stopped?).to be(true)
|
244
|
+
end
|
245
|
+
|
246
|
+
before(:each) do
|
247
|
+
start_server
|
248
|
+
end
|
249
|
+
|
250
|
+
after(:each) do
|
251
|
+
stop_server
|
252
|
+
end
|
253
|
+
|
254
|
+
it 'should receive nil when we extract try to extract a google '\
|
255
|
+
'rpc status from a BadStatus exception that didnt have it' do
|
256
|
+
stub = NoStatusDetailsBinTestServiceStub.new("localhost:#{@server_port}",
|
257
|
+
:this_channel_is_insecure)
|
258
|
+
begin
|
259
|
+
stub.an_rpc(EchoMsg.new)
|
260
|
+
rescue GRPC::Unknown => e
|
261
|
+
rpc_status = GRPC::GoogleRpcStatusUtils.extract_google_rpc_status(
|
262
|
+
e.to_status)
|
263
|
+
end
|
264
|
+
expect(rpc_status).to be(nil)
|
265
|
+
end
|
266
|
+
|
267
|
+
it 'should receive nil when we extract try to extract a google '\
|
268
|
+
'rpc status from an op views status object that didnt have it' do
|
269
|
+
stub = NoStatusDetailsBinTestServiceStub.new("localhost:#{@server_port}",
|
270
|
+
:this_channel_is_insecure)
|
271
|
+
op = stub.an_rpc(EchoMsg.new, return_op: true)
|
272
|
+
begin
|
273
|
+
op.execute
|
274
|
+
rescue GRPC::Unknown => e
|
275
|
+
status_from_exception = e.to_status
|
276
|
+
end
|
277
|
+
expect(GRPC::GoogleRpcStatusUtils.extract_google_rpc_status(
|
278
|
+
status_from_exception)).to be(nil)
|
279
|
+
expect(GRPC::GoogleRpcStatusUtils.extract_google_rpc_status(
|
280
|
+
op.status)).to be nil
|
281
|
+
end
|
282
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
// Copyright 2018 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
|
+
syntax = "proto3";
|
16
|
+
|
17
|
+
package grpc.testing;
|
18
|
+
|
19
|
+
// For sanity checking package definitions
|
20
|
+
option ruby_package = "Grpc.Testing.Package.Options";
|
21
|
+
|
22
|
+
message TestRequest { }
|
23
|
+
|
24
|
+
message TestResponse { }
|
25
|
+
|
26
|
+
service TestService {
|
27
|
+
rpc GetTest(TestRequest) returns (TestResponse) { }
|
28
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
// Copyright 2019 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
|
+
syntax = "proto3";
|
16
|
+
|
17
|
+
package grpc.testing;
|
18
|
+
|
19
|
+
// For sanity checking package definitions
|
20
|
+
option ruby_package = "A::Other";
|
21
|
+
|
22
|
+
message Thing { }
|
@@ -0,0 +1,23 @@
|
|
1
|
+
// Copyright 2020 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
|
+
syntax = "proto3";
|
16
|
+
|
17
|
+
package grpc.foo;
|
18
|
+
|
19
|
+
option ruby_package = "B::Other";
|
20
|
+
|
21
|
+
message Foo {
|
22
|
+
message Bar { }
|
23
|
+
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
// Copyright 2019 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
|
+
syntax = "proto3";
|
16
|
+
|
17
|
+
package grpc.testing;
|
18
|
+
|
19
|
+
import "grpc/testing/package_options_import.proto";
|
20
|
+
import "grpc/testing/package_options_import2.proto";
|
21
|
+
|
22
|
+
// For sanity checking package definitions
|
23
|
+
option ruby_package = "RPC::Test::New::Package::Options";
|
24
|
+
|
25
|
+
message AnotherTestRequest { }
|
26
|
+
|
27
|
+
message AnotherTestResponse { }
|
28
|
+
|
29
|
+
message Foo { }
|
30
|
+
|
31
|
+
message Bar {
|
32
|
+
message Baz { }
|
33
|
+
}
|
34
|
+
|
35
|
+
service AnotherTestService {
|
36
|
+
rpc GetTest(AnotherTestRequest) returns (AnotherTestResponse) { }
|
37
|
+
rpc OtherTest(Thing) returns (Thing) { }
|
38
|
+
rpc PackageTest(grpc.testing.Thing) returns (grpc.foo.Foo.Bar) { }
|
39
|
+
rpc FooTest(Foo) returns (Foo) { }
|
40
|
+
rpc NestedMessageTest(Foo) returns (Bar.Baz) { }
|
41
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
// Copyright 2020 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
|
+
syntax = "proto3";
|
16
|
+
|
17
|
+
package same_name;
|
18
|
+
|
19
|
+
service SameName {
|
20
|
+
rpc Health(Request) returns (Status);
|
21
|
+
}
|
22
|
+
|
23
|
+
message Status {
|
24
|
+
string msg = 1;
|
25
|
+
}
|
26
|
+
|
27
|
+
message Request {}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
// Copyright 2020 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
|
+
syntax = "proto3";
|
16
|
+
|
17
|
+
package other_name;
|
18
|
+
|
19
|
+
option ruby_package = "SameName2";
|
20
|
+
|
21
|
+
service SameName2 {
|
22
|
+
rpc Health(Request) returns (Status);
|
23
|
+
}
|
24
|
+
|
25
|
+
message Status {
|
26
|
+
string msg = 1;
|
27
|
+
}
|
28
|
+
|
29
|
+
message Request {}
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# Copyright 2018 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 'open3'
|
17
|
+
require 'tmpdir'
|
18
|
+
|
19
|
+
describe 'Code Generation Options' do
|
20
|
+
it 'should generate and respect package options' do
|
21
|
+
with_protos(%w[grpc/testing/package_options.proto]) do
|
22
|
+
expect { Grpc::Testing::Package::Options::TestService::Service }.to raise_error(NameError)
|
23
|
+
expect(require('grpc/testing/package_options_services_pb')).to be_truthy
|
24
|
+
expect { Grpc::Testing::Package::Options::TestService::Service }.to_not raise_error
|
25
|
+
expect { Grpc::Testing::TestService::Service }.to raise_error(NameError)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should generate and respect Ruby style package options' do
|
30
|
+
with_protos(['grpc/testing/package_options_ruby_style.proto',
|
31
|
+
'grpc/testing/package_options_import.proto',
|
32
|
+
'grpc/testing/package_options_import2.proto']) do
|
33
|
+
expect { RPC::Test::New::Package::Options::AnotherTestService::Service }.to raise_error(NameError)
|
34
|
+
expect(require('grpc/testing/package_options_ruby_style_services_pb')).to be_truthy
|
35
|
+
expect { RPC::Test::New::Package::Options::AnotherTestService::Service }.to_not raise_error
|
36
|
+
expect { Grpc::Testing::AnotherTestService::Service }.to raise_error(NameError)
|
37
|
+
|
38
|
+
services = RPC::Test::New::Package::Options::AnotherTestService::Service.rpc_descs
|
39
|
+
expect(services[:GetTest].input).to eq(RPC::Test::New::Package::Options::AnotherTestRequest)
|
40
|
+
expect(services[:GetTest].output).to eq(RPC::Test::New::Package::Options::AnotherTestResponse)
|
41
|
+
expect(services[:OtherTest].input).to eq(A::Other::Thing)
|
42
|
+
expect(services[:OtherTest].output).to eq(A::Other::Thing)
|
43
|
+
expect(services[:PackageTest].input).to eq(A::Other::Thing)
|
44
|
+
expect(services[:PackageTest].output).to eq(B::Other::Foo::Bar)
|
45
|
+
expect(services[:FooTest].input).to eq(RPC::Test::New::Package::Options::Foo)
|
46
|
+
expect(services[:FooTest].output).to eq(RPC::Test::New::Package::Options::Foo)
|
47
|
+
expect(services[:NestedMessageTest].input).to eq(RPC::Test::New::Package::Options::Foo)
|
48
|
+
expect(services[:NestedMessageTest].output).to eq(RPC::Test::New::Package::Options::Bar::Baz)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should generate when package and service has same name' do
|
53
|
+
with_protos(['grpc/testing/same_package_service_name.proto']) do
|
54
|
+
expect { SameName::SameName::Service }.to raise_error(NameError)
|
55
|
+
expect(require('grpc/testing/same_package_service_name_services_pb')).to be_truthy
|
56
|
+
expect { SameName::SameName::Service }.to_not raise_error
|
57
|
+
expect { SameName::Request }.to_not raise_error
|
58
|
+
expect { SameName::Status }.to_not raise_error
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should generate when ruby_package and service has same name' do
|
63
|
+
with_protos(['grpc/testing/same_ruby_package_service_name.proto']) do
|
64
|
+
expect { SameName2::SameName2::Service }.to raise_error(NameError)
|
65
|
+
expect(require('grpc/testing/same_ruby_package_service_name_services_pb')).to be_truthy
|
66
|
+
expect { SameName2::SameName2::Service }.to_not raise_error
|
67
|
+
expect { SameName2::Request }.to_not raise_error
|
68
|
+
expect { SameName2::Status }.to_not raise_error
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def with_protos(file_paths)
|
74
|
+
pb_dir = File.dirname(__FILE__)
|
75
|
+
bins_dir = File.join('..', '..', '..', '..', '..', 'cmake', 'build')
|
76
|
+
plugin = File.join(bins_dir, 'grpc_ruby_plugin')
|
77
|
+
protoc = File.join(bins_dir, 'third_party', 'protobuf', 'protoc')
|
78
|
+
|
79
|
+
# Generate the service from the proto
|
80
|
+
Dir.mktmpdir(nil, File.dirname(__FILE__)) do |tmp_dir|
|
81
|
+
gen_file = system(protoc,
|
82
|
+
'-I.',
|
83
|
+
*file_paths,
|
84
|
+
"--grpc_out=#{tmp_dir}", # generate the service
|
85
|
+
"--ruby_out=#{tmp_dir}", # generate the definitions
|
86
|
+
"--plugin=protoc-gen-grpc=#{plugin}",
|
87
|
+
chdir: pb_dir,
|
88
|
+
out: File::NULL)
|
89
|
+
|
90
|
+
expect(gen_file).to be_truthy
|
91
|
+
begin
|
92
|
+
$LOAD_PATH.push(tmp_dir)
|
93
|
+
yield
|
94
|
+
ensure
|
95
|
+
$LOAD_PATH.delete(tmp_dir)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Copyright 2016 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 'open3'
|
17
|
+
require 'tmpdir'
|
18
|
+
|
19
|
+
def can_run_codegen_check
|
20
|
+
system('which grpc_ruby_plugin') && system('which protoc')
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'Ping protobuf code generation' do
|
24
|
+
if !can_run_codegen_check
|
25
|
+
skip 'protoc || grpc_ruby_plugin missing, cannot verify ping code-gen'
|
26
|
+
else
|
27
|
+
it 'should have the same content as created by code generation' do
|
28
|
+
root_dir = File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..')
|
29
|
+
|
30
|
+
# Get the current content
|
31
|
+
service_path = File.join(root_dir, 'src', 'ruby', 'pb', 'grpc',
|
32
|
+
'testing', 'duplicate',
|
33
|
+
'echo_duplicate_services_pb.rb')
|
34
|
+
want = nil
|
35
|
+
File.open(service_path) { |f| want = f.read }
|
36
|
+
|
37
|
+
# Regenerate it
|
38
|
+
plugin, = Open3.capture2('which', 'grpc_ruby_plugin')
|
39
|
+
plugin = plugin.strip
|
40
|
+
got = nil
|
41
|
+
Dir.mktmpdir do |tmp_dir|
|
42
|
+
gen_out = File.join(tmp_dir, 'src', 'proto', 'grpc', 'testing',
|
43
|
+
'duplicate', 'echo_duplicate_services_pb.rb')
|
44
|
+
pid = spawn(
|
45
|
+
'protoc',
|
46
|
+
'-I.',
|
47
|
+
'src/proto/grpc/testing/duplicate/echo_duplicate.proto',
|
48
|
+
"--grpc_out=#{tmp_dir}",
|
49
|
+
"--plugin=protoc-gen-grpc=#{plugin}",
|
50
|
+
chdir: root_dir)
|
51
|
+
Process.wait(pid)
|
52
|
+
File.open(gen_out) { |f| got = f.read }
|
53
|
+
end
|
54
|
+
expect(got).to eq(want)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|