grpc 0.6.0 → 0.6.1

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.

Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/.rubocop_todo.yml +12 -20
  4. data/CHANGELOG.md +11 -0
  5. data/Rakefile +1 -0
  6. data/bin/apis/pubsub_demo.rb +3 -6
  7. data/bin/interop/interop_client.rb +43 -3
  8. data/bin/interop/interop_server.rb +1 -1
  9. data/bin/math_server.rb +1 -1
  10. data/bin/noproto_server.rb +1 -1
  11. data/ext/grpc/rb_byte_buffer.c +15 -189
  12. data/ext/grpc/rb_byte_buffer.h +4 -12
  13. data/ext/grpc/rb_call.c +514 -307
  14. data/ext/grpc/rb_call.h +4 -4
  15. data/ext/grpc/rb_channel.c +58 -34
  16. data/ext/grpc/rb_channel.h +0 -3
  17. data/ext/grpc/rb_channel_args.c +13 -4
  18. data/ext/grpc/rb_completion_queue.c +50 -23
  19. data/ext/grpc/rb_completion_queue.h +7 -3
  20. data/ext/grpc/rb_credentials.c +40 -28
  21. data/ext/grpc/rb_credentials.h +0 -4
  22. data/ext/grpc/rb_grpc.c +86 -67
  23. data/ext/grpc/rb_grpc.h +20 -10
  24. data/ext/grpc/rb_server.c +119 -26
  25. data/ext/grpc/rb_server.h +0 -4
  26. data/ext/grpc/rb_server_credentials.c +29 -16
  27. data/ext/grpc/rb_server_credentials.h +0 -4
  28. data/grpc.gemspec +11 -8
  29. data/lib/grpc.rb +1 -1
  30. data/lib/grpc/errors.rb +8 -7
  31. data/lib/grpc/generic/active_call.rb +104 -171
  32. data/lib/grpc/generic/bidi_call.rb +32 -60
  33. data/lib/grpc/generic/client_stub.rb +42 -31
  34. data/lib/grpc/generic/rpc_desc.rb +7 -12
  35. data/lib/grpc/generic/rpc_server.rb +253 -170
  36. data/lib/grpc/{core/event.rb → notifier.rb} +25 -9
  37. data/lib/grpc/version.rb +1 -1
  38. data/spec/call_spec.rb +23 -40
  39. data/spec/channel_spec.rb +11 -20
  40. data/spec/client_server_spec.rb +193 -175
  41. data/spec/credentials_spec.rb +2 -2
  42. data/spec/generic/active_call_spec.rb +59 -85
  43. data/spec/generic/client_stub_spec.rb +46 -64
  44. data/spec/generic/rpc_desc_spec.rb +50 -80
  45. data/spec/generic/rpc_server_pool_spec.rb +2 -3
  46. data/spec/generic/rpc_server_spec.rb +158 -29
  47. data/spec/server_spec.rb +1 -1
  48. data/spec/spec_helper.rb +8 -4
  49. metadata +27 -37
  50. data/ext/grpc/rb_event.c +0 -361
  51. data/ext/grpc/rb_event.h +0 -53
  52. data/ext/grpc/rb_metadata.c +0 -215
  53. data/ext/grpc/rb_metadata.h +0 -53
  54. data/spec/alloc_spec.rb +0 -44
  55. data/spec/byte_buffer_spec.rb +0 -67
  56. data/spec/event_spec.rb +0 -53
  57. data/spec/metadata_spec.rb +0 -64
@@ -61,11 +61,11 @@ describe Credentials do
61
61
  end
62
62
 
63
63
  describe '#compose' do
64
- it 'can be completed OK' do
64
+ it 'cannot be completed OK with 2 SSL creds' do
65
65
  certs = load_test_certs
66
66
  cred1 = Credentials.new(*certs)
67
67
  cred2 = Credentials.new(*certs)
68
- expect { cred1.compose(cred2) }.to_not raise_error
68
+ expect { cred1.compose(cred2) }.to raise_error
69
69
  end
70
70
  end
71
71
  end
@@ -34,12 +34,11 @@ include GRPC::Core::StatusCodes
34
34
  describe GRPC::ActiveCall do
35
35
  ActiveCall = GRPC::ActiveCall
36
36
  Call = GRPC::Core::Call
37
- CompletionType = GRPC::Core::CompletionType
37
+ CallOps = GRPC::Core::CallOps
38
38
 
39
39
  before(:each) do
40
40
  @pass_through = proc { |x| x }
41
41
  @server_tag = Object.new
42
- @server_done_tag = Object.new
43
42
  @tag = Object.new
44
43
 
45
44
  @client_queue = GRPC::Core::CompletionQueue.new
@@ -48,7 +47,7 @@ describe GRPC::ActiveCall do
48
47
  @server = GRPC::Core::Server.new(@server_queue, nil)
49
48
  server_port = @server.add_http2_port(host)
50
49
  @server.start
51
- @ch = GRPC::Core::Channel.new("localhost:#{server_port}", nil)
50
+ @ch = GRPC::Core::Channel.new("0.0.0.0:#{server_port}", nil)
52
51
  end
53
52
 
54
53
  after(:each) do
@@ -58,12 +57,10 @@ describe GRPC::ActiveCall do
58
57
  describe 'restricted view methods' do
59
58
  before(:each) do
60
59
  call = make_test_call
61
- done_tag, meta_tag = ActiveCall.client_invoke(call, @client_queue,
62
- deadline)
60
+ md_tag = ActiveCall.client_invoke(call, @client_queue, deadline)
63
61
  @client_call = ActiveCall.new(call, @client_queue, @pass_through,
64
62
  @pass_through, deadline,
65
- finished_tag: done_tag,
66
- read_metadata_tag: meta_tag)
63
+ metadata_tag: md_tag)
67
64
  end
68
65
 
69
66
  describe '#multi_req_view' do
@@ -90,48 +87,45 @@ describe GRPC::ActiveCall do
90
87
  describe '#remote_send' do
91
88
  it 'allows a client to send a payload to the server' do
92
89
  call = make_test_call
93
- done_tag, meta_tag = ActiveCall.client_invoke(call, @client_queue,
94
- deadline)
90
+ md_tag = ActiveCall.client_invoke(call, @client_queue, deadline)
95
91
  @client_call = ActiveCall.new(call, @client_queue, @pass_through,
96
92
  @pass_through, deadline,
97
- finished_tag: done_tag,
98
- read_metadata_tag: meta_tag)
93
+ metadata_tag: md_tag)
99
94
  msg = 'message is a string'
100
95
  @client_call.remote_send(msg)
101
96
 
102
97
  # check that server rpc new was received
103
- @server.request_call(@server_tag)
104
- ev = @server_queue.next(deadline)
105
- expect(ev.type).to be(CompletionType::SERVER_RPC_NEW)
106
- expect(ev.call).to be_a(Call)
107
- expect(ev.tag).to be(@server_tag)
98
+ recvd_rpc = @server.request_call(@server_queue, @server_tag, deadline)
99
+ expect(recvd_rpc).to_not eq nil
100
+ recvd_call = recvd_rpc.call
108
101
 
109
102
  # Accept the call, and verify that the server reads the response ok.
110
- ev.call.server_accept(@client_queue, @server_tag)
111
- ev.call.server_end_initial_metadata
112
- server_call = ActiveCall.new(ev.call, @client_queue, @pass_through,
103
+ server_ops = {
104
+ CallOps::SEND_INITIAL_METADATA => {}
105
+ }
106
+ recvd_call.run_batch(@server_queue, @server_tag, deadline, server_ops)
107
+ server_call = ActiveCall.new(recvd_call, @server_queue, @pass_through,
113
108
  @pass_through, deadline)
114
109
  expect(server_call.remote_read).to eq(msg)
115
110
  end
116
111
 
117
112
  it 'marshals the payload using the marshal func' do
118
113
  call = make_test_call
119
- done_tag, meta_tag = ActiveCall.client_invoke(call, @client_queue,
120
- deadline)
114
+ ActiveCall.client_invoke(call, @client_queue, deadline)
121
115
  marshal = proc { |x| 'marshalled:' + x }
122
116
  client_call = ActiveCall.new(call, @client_queue, marshal,
123
- @pass_through, deadline,
124
- finished_tag: done_tag,
125
- read_metadata_tag: meta_tag)
117
+ @pass_through, deadline)
126
118
  msg = 'message is a string'
127
119
  client_call.remote_send(msg)
128
120
 
129
121
  # confirm that the message was marshalled
130
- @server.request_call(@server_tag)
131
- ev = @server_queue.next(deadline)
132
- ev.call.server_accept(@client_queue, @server_tag)
133
- ev.call.server_end_initial_metadata
134
- server_call = ActiveCall.new(ev.call, @client_queue, @pass_through,
122
+ recvd_rpc = @server.request_call(@server_queue, @server_tag, deadline)
123
+ recvd_call = recvd_rpc.call
124
+ server_ops = {
125
+ CallOps::SEND_INITIAL_METADATA => nil
126
+ }
127
+ recvd_call.run_batch(@server_queue, @server_tag, deadline, server_ops)
128
+ server_call = ActiveCall.new(recvd_call, @server_queue, @pass_through,
135
129
  @pass_through, deadline)
136
130
  expect(server_call.remote_read).to eq('marshalled:' + msg)
137
131
  end
@@ -142,23 +136,22 @@ describe GRPC::ActiveCall do
142
136
  call = make_test_call
143
137
  ActiveCall.client_invoke(call, @client_queue, deadline,
144
138
  k1: 'v1', k2: 'v2')
145
- @server.request_call(@server_tag)
146
- ev = @server_queue.next(deadline)
147
- expect(ev).to_not be_nil
148
- expect(ev.result.metadata['k1']).to eq('v1')
149
- expect(ev.result.metadata['k2']).to eq('v2')
139
+ recvd_rpc = @server.request_call(@server_queue, @server_tag, deadline)
140
+ recvd_call = recvd_rpc.call
141
+ expect(recvd_call).to_not be_nil
142
+ expect(recvd_rpc.metadata).to_not be_nil
143
+ expect(recvd_rpc.metadata['k1']).to eq('v1')
144
+ expect(recvd_rpc.metadata['k2']).to eq('v2')
150
145
  end
151
146
  end
152
147
 
153
148
  describe '#remote_read' do
154
149
  it 'reads the response sent by a server' do
155
150
  call = make_test_call
156
- done_tag, meta_tag = ActiveCall.client_invoke(call, @client_queue,
157
- deadline)
151
+ md_tag = ActiveCall.client_invoke(call, @client_queue, deadline)
158
152
  client_call = ActiveCall.new(call, @client_queue, @pass_through,
159
153
  @pass_through, deadline,
160
- finished_tag: done_tag,
161
- read_metadata_tag: meta_tag)
154
+ metadata_tag: md_tag)
162
155
  msg = 'message is a string'
163
156
  client_call.remote_send(msg)
164
157
  server_call = expect_server_to_receive(msg)
@@ -168,12 +161,10 @@ describe GRPC::ActiveCall do
168
161
 
169
162
  it 'saves no metadata when the server adds no metadata' do
170
163
  call = make_test_call
171
- done_tag, meta_tag = ActiveCall.client_invoke(call, @client_queue,
172
- deadline)
164
+ md_tag = ActiveCall.client_invoke(call, @client_queue, deadline)
173
165
  client_call = ActiveCall.new(call, @client_queue, @pass_through,
174
166
  @pass_through, deadline,
175
- finished_tag: done_tag,
176
- read_metadata_tag: meta_tag)
167
+ metadata_tag: md_tag)
177
168
  msg = 'message is a string'
178
169
  client_call.remote_send(msg)
179
170
  server_call = expect_server_to_receive(msg)
@@ -185,12 +176,10 @@ describe GRPC::ActiveCall do
185
176
 
186
177
  it 'saves metadata add by the server' do
187
178
  call = make_test_call
188
- done_tag, meta_tag = ActiveCall.client_invoke(call, @client_queue,
189
- deadline)
179
+ md_tag = ActiveCall.client_invoke(call, @client_queue, deadline)
190
180
  client_call = ActiveCall.new(call, @client_queue, @pass_through,
191
181
  @pass_through, deadline,
192
- finished_tag: done_tag,
193
- read_metadata_tag: meta_tag)
182
+ metadata_tag: md_tag)
194
183
  msg = 'message is a string'
195
184
  client_call.remote_send(msg)
196
185
  server_call = expect_server_to_receive(msg, k1: 'v1', k2: 'v2')
@@ -203,12 +192,10 @@ describe GRPC::ActiveCall do
203
192
 
204
193
  it 'get a nil msg before a status when an OK status is sent' do
205
194
  call = make_test_call
206
- done_tag, meta_tag = ActiveCall.client_invoke(call, @client_queue,
207
- deadline)
195
+ md_tag = ActiveCall.client_invoke(call, @client_queue, deadline)
208
196
  client_call = ActiveCall.new(call, @client_queue, @pass_through,
209
197
  @pass_through, deadline,
210
- finished_tag: done_tag,
211
- read_metadata_tag: meta_tag)
198
+ metadata_tag: md_tag)
212
199
  msg = 'message is a string'
213
200
  client_call.remote_send(msg)
214
201
  client_call.writes_done(false)
@@ -222,13 +209,11 @@ describe GRPC::ActiveCall do
222
209
 
223
210
  it 'unmarshals the response using the unmarshal func' do
224
211
  call = make_test_call
225
- done_tag, meta_tag = ActiveCall.client_invoke(call, @client_queue,
226
- deadline)
212
+ md_tag = ActiveCall.client_invoke(call, @client_queue, deadline)
227
213
  unmarshal = proc { |x| 'unmarshalled:' + x }
228
214
  client_call = ActiveCall.new(call, @client_queue, @pass_through,
229
215
  unmarshal, deadline,
230
- finished_tag: done_tag,
231
- read_metadata_tag: meta_tag)
216
+ metadata_tag: md_tag)
232
217
 
233
218
  # confirm the client receives the unmarshalled message
234
219
  msg = 'message is a string'
@@ -249,13 +234,11 @@ describe GRPC::ActiveCall do
249
234
 
250
235
  it 'the returns an enumerator that can read n responses' do
251
236
  call = make_test_call
252
- done_tag, meta_tag = ActiveCall.client_invoke(call, @client_queue,
253
- deadline)
237
+ md_tag = ActiveCall.client_invoke(call, @client_queue, deadline)
254
238
  client_call = ActiveCall.new(call, @client_queue, @pass_through,
255
239
  @pass_through, deadline,
256
- finished_tag: done_tag,
257
- read_metadata_tag: meta_tag)
258
- msg = 'message is 4a string'
240
+ metadata_tag: md_tag)
241
+ msg = 'message is a string'
259
242
  reply = 'server_response'
260
243
  client_call.remote_send(msg)
261
244
  server_call = expect_server_to_receive(msg)
@@ -269,12 +252,10 @@ describe GRPC::ActiveCall do
269
252
 
270
253
  it 'the returns an enumerator that stops after an OK Status' do
271
254
  call = make_test_call
272
- done_tag, meta_tag = ActiveCall.client_invoke(call, @client_queue,
273
- deadline)
255
+ md_tag = ActiveCall.client_invoke(call, @client_queue, deadline)
274
256
  client_call = ActiveCall.new(call, @client_queue, @pass_through,
275
257
  @pass_through, deadline,
276
- read_metadata_tag: meta_tag,
277
- finished_tag: done_tag)
258
+ metadata_tag: md_tag)
278
259
  msg = 'message is a string'
279
260
  reply = 'server_response'
280
261
  client_call.remote_send(msg)
@@ -294,12 +275,10 @@ describe GRPC::ActiveCall do
294
275
  describe '#writes_done' do
295
276
  it 'finishes ok if the server sends a status response' do
296
277
  call = make_test_call
297
- done_tag, meta_tag = ActiveCall.client_invoke(call, @client_queue,
298
- deadline)
278
+ md_tag = ActiveCall.client_invoke(call, @client_queue, deadline)
299
279
  client_call = ActiveCall.new(call, @client_queue, @pass_through,
300
280
  @pass_through, deadline,
301
- finished_tag: done_tag,
302
- read_metadata_tag: meta_tag)
281
+ metadata_tag: md_tag)
303
282
  msg = 'message is a string'
304
283
  client_call.remote_send(msg)
305
284
  expect { client_call.writes_done(false) }.to_not raise_error
@@ -312,12 +291,10 @@ describe GRPC::ActiveCall do
312
291
 
313
292
  it 'finishes ok if the server sends an early status response' do
314
293
  call = make_test_call
315
- done_tag, meta_tag = ActiveCall.client_invoke(call, @client_queue,
316
- deadline)
294
+ md_tag = ActiveCall.client_invoke(call, @client_queue, deadline)
317
295
  client_call = ActiveCall.new(call, @client_queue, @pass_through,
318
296
  @pass_through, deadline,
319
- read_metadata_tag: meta_tag,
320
- finished_tag: done_tag)
297
+ metadata_tag: md_tag)
321
298
  msg = 'message is a string'
322
299
  client_call.remote_send(msg)
323
300
  server_call = expect_server_to_receive(msg)
@@ -330,12 +307,10 @@ describe GRPC::ActiveCall do
330
307
 
331
308
  it 'finishes ok if writes_done is true' do
332
309
  call = make_test_call
333
- done_tag, meta_tag = ActiveCall.client_invoke(call, @client_queue,
334
- deadline)
310
+ md_tag = ActiveCall.client_invoke(call, @client_queue, deadline)
335
311
  client_call = ActiveCall.new(call, @client_queue, @pass_through,
336
312
  @pass_through, deadline,
337
- read_metadata_tag: meta_tag,
338
- finished_tag: done_tag)
313
+ metadata_tag: md_tag)
339
314
  msg = 'message is a string'
340
315
  client_call.remote_send(msg)
341
316
  server_call = expect_server_to_receive(msg)
@@ -353,21 +328,20 @@ describe GRPC::ActiveCall do
353
328
  end
354
329
 
355
330
  def expect_server_to_be_invoked(**kw)
356
- @server.request_call(@server_tag)
357
- ev = @server_queue.next(deadline)
358
- ev.call.add_metadata(kw)
359
- ev.call.server_accept(@client_queue, @server_done_tag)
360
- ev.call.server_end_initial_metadata
361
- ActiveCall.new(ev.call, @client_queue, @pass_through,
362
- @pass_through, deadline,
363
- finished_tag: @server_done_tag)
331
+ recvd_rpc = @server.request_call(@server_queue, @server_tag, deadline)
332
+ expect(recvd_rpc).to_not eq nil
333
+ recvd_call = recvd_rpc.call
334
+ recvd_call.run_batch(@server_queue, @server_tag, deadline,
335
+ CallOps::SEND_INITIAL_METADATA => kw)
336
+ ActiveCall.new(recvd_call, @server_queue, @pass_through,
337
+ @pass_through, deadline)
364
338
  end
365
339
 
366
340
  def make_test_call
367
- @ch.create_call('dummy_method', 'dummy_host', deadline)
341
+ @ch.create_call(@client_queue, '/method', 'a.dummy.host', deadline)
368
342
  end
369
343
 
370
344
  def deadline
371
- Time.now + 1 # in 1 second; arbitrary
345
+ Time.now + 2 # in 2 seconds; arbitrary
372
346
  end
373
347
  end
@@ -28,17 +28,13 @@
28
28
  # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
29
 
30
30
  require 'grpc'
31
- require 'xray/thread_dump_signal_handler'
32
-
33
- NOOP = proc { |x| x }
34
- FAKE_HOST = 'localhost:0'
35
31
 
36
32
  def wakey_thread(&blk)
37
- awake_mutex, awake_cond = Mutex.new, ConditionVariable.new
33
+ n = GRPC::Notifier.new
38
34
  t = Thread.new do
39
- blk.call(awake_mutex, awake_cond)
35
+ blk.call(n)
40
36
  end
41
- awake_mutex.synchronize { awake_cond.wait(awake_mutex) }
37
+ n.wait
42
38
  t
43
39
  end
44
40
 
@@ -50,8 +46,11 @@ end
50
46
 
51
47
  include GRPC::Core::StatusCodes
52
48
  include GRPC::Core::TimeConsts
49
+ include GRPC::Core::CallOps
53
50
 
54
51
  describe 'ClientStub' do
52
+ let(:noop) { proc { |x| x } }
53
+
55
54
  before(:each) do
56
55
  Thread.abort_on_exception = true
57
56
  @server = nil
@@ -66,61 +65,56 @@ describe 'ClientStub' do
66
65
  end
67
66
 
68
67
  describe '#new' do
68
+ let(:fake_host) { 'localhost:0' }
69
69
  it 'can be created from a host and args' do
70
- host = FAKE_HOST
71
70
  opts = { a_channel_arg: 'an_arg' }
72
71
  blk = proc do
73
- GRPC::ClientStub.new(host, @cq, **opts)
72
+ GRPC::ClientStub.new(fake_host, @cq, **opts)
74
73
  end
75
74
  expect(&blk).not_to raise_error
76
75
  end
77
76
 
78
77
  it 'can be created with a default deadline' do
79
- host = FAKE_HOST
80
78
  opts = { a_channel_arg: 'an_arg', deadline: 5 }
81
79
  blk = proc do
82
- GRPC::ClientStub.new(host, @cq, **opts)
80
+ GRPC::ClientStub.new(fake_host, @cq, **opts)
83
81
  end
84
82
  expect(&blk).not_to raise_error
85
83
  end
86
84
 
87
85
  it 'can be created with an channel override' do
88
- host = FAKE_HOST
89
86
  opts = { a_channel_arg: 'an_arg', channel_override: @ch }
90
87
  blk = proc do
91
- GRPC::ClientStub.new(host, @cq, **opts)
88
+ GRPC::ClientStub.new(fake_host, @cq, **opts)
92
89
  end
93
90
  expect(&blk).not_to raise_error
94
91
  end
95
92
 
96
93
  it 'cannot be created with a bad channel override' do
97
- host = FAKE_HOST
98
94
  blk = proc do
99
95
  opts = { a_channel_arg: 'an_arg', channel_override: Object.new }
100
- GRPC::ClientStub.new(host, @cq, **opts)
96
+ GRPC::ClientStub.new(fake_host, @cq, **opts)
101
97
  end
102
98
  expect(&blk).to raise_error
103
99
  end
104
100
 
105
101
  it 'cannot be created with bad credentials' do
106
- host = FAKE_HOST
107
102
  blk = proc do
108
103
  opts = { a_channel_arg: 'an_arg', creds: Object.new }
109
- GRPC::ClientStub.new(host, @cq, **opts)
104
+ GRPC::ClientStub.new(fake_host, @cq, **opts)
110
105
  end
111
106
  expect(&blk).to raise_error
112
107
  end
113
108
 
114
109
  it 'can be created with test test credentials' do
115
110
  certs = load_test_certs
116
- host = FAKE_HOST
117
111
  blk = proc do
118
112
  opts = {
119
113
  GRPC::Core::Channel::SSL_TARGET => 'foo.test.google.fr',
120
114
  a_channel_arg: 'an_arg',
121
115
  creds: GRPC::Core::Credentials.new(certs[0], nil, nil)
122
116
  }
123
- GRPC::ClientStub.new(host, @cq, **opts)
117
+ GRPC::ClientStub.new(fake_host, @cq, **opts)
124
118
  end
125
119
  expect(&blk).to_not raise_error
126
120
  end
@@ -187,7 +181,7 @@ describe 'ClientStub' do
187
181
 
188
182
  describe 'without a call operation' do
189
183
  def get_response(stub)
190
- stub.request_response(@method, @sent_msg, NOOP, NOOP,
184
+ stub.request_response(@method, @sent_msg, noop, noop,
191
185
  k1: 'v1', k2: 'v2')
192
186
  end
193
187
 
@@ -196,7 +190,7 @@ describe 'ClientStub' do
196
190
 
197
191
  describe 'via a call operation' do
198
192
  def get_response(stub)
199
- op = stub.request_response(@method, @sent_msg, NOOP, NOOP,
193
+ op = stub.request_response(@method, @sent_msg, noop, noop,
200
194
  return_op: true, k1: 'v1', k2: 'v2')
201
195
  expect(op).to be_a(GRPC::ActiveCall::Operation)
202
196
  op.execute
@@ -259,7 +253,7 @@ describe 'ClientStub' do
259
253
 
260
254
  describe 'without a call operation' do
261
255
  def get_response(stub)
262
- stub.client_streamer(@method, @sent_msgs, NOOP, NOOP,
256
+ stub.client_streamer(@method, @sent_msgs, noop, noop,
263
257
  k1: 'v1', k2: 'v2')
264
258
  end
265
259
 
@@ -268,7 +262,7 @@ describe 'ClientStub' do
268
262
 
269
263
  describe 'via a call operation' do
270
264
  def get_response(stub)
271
- op = stub.client_streamer(@method, @sent_msgs, NOOP, NOOP,
265
+ op = stub.client_streamer(@method, @sent_msgs, noop, noop,
272
266
  return_op: true, k1: 'v1', k2: 'v2')
273
267
  expect(op).to be_a(GRPC::ActiveCall::Operation)
274
268
  op.execute
@@ -333,7 +327,7 @@ describe 'ClientStub' do
333
327
 
334
328
  describe 'without a call operation' do
335
329
  def get_responses(stub)
336
- e = stub.server_streamer(@method, @sent_msg, NOOP, NOOP,
330
+ e = stub.server_streamer(@method, @sent_msg, noop, noop,
337
331
  k1: 'v1', k2: 'v2')
338
332
  expect(e).to be_a(Enumerator)
339
333
  e
@@ -344,7 +338,7 @@ describe 'ClientStub' do
344
338
 
345
339
  describe 'via a call operation' do
346
340
  def get_responses(stub)
347
- op = stub.server_streamer(@method, @sent_msg, NOOP, NOOP,
341
+ op = stub.server_streamer(@method, @sent_msg, noop, noop,
348
342
  return_op: true, k1: 'v1', k2: 'v2')
349
343
  expect(op).to be_a(GRPC::ActiveCall::Operation)
350
344
  e = op.execute
@@ -361,34 +355,30 @@ describe 'ClientStub' do
361
355
  before(:each) do
362
356
  @sent_msgs = Array.new(3) { |i| 'msg_' + (i + 1).to_s }
363
357
  @replys = Array.new(3) { |i| 'reply_' + (i + 1).to_s }
358
+ server_port = create_test_server
359
+ @host = "localhost:#{server_port}"
364
360
  end
365
361
 
366
362
  it 'supports sending all the requests first', bidi: true do
367
- server_port = create_test_server
368
- host = "localhost:#{server_port}"
369
363
  th = run_bidi_streamer_handle_inputs_first(@sent_msgs, @replys,
370
364
  @pass)
371
- stub = GRPC::ClientStub.new(host, @cq)
365
+ stub = GRPC::ClientStub.new(@host, @cq)
372
366
  e = get_responses(stub)
373
367
  expect(e.collect { |r| r }).to eq(@replys)
374
368
  th.join
375
369
  end
376
370
 
377
371
  it 'supports client-initiated ping pong', bidi: true do
378
- server_port = create_test_server
379
- host = "localhost:#{server_port}"
380
372
  th = run_bidi_streamer_echo_ping_pong(@sent_msgs, @pass, true)
381
- stub = GRPC::ClientStub.new(host, @cq)
373
+ stub = GRPC::ClientStub.new(@host, @cq)
382
374
  e = get_responses(stub)
383
375
  expect(e.collect { |r| r }).to eq(@sent_msgs)
384
376
  th.join
385
377
  end
386
378
 
387
379
  it 'supports a server-initiated ping pong', bidi: true do
388
- server_port = create_test_server
389
- host = "localhost:#{server_port}"
390
380
  th = run_bidi_streamer_echo_ping_pong(@sent_msgs, @pass, false)
391
- stub = GRPC::ClientStub.new(host, @cq)
381
+ stub = GRPC::ClientStub.new(@host, @cq)
392
382
  e = get_responses(stub)
393
383
  expect(e.collect { |r| r }).to eq(@sent_msgs)
394
384
  th.join
@@ -397,7 +387,7 @@ describe 'ClientStub' do
397
387
 
398
388
  describe 'without a call operation' do
399
389
  def get_responses(stub)
400
- e = stub.bidi_streamer(@method, @sent_msgs, NOOP, NOOP)
390
+ e = stub.bidi_streamer(@method, @sent_msgs, noop, noop)
401
391
  expect(e).to be_a(Enumerator)
402
392
  e
403
393
  end
@@ -407,7 +397,7 @@ describe 'ClientStub' do
407
397
 
408
398
  describe 'via a call operation' do
409
399
  def get_responses(stub)
410
- op = stub.bidi_streamer(@method, @sent_msgs, NOOP, NOOP,
400
+ op = stub.bidi_streamer(@method, @sent_msgs, noop, noop,
411
401
  return_op: true)
412
402
  expect(op).to be_a(GRPC::ActiveCall::Operation)
413
403
  e = op.execute
@@ -421,8 +411,8 @@ describe 'ClientStub' do
421
411
 
422
412
  def run_server_streamer(expected_input, replys, status, **kw)
423
413
  wanted_metadata = kw.clone
424
- wakey_thread do |mtx, cnd|
425
- c = expect_server_to_be_invoked(mtx, cnd)
414
+ wakey_thread do |notifier|
415
+ c = expect_server_to_be_invoked(notifier)
426
416
  wanted_metadata.each do |k, v|
427
417
  expect(c.metadata[k.to_s]).to eq(v)
428
418
  end
@@ -434,8 +424,8 @@ describe 'ClientStub' do
434
424
 
435
425
  def run_bidi_streamer_handle_inputs_first(expected_inputs, replys,
436
426
  status)
437
- wakey_thread do |mtx, cnd|
438
- c = expect_server_to_be_invoked(mtx, cnd)
427
+ wakey_thread do |notifier|
428
+ c = expect_server_to_be_invoked(notifier)
439
429
  expected_inputs.each { |i| expect(c.remote_read).to eq(i) }
440
430
  replys.each { |r| c.remote_send(r) }
441
431
  c.send_status(status, status == @pass ? 'OK' : 'NOK', true)
@@ -443,8 +433,8 @@ describe 'ClientStub' do
443
433
  end
444
434
 
445
435
  def run_bidi_streamer_echo_ping_pong(expected_inputs, status, client_starts)
446
- wakey_thread do |mtx, cnd|
447
- c = expect_server_to_be_invoked(mtx, cnd)
436
+ wakey_thread do |notifier|
437
+ c = expect_server_to_be_invoked(notifier)
448
438
  expected_inputs.each do |i|
449
439
  if client_starts
450
440
  expect(c.remote_read).to eq(i)
@@ -460,8 +450,8 @@ describe 'ClientStub' do
460
450
 
461
451
  def run_client_streamer(expected_inputs, resp, status, **kw)
462
452
  wanted_metadata = kw.clone
463
- wakey_thread do |mtx, cnd|
464
- c = expect_server_to_be_invoked(mtx, cnd)
453
+ wakey_thread do |notifier|
454
+ c = expect_server_to_be_invoked(notifier)
465
455
  expected_inputs.each { |i| expect(c.remote_read).to eq(i) }
466
456
  wanted_metadata.each do |k, v|
467
457
  expect(c.metadata[k.to_s]).to eq(v)
@@ -473,8 +463,8 @@ describe 'ClientStub' do
473
463
 
474
464
  def run_request_response(expected_input, resp, status, **kw)
475
465
  wanted_metadata = kw.clone
476
- wakey_thread do |mtx, cnd|
477
- c = expect_server_to_be_invoked(mtx, cnd)
466
+ wakey_thread do |notifier|
467
+ c = expect_server_to_be_invoked(notifier)
478
468
  expect(c.remote_read).to eq(expected_input)
479
469
  wanted_metadata.each do |k, v|
480
470
  expect(c.metadata[k.to_s]).to eq(v)
@@ -490,24 +480,16 @@ describe 'ClientStub' do
490
480
  @server.add_http2_port('0.0.0.0:0')
491
481
  end
492
482
 
493
- def start_test_server(awake_mutex, awake_cond)
483
+ def expect_server_to_be_invoked(notifier)
494
484
  @server.start
495
- @server_tag = Object.new
496
- @server.request_call(@server_tag)
497
- awake_mutex.synchronize { awake_cond.signal }
498
- end
499
-
500
- def expect_server_to_be_invoked(awake_mutex, awake_cond)
501
- start_test_server(awake_mutex, awake_cond)
502
- ev = @server_queue.pluck(@server_tag, INFINITE_FUTURE)
503
- fail OutOfTime if ev.nil?
504
- server_call = ev.call
505
- server_call.metadata = ev.result.metadata
506
- finished_tag = Object.new
507
- server_call.server_accept(@server_queue, finished_tag)
508
- server_call.server_end_initial_metadata
509
- GRPC::ActiveCall.new(server_call, @server_queue, NOOP, NOOP,
510
- INFINITE_FUTURE,
511
- finished_tag: finished_tag)
485
+ notifier.notify(nil)
486
+ server_tag = Object.new
487
+ recvd_rpc = @server.request_call(@server_queue, server_tag,
488
+ INFINITE_FUTURE)
489
+ recvd_call = recvd_rpc.call
490
+ recvd_call.metadata = recvd_rpc.metadata
491
+ recvd_call.run_batch(@server_queue, server_tag, Time.now + 2,
492
+ SEND_INITIAL_METADATA => nil)
493
+ GRPC::ActiveCall.new(recvd_call, @server_queue, noop, noop, INFINITE_FUTURE)
512
494
  end
513
495
  end