Class: NamedTests
- Inherits:
-
Object
show all
- Includes:
- Grpc::Testing, Grpc::Testing::PayloadType
- Defined in:
- src/ruby/pb/test/client.rb
Overview
defines methods corresponding to each interop test case.
Constant Summary
Grpc::Testing::BoolValue, Grpc::Testing::EchoStatus, Grpc::Testing::Empty, Grpc::Testing::EmptyMessage, Grpc::Testing::GaugeRequest, Grpc::Testing::GaugeResponse, Grpc::Testing::Payload, Grpc::Testing::PayloadType, Grpc::Testing::ReconnectInfo, Grpc::Testing::ReconnectParams, Grpc::Testing::ResponseParameters, Grpc::Testing::SimpleRequest, Grpc::Testing::SimpleResponse, Grpc::Testing::StreamingInputCallRequest, Grpc::Testing::StreamingInputCallResponse, Grpc::Testing::StreamingOutputCallRequest, Grpc::Testing::StreamingOutputCallResponse
Instance Method Summary
collapse
Constructor Details
#initialize(stub, args) ⇒ NamedTests
Returns a new instance of NamedTests.
224
225
226
227
|
# File 'src/ruby/pb/test/client.rb', line 224
def initialize(stub, args)
@stub = stub
@args = args
end
|
Instance Method Details
#all ⇒ Object
387
388
389
390
391
392
393
394
|
# File 'src/ruby/pb/test/client.rb', line 387
def all
all_methods = NamedTests.instance_methods(false).map(&:to_s)
all_methods.each do |m|
next if m == 'all' || m.start_with?('assert')
p "TESTCASE: #{m}"
method(m).call
end
end
|
#cancel_after_begin ⇒ Object
361
362
363
364
365
366
367
368
369
370
371
372
373
|
# File 'src/ruby/pb/test/client.rb', line 361
def cancel_after_begin
msg_sizes = [27_182, 8, 1828, 45_904]
reqs = msg_sizes.map do |x|
req = Payload.new(body: nulls(x))
StreamingInputCallRequest.new(payload: req)
end
op = @stub.streaming_input_call(reqs, return_op: true)
op.cancel
op.execute
fail 'Should have raised GRPC:Cancelled'
rescue GRPC::Cancelled
assert("#{__callee__}: call operation should be CANCELLED") { op.cancelled? }
end
|
#cancel_after_first_response ⇒ Object
375
376
377
378
379
380
381
382
383
384
385
|
# File 'src/ruby/pb/test/client.rb', line 375
def cancel_after_first_response
msg_sizes = [[27_182, 31_415], [8, 9], [1828, 2653], [45_904, 58_979]]
ppp = PingPongPlayer.new(msg_sizes)
op = @stub.full_duplex_call(ppp.each_item, return_op: true)
ppp.canceller_op = op op.execute.each { |r| ppp.queue.push(r) }
fail 'Should have raised GRPC:Cancelled'
rescue GRPC::Cancelled
assert("#{__callee__}: call operation should be CANCELLED") { op.cancelled? }
op.wait
end
|
#client_streaming ⇒ Object
299
300
301
302
303
304
305
306
307
308
309
310
|
# File 'src/ruby/pb/test/client.rb', line 299
def client_streaming
msg_sizes = [27_182, 8, 1828, 45_904]
wanted_aggregate_size = 74_922
reqs = msg_sizes.map do |x|
req = Payload.new(body: nulls(x))
StreamingInputCallRequest.new(payload: req)
end
resp = @stub.streaming_input_call(reqs)
assert("#{__callee__}: aggregate payload size is incorrect") do
wanted_aggregate_size == resp.aggregated_payload_size
end
end
|
#compute_engine_creds ⇒ Object
261
262
263
264
265
266
267
|
# File 'src/ruby/pb/test/client.rb', line 261
def compute_engine_creds
resp = perform_large_unary(fill_username: true,
fill_oauth_scope: true)
assert("#{__callee__}: bad username") do
@args.default_service_account == resp.username
end
end
|
#empty_stream ⇒ Object
348
349
350
351
352
353
354
355
356
357
358
359
|
# File 'src/ruby/pb/test/client.rb', line 348
def empty_stream
ppp = PingPongPlayer.new([])
resps = @stub.full_duplex_call(ppp.each_item)
count = 0
resps.each do |r|
ppp.queue.push(r)
count += 1
end
assert("#{__callee__}: too many responses expected 0") do
count == 0
end
end
|
#empty_unary ⇒ Object
229
230
231
232
|
# File 'src/ruby/pb/test/client.rb', line 229
def empty_unary
resp = @stub.empty_call(Empty.new)
assert('empty_unary: invalid response') { resp.is_a?(Empty) }
end
|
#jwt_token_creds ⇒ Object
254
255
256
257
258
259
|
# File 'src/ruby/pb/test/client.rb', line 254
def jwt_token_creds
json_key = File.read(ENV[AUTH_ENV])
wanted_email = MultiJson.load(json_key)['client_email']
resp = perform_large_unary(fill_username: true)
assert("#{__callee__}: bad username") { wanted_email == resp.username }
end
|
#large_unary ⇒ Object
234
235
236
|
# File 'src/ruby/pb/test/client.rb', line 234
def large_unary
perform_large_unary
end
|
#oauth2_auth_token ⇒ Object
269
270
271
272
273
274
275
276
277
278
|
# File 'src/ruby/pb/test/client.rb', line 269
def oauth2_auth_token
resp = perform_large_unary(fill_username: true,
fill_oauth_scope: true)
json_key = File.read(ENV[AUTH_ENV])
wanted_email = MultiJson.load(json_key)['client_email']
assert("#{__callee__}: bad username") { wanted_email == resp.username }
assert("#{__callee__}: bad oauth scope") do
@args.oauth_scope.include?(resp.oauth_scope)
end
end
|
#per_rpc_creds ⇒ Object
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
|
# File 'src/ruby/pb/test/client.rb', line 280
def per_rpc_creds
auth_creds = Google::Auth.get_application_default(@args.oauth_scope)
update_metadata = proc do |md|
kw = auth_creds.updater_proc.call({})
end
call_creds = GRPC::Core::CallCredentials.new(update_metadata)
resp = perform_large_unary(fill_username: true,
fill_oauth_scope: true,
credentials: call_creds)
json_key = File.read(ENV[AUTH_ENV])
wanted_email = MultiJson.load(json_key)['client_email']
assert("#{__callee__}: bad username") { wanted_email == resp.username }
assert("#{__callee__}: bad oauth scope") do
@args.oauth_scope.include?(resp.oauth_scope)
end
end
|
#ping_pong ⇒ Object
329
330
331
332
333
334
|
# File 'src/ruby/pb/test/client.rb', line 329
def ping_pong
msg_sizes = [[27_182, 31_415], [8, 9], [1828, 2653], [45_904, 58_979]]
ppp = PingPongPlayer.new(msg_sizes)
resps = @stub.full_duplex_call(ppp.each_item)
resps.each { |r| ppp.queue.push(r) }
end
|
#server_streaming ⇒ Object
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
# File 'src/ruby/pb/test/client.rb', line 312
def server_streaming
msg_sizes = [31_415, 9, 2653, 58_979]
response_spec = msg_sizes.map { |s| ResponseParameters.new(size: s) }
req = StreamingOutputCallRequest.new(response_type: :COMPRESSABLE,
response_parameters: response_spec)
resps = @stub.streaming_output_call(req)
resps.each_with_index do |r, i|
assert("#{__callee__}: too many responses") { i < msg_sizes.length }
assert("#{__callee__}: payload body #{i} has the wrong length") do
msg_sizes[i] == r.payload.body.length
end
assert("#{__callee__}: payload type is wrong") do
:COMPRESSABLE == r.payload.type
end
end
end
|
#service_account_creds ⇒ Object
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
# File 'src/ruby/pb/test/client.rb', line 238
def service_account_creds
if @args.oauth_scope.nil?
p 'NOT RUN: service_account_creds; no service_account settings'
return
end
json_key = File.read(ENV[AUTH_ENV])
wanted_email = MultiJson.load(json_key)['client_email']
resp = perform_large_unary(fill_username: true,
fill_oauth_scope: true)
assert("#{__callee__}: bad username") { wanted_email == resp.username }
assert("#{__callee__}: bad oauth scope") do
@args.oauth_scope.include?(resp.oauth_scope)
end
end
|
#timeout_on_sleeping_server ⇒ Object
336
337
338
339
340
341
342
343
344
345
346
|
# File 'src/ruby/pb/test/client.rb', line 336
def timeout_on_sleeping_server
enum = BlockingEnumerator.new(27_182, 2)
deadline = GRPC::Core::TimeConsts::from_relative_time(1)
resps = @stub.full_duplex_call(enum.each_item, deadline: deadline)
resps.each { } fail 'Should have raised GRPC::BadStatus(DEADLINE_EXCEEDED)'
rescue GRPC::BadStatus => e
assert("#{__callee__}: status was wrong") do
e.code == GRPC::Core::StatusCodes::DEADLINE_EXCEEDED
end
end
|