grpc 1.0.1-universal-darwin → 1.1.2-universal-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.

Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/etc/roots.pem +39 -111
  3. data/src/ruby/ext/grpc/extconf.rb +0 -1
  4. data/src/ruby/ext/grpc/rb_byte_buffer.c +8 -7
  5. data/src/ruby/ext/grpc/rb_call.c +15 -5
  6. data/src/ruby/ext/grpc/rb_channel.c +1 -1
  7. data/src/ruby/ext/grpc/rb_compression_options.c +466 -0
  8. data/src/ruby/ext/grpc/rb_compression_options.h +44 -0
  9. data/src/ruby/ext/grpc/rb_grpc.c +3 -1
  10. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +198 -190
  11. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +306 -294
  12. data/src/ruby/ext/grpc/rb_server.c +18 -12
  13. data/src/ruby/lib/grpc/2.0/grpc_c.bundle +0 -0
  14. data/src/ruby/lib/grpc/2.1/grpc_c.bundle +0 -0
  15. data/src/ruby/lib/grpc/2.2/grpc_c.bundle +0 -0
  16. data/src/ruby/lib/grpc/2.3/grpc_c.bundle +0 -0
  17. data/src/ruby/lib/grpc/2.4/grpc_c.bundle +0 -0
  18. data/src/ruby/lib/grpc/errors.rb +154 -2
  19. data/src/ruby/lib/grpc/generic/active_call.rb +144 -63
  20. data/src/ruby/lib/grpc/generic/bidi_call.rb +18 -2
  21. data/src/ruby/lib/grpc/generic/client_stub.rb +7 -5
  22. data/src/ruby/lib/grpc/generic/rpc_desc.rb +39 -13
  23. data/src/ruby/lib/grpc/generic/rpc_server.rb +51 -24
  24. data/src/ruby/lib/grpc/generic/service.rb +3 -2
  25. data/src/ruby/lib/grpc/version.rb +1 -1
  26. data/src/ruby/pb/grpc/health/checker.rb +3 -1
  27. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +7 -0
  28. data/src/ruby/pb/test/client.rb +307 -7
  29. data/src/ruby/pb/test/server.rb +26 -1
  30. data/src/ruby/spec/compression_options_spec.rb +164 -0
  31. data/src/ruby/spec/error_sanity_spec.rb +64 -0
  32. data/src/ruby/spec/generic/active_call_spec.rb +290 -12
  33. data/src/ruby/spec/generic/client_stub_spec.rb +91 -41
  34. data/src/ruby/spec/generic/rpc_desc_spec.rb +36 -16
  35. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +22 -28
  36. data/src/ruby/spec/generic/rpc_server_spec.rb +6 -6
  37. data/src/ruby/spec/pb/health/checker_spec.rb +27 -19
  38. data/src/ruby/spec/spec_helper.rb +2 -0
  39. metadata +18 -8
@@ -190,15 +190,14 @@ describe 'ClientStub' do
190
190
  end
191
191
  creds = GRPC::Core::CallCredentials.new(failing_auth)
192
192
 
193
- error_occured = false
193
+ unauth_error_occured = false
194
194
  begin
195
195
  get_response(stub, credentials: creds)
196
- rescue GRPC::BadStatus => e
197
- error_occured = true
198
- expect(e.code).to eq(GRPC::Core::StatusCodes::UNAUTHENTICATED)
196
+ rescue GRPC::Unauthenticated => e
197
+ unauth_error_occured = true
199
198
  expect(e.details.include?(error_message)).to be true
200
199
  end
201
- expect(error_occured).to eq(true)
200
+ expect(unauth_error_occured).to eq(true)
202
201
 
203
202
  # Kill the server thread so tests can complete
204
203
  th.kill
@@ -217,31 +216,45 @@ describe 'ClientStub' do
217
216
  end
218
217
 
219
218
  describe 'via a call operation' do
220
- def get_response(stub, credentials: nil)
219
+ def get_response(stub, run_start_call_first: false, credentials: nil)
221
220
  op = stub.request_response(@method, @sent_msg, noop, noop,
222
221
  return_op: true,
223
222
  metadata: { k1: 'v1', k2: 'v2' },
224
223
  deadline: from_relative_time(2),
225
224
  credentials: credentials)
226
225
  expect(op).to be_a(GRPC::ActiveCall::Operation)
227
- op.execute
226
+ op.start_call if run_start_call_first
227
+ result = op.execute
228
+ op.wait # make sure wait doesn't hang
229
+ result
228
230
  end
229
231
 
230
232
  it_behaves_like 'request response'
231
- end
232
- end
233
233
 
234
- describe '#client_streamer' do
235
- shared_examples 'client streaming' do
236
- before(:each) do
234
+ it 'sends metadata to the server ok when running start_call first' do
237
235
  server_port = create_test_server
238
236
  host = "localhost:#{server_port}"
239
- @stub = GRPC::ClientStub.new(host, :this_channel_is_insecure)
240
- @metadata = { k1: 'v1', k2: 'v2' }
241
- @sent_msgs = Array.new(3) { |i| 'msg_' + (i + 1).to_s }
242
- @resp = 'a_reply'
237
+ th = run_request_response(@sent_msg, @resp, @pass,
238
+ k1: 'v1', k2: 'v2')
239
+ stub = GRPC::ClientStub.new(host, :this_channel_is_insecure)
240
+ expect(get_response(stub)).to eq(@resp)
241
+ th.join
243
242
  end
243
+ end
244
+ end
245
+
246
+ describe '#client_streamer' do
247
+ before(:each) do
248
+ Thread.abort_on_exception = true
249
+ server_port = create_test_server
250
+ host = "localhost:#{server_port}"
251
+ @stub = GRPC::ClientStub.new(host, :this_channel_is_insecure)
252
+ @metadata = { k1: 'v1', k2: 'v2' }
253
+ @sent_msgs = Array.new(3) { |i| 'msg_' + (i + 1).to_s }
254
+ @resp = 'a_reply'
255
+ end
244
256
 
257
+ shared_examples 'client streaming' do
245
258
  it 'should send requests to/receive a reply from a server' do
246
259
  th = run_client_streamer(@sent_msgs, @resp, @pass)
247
260
  expect(get_response(@stub)).to eq(@resp)
@@ -280,24 +293,33 @@ describe 'ClientStub' do
280
293
  end
281
294
 
282
295
  describe 'via a call operation' do
283
- def get_response(stub)
296
+ def get_response(stub, run_start_call_first: false)
284
297
  op = stub.client_streamer(@method, @sent_msgs, noop, noop,
285
298
  return_op: true, metadata: @metadata)
286
299
  expect(op).to be_a(GRPC::ActiveCall::Operation)
287
- op.execute
300
+ op.start_call if run_start_call_first
301
+ result = op.execute
302
+ op.wait # make sure wait doesn't hang
303
+ result
288
304
  end
289
305
 
290
306
  it_behaves_like 'client streaming'
307
+
308
+ it 'sends metadata to the server ok when running start_call first' do
309
+ th = run_client_streamer(@sent_msgs, @resp, @pass, **@metadata)
310
+ expect(get_response(@stub, run_start_call_first: true)).to eq(@resp)
311
+ th.join
312
+ end
291
313
  end
292
314
  end
293
315
 
294
316
  describe '#server_streamer' do
295
- shared_examples 'server streaming' do
296
- before(:each) do
297
- @sent_msg = 'a_msg'
298
- @replys = Array.new(3) { |i| 'reply_' + (i + 1).to_s }
299
- end
317
+ before(:each) do
318
+ @sent_msg = 'a_msg'
319
+ @replys = Array.new(3) { |i| 'reply_' + (i + 1).to_s }
320
+ end
300
321
 
322
+ shared_examples 'server streaming' do
301
323
  it 'should send a request to/receive replies from a server' do
302
324
  server_port = create_test_server
303
325
  host = "localhost:#{server_port}"
@@ -341,29 +363,44 @@ describe 'ClientStub' do
341
363
  end
342
364
 
343
365
  describe 'via a call operation' do
344
- def get_responses(stub)
345
- op = stub.server_streamer(@method, @sent_msg, noop, noop,
346
- return_op: true,
347
- metadata: { k1: 'v1', k2: 'v2' })
348
- expect(op).to be_a(GRPC::ActiveCall::Operation)
349
- e = op.execute
366
+ after(:each) do
367
+ @op.wait # make sure wait doesn't hang
368
+ end
369
+ def get_responses(stub, run_start_call_first: false)
370
+ @op = stub.server_streamer(@method, @sent_msg, noop, noop,
371
+ return_op: true,
372
+ metadata: { k1: 'v1', k2: 'v2' })
373
+ expect(@op).to be_a(GRPC::ActiveCall::Operation)
374
+ @op.start_call if run_start_call_first
375
+ e = @op.execute
350
376
  expect(e).to be_a(Enumerator)
351
377
  e
352
378
  end
353
379
 
354
380
  it_behaves_like 'server streaming'
381
+
382
+ it 'should send metadata to the server ok when start_call is run first' do
383
+ server_port = create_test_server
384
+ host = "localhost:#{server_port}"
385
+ th = run_server_streamer(@sent_msg, @replys, @fail,
386
+ k1: 'v1', k2: 'v2')
387
+ stub = GRPC::ClientStub.new(host, :this_channel_is_insecure)
388
+ e = get_responses(stub, run_start_call_first: true)
389
+ expect { e.collect { |r| r } }.to raise_error(GRPC::BadStatus)
390
+ th.join
391
+ end
355
392
  end
356
393
  end
357
394
 
358
395
  describe '#bidi_streamer' do
359
- shared_examples 'bidi streaming' do
360
- before(:each) do
361
- @sent_msgs = Array.new(3) { |i| 'msg_' + (i + 1).to_s }
362
- @replys = Array.new(3) { |i| 'reply_' + (i + 1).to_s }
363
- server_port = create_test_server
364
- @host = "localhost:#{server_port}"
365
- end
396
+ before(:each) do
397
+ @sent_msgs = Array.new(3) { |i| 'msg_' + (i + 1).to_s }
398
+ @replys = Array.new(3) { |i| 'reply_' + (i + 1).to_s }
399
+ server_port = create_test_server
400
+ @host = "localhost:#{server_port}"
401
+ end
366
402
 
403
+ shared_examples 'bidi streaming' do
367
404
  it 'supports sending all the requests first', bidi: true do
368
405
  th = run_bidi_streamer_handle_inputs_first(@sent_msgs, @replys,
369
406
  @pass)
@@ -401,16 +438,29 @@ describe 'ClientStub' do
401
438
  end
402
439
 
403
440
  describe 'via a call operation' do
404
- def get_responses(stub)
405
- op = stub.bidi_streamer(@method, @sent_msgs, noop, noop,
406
- return_op: true)
407
- expect(op).to be_a(GRPC::ActiveCall::Operation)
408
- e = op.execute
441
+ after(:each) do
442
+ @op.wait # make sure wait doesn't hang
443
+ end
444
+ def get_responses(stub, run_start_call_first: false)
445
+ @op = stub.bidi_streamer(@method, @sent_msgs, noop, noop,
446
+ return_op: true)
447
+ expect(@op).to be_a(GRPC::ActiveCall::Operation)
448
+ @op.start_call if run_start_call_first
449
+ e = @op.execute
409
450
  expect(e).to be_a(Enumerator)
410
451
  e
411
452
  end
412
453
 
413
454
  it_behaves_like 'bidi streaming'
455
+
456
+ it 'can run start_call before executing the call' do
457
+ th = run_bidi_streamer_handle_inputs_first(@sent_msgs, @replys,
458
+ @pass)
459
+ stub = GRPC::ClientStub.new(@host, :this_channel_is_insecure)
460
+ e = get_responses(stub, run_start_call_first: true)
461
+ expect(e.collect { |r| r }).to eq(@replys)
462
+ th.join
463
+ end
414
464
  end
415
465
  end
416
466
 
@@ -48,7 +48,6 @@ describe GRPC::RpcDesc do
48
48
  @bidi_streamer = RpcDesc.new('ss', Stream.new(Object.new),
49
49
  Stream.new(Object.new), 'encode', 'decode')
50
50
  @bs_code = INTERNAL
51
- @no_reason = 'no reason given'
52
51
  @ok_response = Object.new
53
52
  end
54
53
 
@@ -62,8 +61,9 @@ describe GRPC::RpcDesc do
62
61
 
63
62
  it 'sends status UNKNOWN if other StandardErrors are raised' do
64
63
  expect(@call).to receive(:remote_read).once.and_return(Object.new)
65
- expect(@call).to receive(:send_status) .once.with(UNKNOWN, @no_reason,
66
- false, metadata: {})
64
+ expect(@call).to receive(:send_status).once.with(UNKNOWN,
65
+ arg_error_msg,
66
+ false, metadata: {})
67
67
  this_desc.run_server_method(@call, method(:other_error))
68
68
  end
69
69
 
@@ -83,6 +83,7 @@ describe GRPC::RpcDesc do
83
83
  before(:each) do
84
84
  @call = double('active_call')
85
85
  allow(@call).to receive(:single_req_view).and_return(@call)
86
+ allow(@call).to receive(:output_metadata).and_return(@call)
86
87
  end
87
88
 
88
89
  it_behaves_like 'it handles errors'
@@ -90,10 +91,10 @@ describe GRPC::RpcDesc do
90
91
  it 'sends a response and closes the stream if there no errors' do
91
92
  req = Object.new
92
93
  expect(@call).to receive(:remote_read).once.and_return(req)
93
- expect(@call).to receive(:remote_send).once.with(@ok_response)
94
- expect(@call).to receive(:output_metadata).and_return(fake_md)
95
- expect(@call).to receive(:send_status).once.with(OK, 'OK', true,
96
- metadata: fake_md)
94
+ expect(@call).to receive(:output_metadata).once.and_return(fake_md)
95
+ expect(@call).to receive(:server_unary_response).once
96
+ .with(@ok_response, trailing_metadata: fake_md)
97
+
97
98
  this_desc.run_server_method(@call, method(:fake_reqresp))
98
99
  end
99
100
  end
@@ -111,13 +112,15 @@ describe GRPC::RpcDesc do
111
112
  end
112
113
 
113
114
  it 'sends status UNKNOWN if other StandardErrors are raised' do
114
- expect(@call).to receive(:send_status).once.with(UNKNOWN, @no_reason,
115
+ expect(@call).to receive(:send_status).once.with(UNKNOWN, arg_error_msg,
115
116
  false, metadata: {})
116
117
  @client_streamer.run_server_method(@call, method(:other_error_alt))
117
118
  end
118
119
 
119
120
  it 'absorbs CallError with no further action' do
120
- expect(@call).to receive(:remote_send).once.and_raise(CallError)
121
+ expect(@call).to receive(:server_unary_response).once.and_raise(
122
+ CallError)
123
+ allow(@call).to receive(:output_metadata).and_return({})
121
124
  blk = proc do
122
125
  @client_streamer.run_server_method(@call, method(:fake_clstream))
123
126
  end
@@ -125,10 +128,11 @@ describe GRPC::RpcDesc do
125
128
  end
126
129
 
127
130
  it 'sends a response and closes the stream if there no errors' do
128
- expect(@call).to receive(:remote_send).once.with(@ok_response)
129
- expect(@call).to receive(:output_metadata).and_return(fake_md)
130
- expect(@call).to receive(:send_status).once.with(OK, 'OK', true,
131
- metadata: fake_md)
131
+ expect(@call).to receive(:output_metadata).and_return(
132
+ fake_md)
133
+ expect(@call).to receive(:server_unary_response).once
134
+ .with(@ok_response, trailing_metadata: fake_md)
135
+
132
136
  @client_streamer.run_server_method(@call, method(:fake_clstream))
133
137
  end
134
138
  end
@@ -170,8 +174,9 @@ describe GRPC::RpcDesc do
170
174
  end
171
175
 
172
176
  it 'sends status UNKNOWN if other StandardErrors are raised' do
177
+ error_msg = arg_error_msg(StandardError.new)
173
178
  expect(@call).to receive(:run_server_bidi).and_raise(StandardError)
174
- expect(@call).to receive(:send_status).once.with(UNKNOWN, @no_reason,
179
+ expect(@call).to receive(:send_status).once.with(UNKNOWN, error_msg,
175
180
  false, metadata: {})
176
181
  @bidi_streamer.run_server_method(@call, method(:other_error_alt))
177
182
  end
@@ -196,6 +201,9 @@ describe GRPC::RpcDesc do
196
201
  def fake_svstream(_arg1, _arg2)
197
202
  end
198
203
 
204
+ def fake_three_args(_arg1, _arg2, _arg3)
205
+ end
206
+
199
207
  it 'raises when a request_response does not have 2 args' do
200
208
  [:fake_clstream, :no_arg].each do |mth|
201
209
  blk = proc do
@@ -244,8 +252,8 @@ describe GRPC::RpcDesc do
244
252
  expect(&blk).to_not raise_error
245
253
  end
246
254
 
247
- it 'raises when a bidi streamer does not have 1 arg' do
248
- [:fake_svstream, :no_arg].each do |mth|
255
+ it 'raises when a bidi streamer does not have 1 or 2 args' do
256
+ [:fake_three_args, :no_arg].each do |mth|
249
257
  blk = proc do
250
258
  @bidi_streamer.assert_arity_matches(method(mth))
251
259
  end
@@ -259,6 +267,13 @@ describe GRPC::RpcDesc do
259
267
  end
260
268
  expect(&blk).to_not raise_error
261
269
  end
270
+
271
+ it 'passes when a bidi streamer has 2 args' do
272
+ blk = proc do
273
+ @bidi_streamer.assert_arity_matches(method(:fake_svstream))
274
+ end
275
+ expect(&blk).to_not raise_error
276
+ end
262
277
  end
263
278
 
264
279
  describe '#request_response?' do
@@ -328,4 +343,9 @@ describe GRPC::RpcDesc do
328
343
  def other_error_alt(_call)
329
344
  fail(ArgumentError, 'other error')
330
345
  end
346
+
347
+ def arg_error_msg(error = nil)
348
+ error ||= ArgumentError.new('other error')
349
+ "#{error.class}: #{error.message}"
350
+ end
331
351
  end
@@ -29,6 +29,8 @@
29
29
 
30
30
  require 'grpc'
31
31
 
32
+ Thread.abort_on_exception = true
33
+
32
34
  describe GRPC::Pool do
33
35
  Pool = GRPC::Pool
34
36
 
@@ -44,32 +46,34 @@ describe GRPC::Pool do
44
46
  end
45
47
  end
46
48
 
47
- describe '#jobs_waiting' do
48
- it 'at start, it is zero' do
49
+ describe '#ready_for_work?' do
50
+ it 'before start it is not ready' do
49
51
  p = Pool.new(1)
50
- expect(p.jobs_waiting).to be(0)
52
+ expect(p.ready_for_work?).to be(false)
51
53
  end
52
54
 
53
- it 'it increases, with each scheduled job if the pool is not running' do
54
- p = Pool.new(1)
55
- job = proc {}
56
- expect(p.jobs_waiting).to be(0)
57
- 5.times do |i|
55
+ it 'it stops being ready after all workers jobs waiting or running' do
56
+ p = Pool.new(5)
57
+ p.start
58
+ job = proc { sleep(3) } # sleep so workers busy when done scheduling
59
+ 5.times do
60
+ expect(p.ready_for_work?).to be(true)
58
61
  p.schedule(&job)
59
- expect(p.jobs_waiting).to be(i + 1)
60
62
  end
63
+ expect(p.ready_for_work?).to be(false)
61
64
  end
62
65
 
63
- it 'it decreases as jobs are run' do
64
- p = Pool.new(1)
66
+ it 'it becomes ready again after jobs complete' do
67
+ p = Pool.new(5)
68
+ p.start
65
69
  job = proc {}
66
- expect(p.jobs_waiting).to be(0)
67
- 3.times do
70
+ 5.times do
71
+ expect(p.ready_for_work?).to be(true)
68
72
  p.schedule(&job)
69
73
  end
70
- p.start
71
- sleep 2
72
- expect(p.jobs_waiting).to be(0)
74
+ expect(p.ready_for_work?).to be(false)
75
+ sleep 5 # give the pool time do get at least one task done
76
+ expect(p.ready_for_work?).to be(true)
73
77
  end
74
78
  end
75
79
 
@@ -113,18 +117,8 @@ describe GRPC::Pool do
113
117
  end
114
118
 
115
119
  describe '#start' do
116
- it 'runs pre-scheduled jobs' do
117
- p = Pool.new(2)
118
- o, q = Object.new, Queue.new
119
- n = 5 # arbitrary
120
- n.times { p.schedule(o, &q.method(:push)) }
121
- p.start
122
- n.times { expect(q.pop).to be(o) }
123
- p.stop
124
- end
125
-
126
- it 'runs jobs as they are scheduled ' do
127
- p = Pool.new(2)
120
+ it 'runs jobs as they are scheduled' do
121
+ p = Pool.new(5)
128
122
  o, q = Object.new, Queue.new
129
123
  p.start
130
124
  n = 5 # arbitrary
@@ -395,9 +395,9 @@ describe GRPC::RpcServer do
395
395
  it 'should return RESOURCE_EXHAUSTED on too many jobs', server: true do
396
396
  opts = {
397
397
  server_args: { a_channel_arg: 'an_arg' },
398
- pool_size: 1,
398
+ pool_size: 2,
399
399
  poll_period: 1,
400
- max_waiting_requests: 0
400
+ max_waiting_requests: 1
401
401
  }
402
402
  alt_srv = RpcServer.new(**opts)
403
403
  alt_srv.handle(SlowService)
@@ -406,7 +406,7 @@ describe GRPC::RpcServer do
406
406
  t = Thread.new { alt_srv.run }
407
407
  alt_srv.wait_till_running
408
408
  req = EchoMsg.new
409
- n = 5 # arbitrary, use as many to ensure the server pool is exceeded
409
+ n = 20 # arbitrary, use as many to ensure the server pool is exceeded
410
410
  threads = []
411
411
  one_failed_as_unavailable = false
412
412
  n.times do
@@ -414,9 +414,8 @@ describe GRPC::RpcServer do
414
414
  stub = SlowStub.new(alt_host, :this_channel_is_insecure)
415
415
  begin
416
416
  stub.an_rpc(req)
417
- rescue GRPC::BadStatus => e
418
- one_failed_as_unavailable =
419
- e.code == StatusCodes::RESOURCE_EXHAUSTED
417
+ rescue GRPC::ResourceExhausted
418
+ one_failed_as_unavailable = true
420
419
  end
421
420
  end
422
421
  end
@@ -463,6 +462,7 @@ describe GRPC::RpcServer do
463
462
  'connect_k1' => 'connect_v1'
464
463
  }
465
464
  wanted_md.each do |key, value|
465
+ puts "key: #{key}"
466
466
  expect(op.metadata[key]).to eq(value)
467
467
  end
468
468
  @srv.stop