grpc 0.5.0
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/.gitignore +15 -0
- data/.rspec +1 -0
- data/.rubocop.yml +10 -0
- data/.rubocop_todo.yml +52 -0
- data/Gemfile +4 -0
- data/README.md +82 -0
- data/Rakefile +54 -0
- data/bin/apis/google/protobuf/empty.rb +44 -0
- data/bin/apis/pubsub_demo.rb +267 -0
- data/bin/apis/tech/pubsub/proto/pubsub.rb +174 -0
- data/bin/apis/tech/pubsub/proto/pubsub_services.rb +103 -0
- data/bin/interop/README.md +8 -0
- data/bin/interop/interop_client.rb +334 -0
- data/bin/interop/interop_server.rb +192 -0
- data/bin/interop/test/cpp/interop/empty.rb +44 -0
- data/bin/interop/test/cpp/interop/messages.rb +89 -0
- data/bin/interop/test/cpp/interop/test.rb +43 -0
- data/bin/interop/test/cpp/interop/test_services.rb +60 -0
- data/bin/math.proto +80 -0
- data/bin/math.rb +61 -0
- data/bin/math_client.rb +147 -0
- data/bin/math_server.rb +190 -0
- data/bin/math_services.rb +56 -0
- data/bin/noproto_client.rb +108 -0
- data/bin/noproto_server.rb +112 -0
- data/ext/grpc/extconf.rb +76 -0
- data/ext/grpc/rb_byte_buffer.c +241 -0
- data/ext/grpc/rb_byte_buffer.h +54 -0
- data/ext/grpc/rb_call.c +569 -0
- data/ext/grpc/rb_call.h +59 -0
- data/ext/grpc/rb_channel.c +264 -0
- data/ext/grpc/rb_channel.h +49 -0
- data/ext/grpc/rb_channel_args.c +154 -0
- data/ext/grpc/rb_channel_args.h +52 -0
- data/ext/grpc/rb_completion_queue.c +185 -0
- data/ext/grpc/rb_completion_queue.h +50 -0
- data/ext/grpc/rb_credentials.c +281 -0
- data/ext/grpc/rb_credentials.h +50 -0
- data/ext/grpc/rb_event.c +361 -0
- data/ext/grpc/rb_event.h +53 -0
- data/ext/grpc/rb_grpc.c +274 -0
- data/ext/grpc/rb_grpc.h +74 -0
- data/ext/grpc/rb_metadata.c +215 -0
- data/ext/grpc/rb_metadata.h +53 -0
- data/ext/grpc/rb_server.c +278 -0
- data/ext/grpc/rb_server.h +50 -0
- data/ext/grpc/rb_server_credentials.c +210 -0
- data/ext/grpc/rb_server_credentials.h +50 -0
- data/grpc.gemspec +41 -0
- data/lib/grpc.rb +39 -0
- data/lib/grpc/core/event.rb +44 -0
- data/lib/grpc/core/time_consts.rb +71 -0
- data/lib/grpc/errors.rb +61 -0
- data/lib/grpc/generic/active_call.rb +536 -0
- data/lib/grpc/generic/bidi_call.rb +221 -0
- data/lib/grpc/generic/client_stub.rb +413 -0
- data/lib/grpc/generic/rpc_desc.rb +150 -0
- data/lib/grpc/generic/rpc_server.rb +404 -0
- data/lib/grpc/generic/service.rb +235 -0
- data/lib/grpc/logconfig.rb +40 -0
- data/lib/grpc/version.rb +33 -0
- data/spec/alloc_spec.rb +44 -0
- data/spec/byte_buffer_spec.rb +67 -0
- data/spec/call_spec.rb +163 -0
- data/spec/channel_spec.rb +181 -0
- data/spec/client_server_spec.rb +372 -0
- data/spec/completion_queue_spec.rb +74 -0
- data/spec/credentials_spec.rb +71 -0
- data/spec/event_spec.rb +53 -0
- data/spec/generic/active_call_spec.rb +373 -0
- data/spec/generic/client_stub_spec.rb +519 -0
- data/spec/generic/rpc_desc_spec.rb +357 -0
- data/spec/generic/rpc_server_pool_spec.rb +139 -0
- data/spec/generic/rpc_server_spec.rb +404 -0
- data/spec/generic/service_spec.rb +342 -0
- data/spec/metadata_spec.rb +64 -0
- data/spec/server_credentials_spec.rb +69 -0
- data/spec/server_spec.rb +212 -0
- data/spec/spec_helper.rb +51 -0
- data/spec/testdata/README +1 -0
- data/spec/testdata/ca.pem +15 -0
- data/spec/testdata/server1.key +16 -0
- data/spec/testdata/server1.pem +16 -0
- data/spec/time_consts_spec.rb +89 -0
- metadata +353 -0
@@ -0,0 +1,519 @@
|
|
1
|
+
# Copyright 2015, Google Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are
|
6
|
+
# met:
|
7
|
+
#
|
8
|
+
# * Redistributions of source code must retain the above copyright
|
9
|
+
# notice, this list of conditions and the following disclaimer.
|
10
|
+
# * Redistributions in binary form must reproduce the above
|
11
|
+
# copyright notice, this list of conditions and the following disclaimer
|
12
|
+
# in the documentation and/or other materials provided with the
|
13
|
+
# distribution.
|
14
|
+
# * Neither the name of Google Inc. nor the names of its
|
15
|
+
# contributors may be used to endorse or promote products derived from
|
16
|
+
# this software without specific prior written permission.
|
17
|
+
#
|
18
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
19
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
20
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
21
|
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
22
|
+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
23
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
24
|
+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
25
|
+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
26
|
+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
27
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
+
|
30
|
+
require 'grpc'
|
31
|
+
require 'xray/thread_dump_signal_handler'
|
32
|
+
|
33
|
+
NOOP = proc { |x| x }
|
34
|
+
FAKE_HOST = 'localhost:0'
|
35
|
+
|
36
|
+
def wakey_thread(&blk)
|
37
|
+
awake_mutex, awake_cond = Mutex.new, ConditionVariable.new
|
38
|
+
t = Thread.new do
|
39
|
+
blk.call(awake_mutex, awake_cond)
|
40
|
+
end
|
41
|
+
awake_mutex.synchronize { awake_cond.wait(awake_mutex) }
|
42
|
+
t
|
43
|
+
end
|
44
|
+
|
45
|
+
def load_test_certs
|
46
|
+
test_root = File.join(File.dirname(File.dirname(__FILE__)), 'testdata')
|
47
|
+
files = ['ca.pem', 'server1.key', 'server1.pem']
|
48
|
+
files.map { |f| File.open(File.join(test_root, f)).read }
|
49
|
+
end
|
50
|
+
|
51
|
+
include GRPC::Core::StatusCodes
|
52
|
+
include GRPC::Core::TimeConsts
|
53
|
+
|
54
|
+
describe 'ClientStub' do
|
55
|
+
before(:each) do
|
56
|
+
Thread.abort_on_exception = true
|
57
|
+
@server = nil
|
58
|
+
@method = 'an_rpc_method'
|
59
|
+
@pass = OK
|
60
|
+
@fail = INTERNAL
|
61
|
+
@cq = GRPC::Core::CompletionQueue.new
|
62
|
+
end
|
63
|
+
|
64
|
+
after(:each) do
|
65
|
+
@server.close unless @server.nil?
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#new' do
|
69
|
+
it 'can be created from a host and args' do
|
70
|
+
host = FAKE_HOST
|
71
|
+
opts = { a_channel_arg: 'an_arg' }
|
72
|
+
blk = proc do
|
73
|
+
GRPC::ClientStub.new(host, @cq, **opts)
|
74
|
+
end
|
75
|
+
expect(&blk).not_to raise_error
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'can be created with a default deadline' do
|
79
|
+
host = FAKE_HOST
|
80
|
+
opts = { a_channel_arg: 'an_arg', deadline: 5 }
|
81
|
+
blk = proc do
|
82
|
+
GRPC::ClientStub.new(host, @cq, **opts)
|
83
|
+
end
|
84
|
+
expect(&blk).not_to raise_error
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'can be created with an channel override' do
|
88
|
+
host = FAKE_HOST
|
89
|
+
opts = { a_channel_arg: 'an_arg', channel_override: @ch }
|
90
|
+
blk = proc do
|
91
|
+
GRPC::ClientStub.new(host, @cq, **opts)
|
92
|
+
end
|
93
|
+
expect(&blk).not_to raise_error
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'cannot be created with a bad channel override' do
|
97
|
+
host = FAKE_HOST
|
98
|
+
blk = proc do
|
99
|
+
opts = { a_channel_arg: 'an_arg', channel_override: Object.new }
|
100
|
+
GRPC::ClientStub.new(host, @cq, **opts)
|
101
|
+
end
|
102
|
+
expect(&blk).to raise_error
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'cannot be created with bad credentials' do
|
106
|
+
host = FAKE_HOST
|
107
|
+
blk = proc do
|
108
|
+
opts = { a_channel_arg: 'an_arg', creds: Object.new }
|
109
|
+
GRPC::ClientStub.new(host, @cq, **opts)
|
110
|
+
end
|
111
|
+
expect(&blk).to raise_error
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'can be created with test test credentials' do
|
115
|
+
certs = load_test_certs
|
116
|
+
host = FAKE_HOST
|
117
|
+
blk = proc do
|
118
|
+
opts = {
|
119
|
+
GRPC::Core::Channel::SSL_TARGET => 'foo.test.google.fr',
|
120
|
+
a_channel_arg: 'an_arg',
|
121
|
+
creds: GRPC::Core::Credentials.new(certs[0], nil, nil)
|
122
|
+
}
|
123
|
+
GRPC::ClientStub.new(host, @cq, **opts)
|
124
|
+
end
|
125
|
+
expect(&blk).to_not raise_error
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe '#request_response' do
|
130
|
+
before(:each) do
|
131
|
+
@sent_msg, @resp = 'a_msg', 'a_reply'
|
132
|
+
end
|
133
|
+
|
134
|
+
shared_examples 'request response' do
|
135
|
+
it 'should send a request to/receive a reply from a server' do
|
136
|
+
server_port = create_test_server
|
137
|
+
th = run_request_response(@sent_msg, @resp, @pass)
|
138
|
+
stub = GRPC::ClientStub.new("localhost:#{server_port}", @cq)
|
139
|
+
expect(get_response(stub)).to eq(@resp)
|
140
|
+
th.join
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should send metadata to the server ok' do
|
144
|
+
server_port = create_test_server
|
145
|
+
host = "localhost:#{server_port}"
|
146
|
+
th = run_request_response(@sent_msg, @resp, @pass,
|
147
|
+
k1: 'v1', k2: 'v2')
|
148
|
+
stub = GRPC::ClientStub.new(host, @cq)
|
149
|
+
expect(get_response(stub)).to eq(@resp)
|
150
|
+
th.join
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'should update the sent metadata with a provided metadata updater' do
|
154
|
+
server_port = create_test_server
|
155
|
+
host = "localhost:#{server_port}"
|
156
|
+
th = run_request_response(@sent_msg, @resp, @pass,
|
157
|
+
k1: 'updated-v1', k2: 'v2')
|
158
|
+
update_md = proc do |md|
|
159
|
+
md[:k1] = 'updated-v1'
|
160
|
+
md
|
161
|
+
end
|
162
|
+
stub = GRPC::ClientStub.new(host, @cq, update_metadata: update_md)
|
163
|
+
expect(get_response(stub)).to eq(@resp)
|
164
|
+
th.join
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'should send a request when configured using an override channel' do
|
168
|
+
server_port = create_test_server
|
169
|
+
alt_host = "localhost:#{server_port}"
|
170
|
+
th = run_request_response(@sent_msg, @resp, @pass)
|
171
|
+
ch = GRPC::Core::Channel.new(alt_host, nil)
|
172
|
+
stub = GRPC::ClientStub.new('ignored-host', @cq, channel_override: ch)
|
173
|
+
expect(get_response(stub)).to eq(@resp)
|
174
|
+
th.join
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'should raise an error if the status is not OK' do
|
178
|
+
server_port = create_test_server
|
179
|
+
host = "localhost:#{server_port}"
|
180
|
+
th = run_request_response(@sent_msg, @resp, @fail)
|
181
|
+
stub = GRPC::ClientStub.new(host, @cq)
|
182
|
+
blk = proc { get_response(stub) }
|
183
|
+
expect(&blk).to raise_error(GRPC::BadStatus)
|
184
|
+
th.join
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe 'without a call operation' do
|
189
|
+
def get_response(stub)
|
190
|
+
stub.request_response(@method, @sent_msg, NOOP, NOOP,
|
191
|
+
k1: 'v1', k2: 'v2')
|
192
|
+
end
|
193
|
+
|
194
|
+
it_behaves_like 'request response'
|
195
|
+
end
|
196
|
+
|
197
|
+
describe 'via a call operation' do
|
198
|
+
def get_response(stub)
|
199
|
+
op = stub.request_response(@method, @sent_msg, NOOP, NOOP,
|
200
|
+
return_op: true, k1: 'v1', k2: 'v2')
|
201
|
+
expect(op).to be_a(GRPC::ActiveCall::Operation)
|
202
|
+
op.execute
|
203
|
+
end
|
204
|
+
|
205
|
+
it_behaves_like 'request response'
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe '#client_streamer' do
|
210
|
+
shared_examples 'client streaming' do
|
211
|
+
before(:each) do
|
212
|
+
@sent_msgs = Array.new(3) { |i| 'msg_' + (i + 1).to_s }
|
213
|
+
@resp = 'a_reply'
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'should send requests to/receive a reply from a server' do
|
217
|
+
server_port = create_test_server
|
218
|
+
host = "localhost:#{server_port}"
|
219
|
+
th = run_client_streamer(@sent_msgs, @resp, @pass)
|
220
|
+
stub = GRPC::ClientStub.new(host, @cq)
|
221
|
+
expect(get_response(stub)).to eq(@resp)
|
222
|
+
th.join
|
223
|
+
end
|
224
|
+
|
225
|
+
it 'should send metadata to the server ok' do
|
226
|
+
server_port = create_test_server
|
227
|
+
host = "localhost:#{server_port}"
|
228
|
+
th = run_client_streamer(@sent_msgs, @resp, @pass,
|
229
|
+
k1: 'v1', k2: 'v2')
|
230
|
+
stub = GRPC::ClientStub.new(host, @cq)
|
231
|
+
expect(get_response(stub)).to eq(@resp)
|
232
|
+
th.join
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'should update the sent metadata with a provided metadata updater' do
|
236
|
+
server_port = create_test_server
|
237
|
+
host = "localhost:#{server_port}"
|
238
|
+
th = run_client_streamer(@sent_msgs, @resp, @pass,
|
239
|
+
k1: 'updated-v1', k2: 'v2')
|
240
|
+
update_md = proc do |md|
|
241
|
+
md[:k1] = 'updated-v1'
|
242
|
+
md
|
243
|
+
end
|
244
|
+
stub = GRPC::ClientStub.new(host, @cq, update_metadata: update_md)
|
245
|
+
expect(get_response(stub)).to eq(@resp)
|
246
|
+
th.join
|
247
|
+
end
|
248
|
+
|
249
|
+
it 'should raise an error if the status is not ok' do
|
250
|
+
server_port = create_test_server
|
251
|
+
host = "localhost:#{server_port}"
|
252
|
+
th = run_client_streamer(@sent_msgs, @resp, @fail)
|
253
|
+
stub = GRPC::ClientStub.new(host, @cq)
|
254
|
+
blk = proc { get_response(stub) }
|
255
|
+
expect(&blk).to raise_error(GRPC::BadStatus)
|
256
|
+
th.join
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
describe 'without a call operation' do
|
261
|
+
def get_response(stub)
|
262
|
+
stub.client_streamer(@method, @sent_msgs, NOOP, NOOP,
|
263
|
+
k1: 'v1', k2: 'v2')
|
264
|
+
end
|
265
|
+
|
266
|
+
it_behaves_like 'client streaming'
|
267
|
+
end
|
268
|
+
|
269
|
+
describe 'via a call operation' do
|
270
|
+
def get_response(stub)
|
271
|
+
op = stub.client_streamer(@method, @sent_msgs, NOOP, NOOP,
|
272
|
+
return_op: true, k1: 'v1', k2: 'v2')
|
273
|
+
expect(op).to be_a(GRPC::ActiveCall::Operation)
|
274
|
+
op.execute
|
275
|
+
end
|
276
|
+
|
277
|
+
it_behaves_like 'client streaming'
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
describe '#server_streamer' do
|
282
|
+
shared_examples 'server streaming' do
|
283
|
+
before(:each) do
|
284
|
+
@sent_msg = 'a_msg'
|
285
|
+
@replys = Array.new(3) { |i| 'reply_' + (i + 1).to_s }
|
286
|
+
end
|
287
|
+
|
288
|
+
it 'should send a request to/receive replies from a server' do
|
289
|
+
server_port = create_test_server
|
290
|
+
host = "localhost:#{server_port}"
|
291
|
+
th = run_server_streamer(@sent_msg, @replys, @pass)
|
292
|
+
stub = GRPC::ClientStub.new(host, @cq)
|
293
|
+
expect(get_responses(stub).collect { |r| r }).to eq(@replys)
|
294
|
+
th.join
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'should raise an error if the status is not ok' do
|
298
|
+
server_port = create_test_server
|
299
|
+
host = "localhost:#{server_port}"
|
300
|
+
th = run_server_streamer(@sent_msg, @replys, @fail)
|
301
|
+
stub = GRPC::ClientStub.new(host, @cq)
|
302
|
+
e = get_responses(stub)
|
303
|
+
expect { e.collect { |r| r } }.to raise_error(GRPC::BadStatus)
|
304
|
+
th.join
|
305
|
+
end
|
306
|
+
|
307
|
+
it 'should send metadata to the server ok' do
|
308
|
+
server_port = create_test_server
|
309
|
+
host = "localhost:#{server_port}"
|
310
|
+
th = run_server_streamer(@sent_msg, @replys, @fail,
|
311
|
+
k1: 'v1', k2: 'v2')
|
312
|
+
stub = GRPC::ClientStub.new(host, @cq)
|
313
|
+
e = get_responses(stub)
|
314
|
+
expect { e.collect { |r| r } }.to raise_error(GRPC::BadStatus)
|
315
|
+
th.join
|
316
|
+
end
|
317
|
+
|
318
|
+
it 'should update the sent metadata with a provided metadata updater' do
|
319
|
+
server_port = create_test_server
|
320
|
+
host = "localhost:#{server_port}"
|
321
|
+
th = run_server_streamer(@sent_msg, @replys, @pass,
|
322
|
+
k1: 'updated-v1', k2: 'v2')
|
323
|
+
update_md = proc do |md|
|
324
|
+
md[:k1] = 'updated-v1'
|
325
|
+
md
|
326
|
+
end
|
327
|
+
stub = GRPC::ClientStub.new(host, @cq, update_metadata: update_md)
|
328
|
+
e = get_responses(stub)
|
329
|
+
expect(e.collect { |r| r }).to eq(@replys)
|
330
|
+
th.join
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
describe 'without a call operation' do
|
335
|
+
def get_responses(stub)
|
336
|
+
e = stub.server_streamer(@method, @sent_msg, NOOP, NOOP,
|
337
|
+
k1: 'v1', k2: 'v2')
|
338
|
+
expect(e).to be_a(Enumerator)
|
339
|
+
e
|
340
|
+
end
|
341
|
+
|
342
|
+
it_behaves_like 'server streaming'
|
343
|
+
end
|
344
|
+
|
345
|
+
describe 'via a call operation' do
|
346
|
+
def get_responses(stub)
|
347
|
+
op = stub.server_streamer(@method, @sent_msg, NOOP, NOOP,
|
348
|
+
return_op: true, k1: 'v1', k2: 'v2')
|
349
|
+
expect(op).to be_a(GRPC::ActiveCall::Operation)
|
350
|
+
e = op.execute
|
351
|
+
expect(e).to be_a(Enumerator)
|
352
|
+
e
|
353
|
+
end
|
354
|
+
|
355
|
+
it_behaves_like 'server streaming'
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
describe '#bidi_streamer' do
|
360
|
+
shared_examples 'bidi streaming' do
|
361
|
+
before(:each) do
|
362
|
+
@sent_msgs = Array.new(3) { |i| 'msg_' + (i + 1).to_s }
|
363
|
+
@replys = Array.new(3) { |i| 'reply_' + (i + 1).to_s }
|
364
|
+
end
|
365
|
+
|
366
|
+
it 'supports sending all the requests first', bidi: true do
|
367
|
+
server_port = create_test_server
|
368
|
+
host = "localhost:#{server_port}"
|
369
|
+
th = run_bidi_streamer_handle_inputs_first(@sent_msgs, @replys,
|
370
|
+
@pass)
|
371
|
+
stub = GRPC::ClientStub.new(host, @cq)
|
372
|
+
e = get_responses(stub)
|
373
|
+
expect(e.collect { |r| r }).to eq(@replys)
|
374
|
+
th.join
|
375
|
+
end
|
376
|
+
|
377
|
+
it 'supports client-initiated ping pong', bidi: true do
|
378
|
+
server_port = create_test_server
|
379
|
+
host = "localhost:#{server_port}"
|
380
|
+
th = run_bidi_streamer_echo_ping_pong(@sent_msgs, @pass, true)
|
381
|
+
stub = GRPC::ClientStub.new(host, @cq)
|
382
|
+
e = get_responses(stub)
|
383
|
+
expect(e.collect { |r| r }).to eq(@sent_msgs)
|
384
|
+
th.join
|
385
|
+
end
|
386
|
+
|
387
|
+
# disabled because an unresolved wire-protocol implementation feature
|
388
|
+
#
|
389
|
+
# - servers should be able initiate messaging, however, as it stand
|
390
|
+
# servers don't know if all the client metadata has been sent until
|
391
|
+
# they receive a message from the client. Without receiving all the
|
392
|
+
# metadata, the server does not accept the call, so this test hangs.
|
393
|
+
xit 'supports a server-initiated ping pong', bidi: true do
|
394
|
+
server_port = create_test_server
|
395
|
+
host = "localhost:#{server_port}"
|
396
|
+
th = run_bidi_streamer_echo_ping_pong(@sent_msgs, @pass, false)
|
397
|
+
stub = GRPC::ClientStub.new(host, @cq)
|
398
|
+
e = get_responses(stub)
|
399
|
+
expect(e.collect { |r| r }).to eq(@sent_msgs)
|
400
|
+
th.join
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
describe 'without a call operation' do
|
405
|
+
def get_responses(stub)
|
406
|
+
e = stub.bidi_streamer(@method, @sent_msgs, NOOP, NOOP)
|
407
|
+
expect(e).to be_a(Enumerator)
|
408
|
+
e
|
409
|
+
end
|
410
|
+
|
411
|
+
it_behaves_like 'bidi streaming'
|
412
|
+
end
|
413
|
+
|
414
|
+
describe 'via a call operation' do
|
415
|
+
def get_responses(stub)
|
416
|
+
op = stub.bidi_streamer(@method, @sent_msgs, NOOP, NOOP,
|
417
|
+
return_op: true)
|
418
|
+
expect(op).to be_a(GRPC::ActiveCall::Operation)
|
419
|
+
e = op.execute
|
420
|
+
expect(e).to be_a(Enumerator)
|
421
|
+
e
|
422
|
+
end
|
423
|
+
|
424
|
+
it_behaves_like 'bidi streaming'
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
def run_server_streamer(expected_input, replys, status, **kw)
|
429
|
+
wanted_metadata = kw.clone
|
430
|
+
wakey_thread do |mtx, cnd|
|
431
|
+
c = expect_server_to_be_invoked(mtx, cnd)
|
432
|
+
wanted_metadata.each do |k, v|
|
433
|
+
expect(c.metadata[k.to_s]).to eq(v)
|
434
|
+
end
|
435
|
+
expect(c.remote_read).to eq(expected_input)
|
436
|
+
replys.each { |r| c.remote_send(r) }
|
437
|
+
c.send_status(status, status == @pass ? 'OK' : 'NOK')
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
def run_bidi_streamer_handle_inputs_first(expected_inputs, replys,
|
442
|
+
status)
|
443
|
+
wakey_thread do |mtx, cnd|
|
444
|
+
c = expect_server_to_be_invoked(mtx, cnd)
|
445
|
+
expected_inputs.each { |i| expect(c.remote_read).to eq(i) }
|
446
|
+
replys.each { |r| c.remote_send(r) }
|
447
|
+
c.send_status(status, status == @pass ? 'OK' : 'NOK')
|
448
|
+
end
|
449
|
+
end
|
450
|
+
|
451
|
+
def run_bidi_streamer_echo_ping_pong(expected_inputs, status, client_starts)
|
452
|
+
wakey_thread do |mtx, cnd|
|
453
|
+
c = expect_server_to_be_invoked(mtx, cnd)
|
454
|
+
expected_inputs.each do |i|
|
455
|
+
if client_starts
|
456
|
+
expect(c.remote_read).to eq(i)
|
457
|
+
c.remote_send(i)
|
458
|
+
else
|
459
|
+
c.remote_send(i)
|
460
|
+
expect(c.remote_read).to eq(i)
|
461
|
+
end
|
462
|
+
end
|
463
|
+
c.send_status(status, status == @pass ? 'OK' : 'NOK')
|
464
|
+
end
|
465
|
+
end
|
466
|
+
|
467
|
+
def run_client_streamer(expected_inputs, resp, status, **kw)
|
468
|
+
wanted_metadata = kw.clone
|
469
|
+
wakey_thread do |mtx, cnd|
|
470
|
+
c = expect_server_to_be_invoked(mtx, cnd)
|
471
|
+
expected_inputs.each { |i| expect(c.remote_read).to eq(i) }
|
472
|
+
wanted_metadata.each do |k, v|
|
473
|
+
expect(c.metadata[k.to_s]).to eq(v)
|
474
|
+
end
|
475
|
+
c.remote_send(resp)
|
476
|
+
c.send_status(status, status == @pass ? 'OK' : 'NOK')
|
477
|
+
end
|
478
|
+
end
|
479
|
+
|
480
|
+
def run_request_response(expected_input, resp, status, **kw)
|
481
|
+
wanted_metadata = kw.clone
|
482
|
+
wakey_thread do |mtx, cnd|
|
483
|
+
c = expect_server_to_be_invoked(mtx, cnd)
|
484
|
+
expect(c.remote_read).to eq(expected_input)
|
485
|
+
wanted_metadata.each do |k, v|
|
486
|
+
expect(c.metadata[k.to_s]).to eq(v)
|
487
|
+
end
|
488
|
+
c.remote_send(resp)
|
489
|
+
c.send_status(status, status == @pass ? 'OK' : 'NOK')
|
490
|
+
end
|
491
|
+
end
|
492
|
+
|
493
|
+
def create_test_server
|
494
|
+
@server_queue = GRPC::Core::CompletionQueue.new
|
495
|
+
@server = GRPC::Core::Server.new(@server_queue, nil)
|
496
|
+
@server.add_http2_port('0.0.0.0:0')
|
497
|
+
end
|
498
|
+
|
499
|
+
def start_test_server(awake_mutex, awake_cond)
|
500
|
+
@server.start
|
501
|
+
@server_tag = Object.new
|
502
|
+
@server.request_call(@server_tag)
|
503
|
+
awake_mutex.synchronize { awake_cond.signal }
|
504
|
+
end
|
505
|
+
|
506
|
+
def expect_server_to_be_invoked(awake_mutex, awake_cond)
|
507
|
+
start_test_server(awake_mutex, awake_cond)
|
508
|
+
ev = @server_queue.pluck(@server_tag, INFINITE_FUTURE)
|
509
|
+
fail OutOfTime if ev.nil?
|
510
|
+
server_call = ev.call
|
511
|
+
server_call.metadata = ev.result.metadata
|
512
|
+
finished_tag = Object.new
|
513
|
+
server_call.server_accept(@server_queue, finished_tag)
|
514
|
+
server_call.server_end_initial_metadata
|
515
|
+
GRPC::ActiveCall.new(server_call, @server_queue, NOOP, NOOP,
|
516
|
+
INFINITE_FUTURE,
|
517
|
+
finished_tag: finished_tag)
|
518
|
+
end
|
519
|
+
end
|