grpc 1.6.7-x86-linux → 1.7.0.pre1-x86-linux

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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/grpc_c.32.ruby +0 -0
  3. data/grpc_c.64.ruby +0 -0
  4. data/src/ruby/ext/grpc/rb_call_credentials.c +6 -2
  5. data/src/ruby/ext/grpc/rb_grpc.c +1 -1
  6. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +30 -20
  7. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +50 -35
  8. data/src/ruby/lib/grpc.rb +1 -0
  9. data/src/ruby/lib/grpc/2.0/grpc_c.so +0 -0
  10. data/src/ruby/lib/grpc/2.1/grpc_c.so +0 -0
  11. data/src/ruby/lib/grpc/2.2/grpc_c.so +0 -0
  12. data/src/ruby/lib/grpc/2.3/grpc_c.so +0 -0
  13. data/src/ruby/lib/grpc/2.4/grpc_c.so +0 -0
  14. data/src/ruby/lib/grpc/generic/active_call.rb +34 -9
  15. data/src/ruby/lib/grpc/generic/bidi_call.rb +19 -10
  16. data/src/ruby/lib/grpc/generic/client_stub.rb +95 -38
  17. data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
  18. data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
  19. data/src/ruby/lib/grpc/generic/rpc_desc.rb +66 -20
  20. data/src/ruby/lib/grpc/generic/rpc_server.rb +15 -3
  21. data/src/ruby/lib/grpc/google_rpc_status_utils.rb +1 -2
  22. data/src/ruby/lib/grpc/grpc_c.so +0 -0
  23. data/src/ruby/lib/grpc/version.rb +1 -1
  24. data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +1 -0
  25. data/src/ruby/spec/channel_connection_spec.rb +1 -34
  26. data/src/ruby/spec/client_server_spec.rb +188 -82
  27. data/src/ruby/spec/generic/active_call_spec.rb +65 -11
  28. data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
  29. data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
  30. data/src/ruby/spec/generic/rpc_desc_spec.rb +38 -0
  31. data/src/ruby/spec/generic/rpc_server_spec.rb +1 -34
  32. data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
  33. data/src/ruby/spec/spec_helper.rb +4 -0
  34. data/src/ruby/spec/support/helpers.rb +73 -0
  35. data/src/ruby/spec/support/services.rb +147 -0
  36. metadata +24 -12
@@ -196,11 +196,18 @@ module GRPC
196
196
  #
197
197
  # * server_args:
198
198
  # A server arguments hash to be passed down to the underlying core server
199
+ #
200
+ # * interceptors:
201
+ # Am array of GRPC::ServerInterceptor objects that will be used for
202
+ # intercepting server handlers to provide extra functionality.
203
+ # Interceptors are an EXPERIMENTAL API.
204
+ #
199
205
  def initialize(pool_size:DEFAULT_POOL_SIZE,
200
206
  max_waiting_requests:DEFAULT_MAX_WAITING_REQUESTS,
201
207
  poll_period:DEFAULT_POLL_PERIOD,
202
208
  connect_md_proc:nil,
203
- server_args:{})
209
+ server_args:{},
210
+ interceptors:[])
204
211
  @connect_md_proc = RpcServer.setup_connect_md_proc(connect_md_proc)
205
212
  @max_waiting_requests = max_waiting_requests
206
213
  @poll_period = poll_period
@@ -212,6 +219,7 @@ module GRPC
212
219
  # :stopped. State transitions can only proceed in that order.
213
220
  @running_state = :not_started
214
221
  @server = Core::Server.new(server_args)
222
+ @interceptors = InterceptorRegistry.new(interceptors)
215
223
  end
216
224
 
217
225
  # stops a running server
@@ -374,7 +382,11 @@ module GRPC
374
382
  @pool.schedule(active_call) do |ac|
375
383
  c, mth = ac
376
384
  begin
377
- rpc_descs[mth].run_server_method(c, rpc_handlers[mth])
385
+ rpc_descs[mth].run_server_method(
386
+ c,
387
+ rpc_handlers[mth],
388
+ @interceptors.build_context
389
+ )
378
390
  rescue StandardError
379
391
  c.send_status(GRPC::Core::StatusCodes::INTERNAL,
380
392
  'Server handler failed')
@@ -382,7 +394,7 @@ module GRPC
382
394
  end
383
395
  end
384
396
  rescue Core::CallError, RuntimeError => e
385
- # these might happen for various reasonse. The correct behaviour of
397
+ # these might happen for various reasons. The correct behavior of
386
398
  # the server is to log them and continue, if it's not shutting down.
387
399
  if running_state == :running
388
400
  GRPC.logger.warn("server call failed: #{e}")
@@ -29,8 +29,7 @@ module GRPC
29
29
  fail ArgumentError, 'bad type' unless status.is_a? Struct::Status
30
30
  grpc_status_details_bin_trailer = 'grpc-status-details-bin'
31
31
  return nil if status.metadata[grpc_status_details_bin_trailer].nil?
32
- Google::Rpc::Status.decode(
33
- status.metadata[grpc_status_details_bin_trailer])
32
+ Google::Rpc::Status.decode(status.metadata[grpc_status_details_bin_trailer])
34
33
  end
35
34
  end
36
35
  end
Binary file
@@ -14,5 +14,5 @@
14
14
 
15
15
  # GRPC contains the General RPC module.
16
16
  module GRPC
17
- VERSION = '1.6.7'
17
+ VERSION = '1.7.0.pre1'
18
18
  end
@@ -34,6 +34,7 @@ module Grpc
34
34
  self.service_name = 'grpc.testing.duplicate.EchoTestService'
35
35
 
36
36
  rpc :Echo, Grpc::Testing::EchoRequest, Grpc::Testing::EchoResponse
37
+ rpc :ResponseStream, Grpc::Testing::EchoRequest, stream(Grpc::Testing::EchoResponse)
37
38
  end
38
39
 
39
40
  Stub = Service.rpc_stub_class
@@ -11,45 +11,12 @@
11
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
-
15
- require 'grpc'
14
+ require 'spec_helper'
16
15
  require 'timeout'
17
16
 
18
17
  include Timeout
19
18
  include GRPC::Core
20
19
 
21
- # A test message
22
- class EchoMsg
23
- def self.marshal(_o)
24
- ''
25
- end
26
-
27
- def self.unmarshal(_o)
28
- EchoMsg.new
29
- end
30
- end
31
-
32
- # A test service with an echo implementation.
33
- class EchoService
34
- include GRPC::GenericService
35
- rpc :an_rpc, EchoMsg, EchoMsg
36
- attr_reader :received_md
37
-
38
- def initialize(**kw)
39
- @trailing_metadata = kw
40
- @received_md = []
41
- end
42
-
43
- def an_rpc(req, call)
44
- GRPC.logger.info('echo service received a request')
45
- call.output_metadata.update(@trailing_metadata)
46
- @received_md << call.metadata unless call.metadata.nil?
47
- req
48
- end
49
- end
50
-
51
- EchoStub = EchoService.rpc_stub_class
52
-
53
20
  def start_server(port = 0)
54
21
  @srv = GRPC::RpcServer.new(pool_size: 1)
55
22
  server_port = @srv.add_http2_port("localhost:#{port}", :this_port_is_insecure)
@@ -29,14 +29,18 @@ shared_context 'setup: tags' do
29
29
  expect(recvd_rpc).to_not eq nil
30
30
  server_call = recvd_rpc.call
31
31
  ops = { CallOps::SEND_INITIAL_METADATA => metadata }
32
- svr_batch = server_call.run_batch(ops)
33
- expect(svr_batch.send_metadata).to be true
32
+ server_batch = server_call.run_batch(ops)
33
+ expect(server_batch.send_metadata).to be true
34
34
  server_call
35
35
  end
36
36
 
37
37
  def new_client_call
38
38
  @ch.create_call(nil, nil, '/method', nil, deadline)
39
39
  end
40
+
41
+ def ok_status
42
+ Struct::Status.new(StatusCodes::OK, 'OK')
43
+ end
40
44
  end
41
45
 
42
46
  shared_examples 'basic GRPC message delivery is OK' do
@@ -70,19 +74,32 @@ shared_examples 'basic GRPC message delivery is OK' do
70
74
 
71
75
  client_ops = {
72
76
  CallOps::SEND_INITIAL_METADATA => {},
73
- CallOps::SEND_MESSAGE => sent_message
77
+ CallOps::SEND_MESSAGE => sent_message,
78
+ CallOps::SEND_CLOSE_FROM_CLIENT => nil
74
79
  }
75
- batch_result = call.run_batch(client_ops)
76
- expect(batch_result.send_metadata).to be true
77
- expect(batch_result.send_message).to be true
80
+ client_batch = call.run_batch(client_ops)
81
+ expect(client_batch.send_metadata).to be true
82
+ expect(client_batch.send_message).to be true
83
+ expect(client_batch.send_close).to be true
78
84
 
79
85
  # confirm the server can read the inbound message
80
86
  server_thread.join
81
87
  server_ops = {
82
- CallOps::RECV_MESSAGE => nil
88
+ CallOps::RECV_MESSAGE => nil,
89
+ CallOps::RECV_CLOSE_ON_SERVER => nil,
90
+ CallOps::SEND_STATUS_FROM_SERVER => ok_status
83
91
  }
84
- svr_batch = server_call.run_batch(server_ops)
85
- expect(svr_batch.message).to eq(sent_message)
92
+ server_batch = server_call.run_batch(server_ops)
93
+ expect(server_batch.message).to eq(sent_message)
94
+ expect(server_batch.send_close).to be true
95
+ expect(server_batch.send_status).to be true
96
+
97
+ # finish the call
98
+ final_client_batch = call.run_batch(
99
+ CallOps::RECV_INITIAL_METADATA => nil,
100
+ CallOps::RECV_STATUS_ON_CLIENT => nil)
101
+ expect(final_client_batch.metadata).to eq({})
102
+ expect(final_client_batch.status.code).to eq(0)
86
103
  end
87
104
 
88
105
  it 'responses written by servers are received by the client' do
@@ -95,21 +112,36 @@ shared_examples 'basic GRPC message delivery is OK' do
95
112
 
96
113
  client_ops = {
97
114
  CallOps::SEND_INITIAL_METADATA => {},
98
- CallOps::SEND_MESSAGE => sent_message
115
+ CallOps::SEND_MESSAGE => sent_message,
116
+ CallOps::SEND_CLOSE_FROM_CLIENT => nil
99
117
  }
100
- batch_result = call.run_batch(client_ops)
101
- expect(batch_result.send_metadata).to be true
102
- expect(batch_result.send_message).to be true
118
+ client_batch = call.run_batch(client_ops)
119
+ expect(client_batch.send_metadata).to be true
120
+ expect(client_batch.send_message).to be true
121
+ expect(client_batch.send_close).to be true
103
122
 
104
123
  # confirm the server can read the inbound message
105
124
  server_thread.join
106
125
  server_ops = {
107
126
  CallOps::RECV_MESSAGE => nil,
108
- CallOps::SEND_MESSAGE => reply_text
127
+ CallOps::RECV_CLOSE_ON_SERVER => nil,
128
+ CallOps::SEND_MESSAGE => reply_text,
129
+ CallOps::SEND_STATUS_FROM_SERVER => ok_status
109
130
  }
110
- svr_batch = server_call.run_batch(server_ops)
111
- expect(svr_batch.message).to eq(sent_message)
112
- expect(svr_batch.send_message).to be true
131
+ server_batch = server_call.run_batch(server_ops)
132
+ expect(server_batch.message).to eq(sent_message)
133
+ expect(server_batch.send_close).to be true
134
+ expect(server_batch.send_message).to be true
135
+ expect(server_batch.send_status).to be true
136
+
137
+ # finish the call
138
+ final_client_batch = call.run_batch(
139
+ CallOps::RECV_INITIAL_METADATA => nil,
140
+ CallOps::RECV_MESSAGE => nil,
141
+ CallOps::RECV_STATUS_ON_CLIENT => nil)
142
+ expect(final_client_batch.metadata).to eq({})
143
+ expect(final_client_batch.message).to eq(reply_text)
144
+ expect(final_client_batch.status.code).to eq(0)
113
145
  end
114
146
 
115
147
  it 'compressed messages can be sent and received' do
@@ -125,30 +157,37 @@ shared_examples 'basic GRPC message delivery is OK' do
125
157
 
126
158
  client_ops = {
127
159
  CallOps::SEND_INITIAL_METADATA => md,
128
- CallOps::SEND_MESSAGE => long_request_str
160
+ CallOps::SEND_MESSAGE => long_request_str,
161
+ CallOps::SEND_CLOSE_FROM_CLIENT => nil
129
162
  }
130
- batch_result = call.run_batch(client_ops)
131
- expect(batch_result.send_metadata).to be true
132
- expect(batch_result.send_message).to be true
163
+ client_batch = call.run_batch(client_ops)
164
+ expect(client_batch.send_metadata).to be true
165
+ expect(client_batch.send_message).to be true
166
+ expect(client_batch.send_close).to be true
133
167
 
134
168
  # confirm the server can read the inbound message
135
169
  server_thread.join
136
170
  server_ops = {
137
171
  CallOps::RECV_MESSAGE => nil,
138
- CallOps::SEND_MESSAGE => long_response_str
172
+ CallOps::RECV_CLOSE_ON_SERVER => nil,
173
+ CallOps::SEND_MESSAGE => long_response_str,
174
+ CallOps::SEND_STATUS_FROM_SERVER => ok_status
139
175
  }
140
- svr_batch = server_call.run_batch(server_ops)
141
- expect(svr_batch.message).to eq(long_request_str)
142
- expect(svr_batch.send_message).to be true
176
+ server_batch = server_call.run_batch(server_ops)
177
+ expect(server_batch.message).to eq(long_request_str)
178
+ expect(server_batch.send_close).to be true
179
+ expect(server_batch.send_message).to be true
180
+ expect(server_batch.send_status).to be true
143
181
 
144
182
  client_ops = {
145
- CallOps::SEND_CLOSE_FROM_CLIENT => nil,
146
183
  CallOps::RECV_INITIAL_METADATA => nil,
147
- CallOps::RECV_MESSAGE => nil
184
+ CallOps::RECV_MESSAGE => nil,
185
+ CallOps::RECV_STATUS_ON_CLIENT => nil
148
186
  }
149
- batch_result = call.run_batch(client_ops)
150
- expect(batch_result.send_close).to be true
151
- expect(batch_result.message).to eq long_response_str
187
+ final_client_batch = call.run_batch(client_ops)
188
+ expect(final_client_batch.metadata).to eq({})
189
+ expect(final_client_batch.message).to eq long_response_str
190
+ expect(final_client_batch.status.code).to eq(0)
152
191
  end
153
192
 
154
193
  it 'servers can ignore a client write and send a status' do
@@ -161,11 +200,13 @@ shared_examples 'basic GRPC message delivery is OK' do
161
200
 
162
201
  client_ops = {
163
202
  CallOps::SEND_INITIAL_METADATA => {},
164
- CallOps::SEND_MESSAGE => sent_message
203
+ CallOps::SEND_MESSAGE => sent_message,
204
+ CallOps::SEND_CLOSE_FROM_CLIENT => nil
165
205
  }
166
- batch_result = call.run_batch(client_ops)
167
- expect(batch_result.send_metadata).to be true
168
- expect(batch_result.send_message).to be true
206
+ client_batch = call.run_batch(client_ops)
207
+ expect(client_batch.send_metadata).to be true
208
+ expect(client_batch.send_message).to be true
209
+ expect(client_batch.send_close).to be true
169
210
 
170
211
  # confirm the server can read the inbound message
171
212
  the_status = Struct::Status.new(StatusCodes::OK, 'OK')
@@ -173,9 +214,15 @@ shared_examples 'basic GRPC message delivery is OK' do
173
214
  server_ops = {
174
215
  CallOps::SEND_STATUS_FROM_SERVER => the_status
175
216
  }
176
- svr_batch = server_call.run_batch(server_ops)
177
- expect(svr_batch.message).to eq nil
178
- expect(svr_batch.send_status).to be true
217
+ server_batch = server_call.run_batch(server_ops)
218
+ expect(server_batch.message).to eq nil
219
+ expect(server_batch.send_status).to be true
220
+
221
+ final_client_batch = call.run_batch(
222
+ CallOps::RECV_INITIAL_METADATA => nil,
223
+ CallOps::RECV_STATUS_ON_CLIENT => nil)
224
+ expect(final_client_batch.metadata).to eq({})
225
+ expect(final_client_batch.status.code).to eq(0)
179
226
  end
180
227
 
181
228
  it 'completes calls by sending status to client and server' do
@@ -190,9 +237,9 @@ shared_examples 'basic GRPC message delivery is OK' do
190
237
  CallOps::SEND_INITIAL_METADATA => {},
191
238
  CallOps::SEND_MESSAGE => sent_message
192
239
  }
193
- batch_result = call.run_batch(client_ops)
194
- expect(batch_result.send_metadata).to be true
195
- expect(batch_result.send_message).to be true
240
+ client_batch = call.run_batch(client_ops)
241
+ expect(client_batch.send_metadata).to be true
242
+ expect(client_batch.send_message).to be true
196
243
 
197
244
  # confirm the server can read the inbound message and respond
198
245
  the_status = Struct::Status.new(StatusCodes::OK, 'OK', {})
@@ -202,10 +249,10 @@ shared_examples 'basic GRPC message delivery is OK' do
202
249
  CallOps::SEND_MESSAGE => reply_text,
203
250
  CallOps::SEND_STATUS_FROM_SERVER => the_status
204
251
  }
205
- svr_batch = server_call.run_batch(server_ops)
206
- expect(svr_batch.message).to eq sent_message
207
- expect(svr_batch.send_status).to be true
208
- expect(svr_batch.send_message).to be true
252
+ server_batch = server_call.run_batch(server_ops)
253
+ expect(server_batch.message).to eq sent_message
254
+ expect(server_batch.send_status).to be true
255
+ expect(server_batch.send_message).to be true
209
256
 
210
257
  # confirm the client can receive the server response and status.
211
258
  client_ops = {
@@ -214,17 +261,17 @@ shared_examples 'basic GRPC message delivery is OK' do
214
261
  CallOps::RECV_MESSAGE => nil,
215
262
  CallOps::RECV_STATUS_ON_CLIENT => nil
216
263
  }
217
- batch_result = call.run_batch(client_ops)
218
- expect(batch_result.send_close).to be true
219
- expect(batch_result.message).to eq reply_text
220
- expect(batch_result.status).to eq the_status
264
+ final_client_batch = call.run_batch(client_ops)
265
+ expect(final_client_batch.send_close).to be true
266
+ expect(final_client_batch.message).to eq reply_text
267
+ expect(final_client_batch.status).to eq the_status
221
268
 
222
269
  # confirm the server can receive the client close.
223
270
  server_ops = {
224
271
  CallOps::RECV_CLOSE_ON_SERVER => nil
225
272
  }
226
- svr_batch = server_call.run_batch(server_ops)
227
- expect(svr_batch.send_close).to be true
273
+ final_server_batch = server_call.run_batch(server_ops)
274
+ expect(final_server_batch.send_close).to be true
228
275
  end
229
276
 
230
277
  def client_cancel_test(cancel_proc, expected_code,
@@ -240,9 +287,9 @@ shared_examples 'basic GRPC message delivery is OK' do
240
287
  CallOps::SEND_INITIAL_METADATA => {},
241
288
  CallOps::RECV_INITIAL_METADATA => nil
242
289
  }
243
- batch_result = call.run_batch(client_ops)
244
- expect(batch_result.send_metadata).to be true
245
- expect(batch_result.metadata).to eq({})
290
+ client_batch = call.run_batch(client_ops)
291
+ expect(client_batch.send_metadata).to be true
292
+ expect(client_batch.metadata).to eq({})
246
293
 
247
294
  cancel_proc.call(call)
248
295
 
@@ -250,16 +297,16 @@ shared_examples 'basic GRPC message delivery is OK' do
250
297
  server_ops = {
251
298
  CallOps::RECV_CLOSE_ON_SERVER => nil
252
299
  }
253
- svr_batch = server_call.run_batch(server_ops)
254
- expect(svr_batch.send_close).to be true
300
+ server_batch = server_call.run_batch(server_ops)
301
+ expect(server_batch.send_close).to be true
255
302
 
256
303
  client_ops = {
257
304
  CallOps::RECV_STATUS_ON_CLIENT => {}
258
305
  }
259
- batch_result = call.run_batch(client_ops)
306
+ client_batch = call.run_batch(client_ops)
260
307
 
261
- expect(batch_result.status.code).to be expected_code
262
- expect(batch_result.status.details).to eq expected_details
308
+ expect(client_batch.status.code).to be expected_code
309
+ expect(client_batch.status.details).to eq expected_details
263
310
  end
264
311
 
265
312
  it 'clients can cancel a call on the server' do
@@ -325,10 +372,11 @@ shared_examples 'GRPC metadata delivery works OK' do
325
372
 
326
373
  call = new_client_call
327
374
  client_ops = {
328
- CallOps::SEND_INITIAL_METADATA => md
375
+ CallOps::SEND_INITIAL_METADATA => md,
376
+ CallOps::SEND_CLOSE_FROM_CLIENT => nil
329
377
  }
330
- batch_result = call.run_batch(client_ops)
331
- expect(batch_result.send_metadata).to be true
378
+ client_batch = call.run_batch(client_ops)
379
+ expect(client_batch.send_metadata).to be true
332
380
 
333
381
  # confirm the server can receive the client metadata
334
382
  rcv_thread.join
@@ -336,6 +384,21 @@ shared_examples 'GRPC metadata delivery works OK' do
336
384
  recvd_md = recvd_rpc.metadata
337
385
  replace_symbols = Hash[md.each_pair.collect { |x, y| [x.to_s, y] }]
338
386
  expect(recvd_md).to eq(recvd_md.merge(replace_symbols))
387
+
388
+ # finish the call
389
+ final_server_batch = recvd_rpc.call.run_batch(
390
+ CallOps::RECV_CLOSE_ON_SERVER => nil,
391
+ CallOps::SEND_INITIAL_METADATA => nil,
392
+ CallOps::SEND_STATUS_FROM_SERVER => ok_status)
393
+ expect(final_server_batch.send_close).to be(true)
394
+ expect(final_server_batch.send_metadata).to be(true)
395
+ expect(final_server_batch.send_status).to be(true)
396
+
397
+ final_client_batch = call.run_batch(
398
+ CallOps::RECV_INITIAL_METADATA => nil,
399
+ CallOps::RECV_STATUS_ON_CLIENT => nil)
400
+ expect(final_client_batch.metadata).to eq({})
401
+ expect(final_client_batch.status.code).to eq(0)
339
402
  end
340
403
  end
341
404
  end
@@ -381,6 +444,9 @@ shared_examples 'GRPC metadata delivery works OK' do
381
444
  recvd_rpc.call.run_batch(server_ops)
382
445
  end
383
446
  expect(&blk).to raise_error
447
+
448
+ # cancel the call so the server can shut down immediately
449
+ call.cancel
384
450
  end
385
451
  end
386
452
 
@@ -394,25 +460,37 @@ shared_examples 'GRPC metadata delivery works OK' do
394
460
  # client signals that it's done sending metadata to allow server to
395
461
  # respond
396
462
  client_ops = {
397
- CallOps::SEND_INITIAL_METADATA => nil
463
+ CallOps::SEND_INITIAL_METADATA => nil,
464
+ CallOps::SEND_CLOSE_FROM_CLIENT => nil
398
465
  }
399
- call.run_batch(client_ops)
466
+ client_batch = call.run_batch(client_ops)
467
+ expect(client_batch.send_metadata).to be true
468
+ expect(client_batch.send_close).to be true
400
469
 
401
470
  # server gets the invocation but sends no metadata back
402
471
  rcv_thread.join
403
472
  expect(recvd_rpc).to_not eq nil
404
473
  server_call = recvd_rpc.call
405
474
  server_ops = {
406
- CallOps::SEND_INITIAL_METADATA => nil
475
+ # receive close and send status to finish the call
476
+ CallOps::RECV_CLOSE_ON_SERVER => nil,
477
+ CallOps::SEND_INITIAL_METADATA => nil,
478
+ CallOps::SEND_STATUS_FROM_SERVER => ok_status
407
479
  }
408
- server_call.run_batch(server_ops)
480
+ srv_batch = server_call.run_batch(server_ops)
481
+ expect(srv_batch.send_close).to be true
482
+ expect(srv_batch.send_metadata).to be true
483
+ expect(srv_batch.send_status).to be true
409
484
 
410
485
  # client receives nothing as expected
411
486
  client_ops = {
412
- CallOps::RECV_INITIAL_METADATA => nil
487
+ CallOps::RECV_INITIAL_METADATA => nil,
488
+ # receive status to finish the call
489
+ CallOps::RECV_STATUS_ON_CLIENT => nil
413
490
  }
414
- batch_result = call.run_batch(client_ops)
415
- expect(batch_result.metadata).to eq({})
491
+ final_client_batch = call.run_batch(client_ops)
492
+ expect(final_client_batch.metadata).to eq({})
493
+ expect(final_client_batch.status.code).to eq(0)
416
494
  end
417
495
 
418
496
  it 'sends all the pairs when keys and values are valid' do
@@ -426,26 +504,36 @@ shared_examples 'GRPC metadata delivery works OK' do
426
504
  # client signals that it's done sending metadata to allow server to
427
505
  # respond
428
506
  client_ops = {
429
- CallOps::SEND_INITIAL_METADATA => nil
507
+ CallOps::SEND_INITIAL_METADATA => nil,
508
+ CallOps::SEND_CLOSE_FROM_CLIENT => nil
430
509
  }
431
- call.run_batch(client_ops)
510
+ client_batch = call.run_batch(client_ops)
511
+ expect(client_batch.send_metadata).to be true
512
+ expect(client_batch.send_close).to be true
432
513
 
433
514
  # server gets the invocation but sends no metadata back
434
515
  rcv_thread.join
435
516
  expect(recvd_rpc).to_not eq nil
436
517
  server_call = recvd_rpc.call
437
518
  server_ops = {
438
- CallOps::SEND_INITIAL_METADATA => md
519
+ CallOps::RECV_CLOSE_ON_SERVER => nil,
520
+ CallOps::SEND_INITIAL_METADATA => md,
521
+ CallOps::SEND_STATUS_FROM_SERVER => ok_status
439
522
  }
440
- server_call.run_batch(server_ops)
523
+ srv_batch = server_call.run_batch(server_ops)
524
+ expect(srv_batch.send_close).to be true
525
+ expect(srv_batch.send_metadata).to be true
526
+ expect(srv_batch.send_status).to be true
441
527
 
442
528
  # client receives nothing as expected
443
529
  client_ops = {
444
- CallOps::RECV_INITIAL_METADATA => nil
530
+ CallOps::RECV_INITIAL_METADATA => nil,
531
+ CallOps::RECV_STATUS_ON_CLIENT => nil
445
532
  }
446
- batch_result = call.run_batch(client_ops)
533
+ final_client_batch = call.run_batch(client_ops)
447
534
  replace_symbols = Hash[md.each_pair.collect { |x, y| [x.to_s, y] }]
448
- expect(batch_result.metadata).to eq(replace_symbols)
535
+ expect(final_client_batch.metadata).to eq(replace_symbols)
536
+ expect(final_client_batch.status.code).to eq(0)
449
537
  end
450
538
  end
451
539
  end
@@ -510,8 +598,7 @@ describe 'the secure http client/server' do
510
598
 
511
599
  initial_md_key = 'k2'
512
600
  initial_md_val = 'v2'
513
- initial_md = {}
514
- initial_md[initial_md_key] = initial_md_val
601
+ initial_md = { initial_md_key => initial_md_val }
515
602
  expected_md = creds_update_md.clone
516
603
  fail 'bad test param' unless expected_md[initial_md_key].nil?
517
604
  expected_md[initial_md_key] = initial_md_val
@@ -523,11 +610,12 @@ describe 'the secure http client/server' do
523
610
 
524
611
  call = new_client_call
525
612
  call.set_credentials! call_creds
526
- client_ops = {
527
- CallOps::SEND_INITIAL_METADATA => initial_md
528
- }
529
- batch_result = call.run_batch(client_ops)
530
- expect(batch_result.send_metadata).to be true
613
+
614
+ client_batch = call.run_batch(
615
+ CallOps::SEND_INITIAL_METADATA => initial_md,
616
+ CallOps::SEND_CLOSE_FROM_CLIENT => nil)
617
+ expect(client_batch.send_metadata).to be true
618
+ expect(client_batch.send_close).to be true
531
619
 
532
620
  # confirm the server can receive the client metadata
533
621
  rcv_thread.join
@@ -535,6 +623,24 @@ describe 'the secure http client/server' do
535
623
  recvd_md = recvd_rpc.metadata
536
624
  replace_symbols = Hash[expected_md.each_pair.collect { |x, y| [x.to_s, y] }]
537
625
  expect(recvd_md).to eq(recvd_md.merge(replace_symbols))
626
+
627
+ credentials_update_test_finish_call(call, recvd_rpc.call)
628
+ end
629
+
630
+ def credentials_update_test_finish_call(client_call, server_call)
631
+ final_server_batch = server_call.run_batch(
632
+ CallOps::RECV_CLOSE_ON_SERVER => nil,
633
+ CallOps::SEND_INITIAL_METADATA => nil,
634
+ CallOps::SEND_STATUS_FROM_SERVER => ok_status)
635
+ expect(final_server_batch.send_close).to be(true)
636
+ expect(final_server_batch.send_metadata).to be(true)
637
+ expect(final_server_batch.send_status).to be(true)
638
+
639
+ final_client_batch = client_call.run_batch(
640
+ CallOps::RECV_INITIAL_METADATA => nil,
641
+ CallOps::RECV_STATUS_ON_CLIENT => nil)
642
+ expect(final_client_batch.metadata).to eq({})
643
+ expect(final_client_batch.status.code).to eq(0)
538
644
  end
539
645
 
540
646
  it 'modifies metadata with CallCredentials' do