Class: NamedTests

Inherits:
Object
  • 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

Constants included from Grpc::Testing

Grpc::Testing::CompressionType, Grpc::Testing::EchoStatus, Grpc::Testing::Empty, Grpc::Testing::Payload, Grpc::Testing::PayloadType, Grpc::Testing::ReconnectInfo, 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


203
204
205
206
# File 'src/ruby/pb/test/client.rb', line 203

def initialize(stub, args)
  @stub = stub
  @args = args
end

Instance Method Details

#allObject


380
381
382
383
384
385
386
387
# File 'src/ruby/pb/test/client.rb', line 380

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_beginObject


352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'src/ruby/pb/test/client.rb', line 352

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 }
  p "OK: #{__callee__}"
end

#cancel_after_first_responseObject


367
368
369
370
371
372
373
374
375
376
377
378
# File 'src/ruby/pb/test/client.rb', line 367

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  # causes ppp to cancel after the 1st message
  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
  p "OK: #{__callee__}"
end

#client_streamingObject


285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'src/ruby/pb/test/client.rb', line 285

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
  p "OK: #{__callee__}"
end

#compute_engine_credsObject


244
245
246
247
248
249
250
251
# File 'src/ruby/pb/test/client.rb', line 244

def compute_engine_creds
  resp = perform_large_unary(fill_username: true,
                             fill_oauth_scope: true)
  assert("#{__callee__}: bad username") do
    @args. == resp.username
  end
  p "OK: #{__callee__}"
end

#empty_streamObject


338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'src/ruby/pb/test/client.rb', line 338

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
  p "OK: #{__callee__}"
end

#empty_unaryObject


208
209
210
211
212
# File 'src/ruby/pb/test/client.rb', line 208

def empty_unary
  resp = @stub.empty_call(Empty.new)
  assert('empty_unary: invalid response') { resp.is_a?(Empty) }
  p 'OK: empty_unary'
end

#jwt_token_credsObject


236
237
238
239
240
241
242
# File 'src/ruby/pb/test/client.rb', line 236

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 }
  p "OK: #{__callee__}"
end

#large_unaryObject


214
215
216
217
# File 'src/ruby/pb/test/client.rb', line 214

def large_unary
  perform_large_unary
  p 'OK: large_unary'
end

#oauth2_auth_tokenObject


253
254
255
256
257
258
259
260
261
262
263
# File 'src/ruby/pb/test/client.rb', line 253

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
  p "OK: #{__callee__}"
end

#per_rpc_credsObject


265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'src/ruby/pb/test/client.rb', line 265

def per_rpc_creds
  auth_creds = Google::Auth.get_application_default(@args.oauth_scope)
   = proc do |md|
    kw = auth_creds.updater_proc.call({})
  end

  call_creds = GRPC::Core::CallCredentials.new()

  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
  p "OK: #{__callee__}"
end

#ping_pongObject


317
318
319
320
321
322
323
# File 'src/ruby/pb/test/client.rb', line 317

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) }
  p "OK: #{__callee__}"
end

#server_streamingObject


299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'src/ruby/pb/test/client.rb', line 299

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
  p "OK: #{__callee__}"
end

#service_account_credsObject


219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'src/ruby/pb/test/client.rb', line 219

def 
  # ignore this test if the oauth options are not set
  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
  p "OK: #{__callee__}"
end

#timeout_on_sleeping_serverObject


325
326
327
328
329
330
331
332
333
334
335
336
# File 'src/ruby/pb/test/client.rb', line 325

def timeout_on_sleeping_server
  msg_sizes = [[27_182, 31_415]]
  ppp = PingPongPlayer.new(msg_sizes)
  resps = @stub.full_duplex_call(ppp.each_item, timeout: 0.001)
  resps.each { |r| ppp.queue.push(r) }
  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
  p "OK: #{__callee__}"
end