Class: NamedTests
- Inherits:
-
Object
show all
- Includes:
- GRPC::Core::MetadataKeys, Grpc::Testing, Grpc::Testing::PayloadType
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/pb/test/client.rb
Overview
defines methods corresponding to each interop test case.
Constant Summary
Grpc::Testing::BoolValue, Grpc::Testing::ClientConfigureRequest, Grpc::Testing::ClientConfigureResponse, Grpc::Testing::EchoStatus, Grpc::Testing::Empty, Grpc::Testing::EmptyMessage, Grpc::Testing::GaugeRequest, Grpc::Testing::GaugeResponse, Grpc::Testing::GrpclbRouteType, Grpc::Testing::LoadBalancerAccumulatedStatsRequest, Grpc::Testing::LoadBalancerAccumulatedStatsResponse, Grpc::Testing::LoadBalancerStatsRequest, Grpc::Testing::LoadBalancerStatsResponse, Grpc::Testing::MemorySize, 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.
259
260
261
262
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/pb/test/client.rb', line 259
def initialize(stub, args)
@stub = stub
@args = args
end
|
Instance Method Details
652
653
654
655
656
657
658
659
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/pb/test/client.rb', line 652
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
479
480
481
482
483
484
485
486
487
488
489
490
491
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/pb/test/client.rb', line 479
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
493
494
495
496
497
498
499
500
501
502
503
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/pb/test/client.rb', line 493
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_compressed_streaming ⇒ Object
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/pb/test/client.rb', line 389
def client_compressed_streaming
first_request = StreamingInputCallRequest.new(
payload: Payload.new(type: :COMPRESSABLE, body: nulls(27_182)),
expect_compressed: BoolValue.new(value: true)
)
send_probe_for_compressed_request_support do
request_uncompressed_args = {
COMPRESSION_REQUEST_ALGORITHM => 'identity'
}
@stub.streaming_input_call([first_request],
metadata: request_uncompressed_args)
end
second_request = StreamingInputCallRequest.new(
payload: Payload.new(type: :COMPRESSABLE, body: nulls(45_904)),
expect_compressed: BoolValue.new(value: false)
)
requests = WriteFlagSettingStreamingInputEnumerable.new([
{ request: first_request,
write_flag: 0 },
{ request: second_request,
write_flag: GRPC::Core::WriteFlags::NO_COMPRESS }
])
call_op = @stub.streaming_input_call(requests,
return_op: true)
requests.call_op = call_op
resp = call_op.execute
wanted_aggregate_size = 73_086
assert("#{__callee__}: aggregate payload size is incorrect") do
wanted_aggregate_size == resp.aggregated_payload_size
end
end
|
#client_compressed_unary ⇒ Object
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/pb/test/client.rb', line 273
def client_compressed_unary
req_size, wanted_response_size = 271_828, 314_159
expect_compressed = BoolValue.new(value: true)
payload = Payload.new(type: :COMPRESSABLE, body: nulls(req_size))
req = SimpleRequest.new(response_type: :COMPRESSABLE,
response_size: wanted_response_size,
payload: payload,
expect_compressed: expect_compressed)
send_probe_for_compressed_request_support do
request_uncompressed_args = {
COMPRESSION_REQUEST_ALGORITHM => 'identity'
}
@stub.unary_call(req, metadata: request_uncompressed_args)
end
resp = @stub.unary_call(req)
assert('Expected second unary call with compression to work') do
resp.payload.body.length == wanted_response_size
end
stub_options = {
COMPRESSION_REQUEST_ALGORITHM => 'identity'
}
req = SimpleRequest.new(
response_type: :COMPRESSABLE,
response_size: wanted_response_size,
payload: payload,
expect_compressed: BoolValue.new(value: false)
)
resp = @stub.unary_call(req, metadata: stub_options)
assert('Expected second unary call with compression to work') do
resp.payload.body.length == wanted_response_size
end
end
|
#client_streaming ⇒ Object
376
377
378
379
380
381
382
383
384
385
386
387
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/pb/test/client.rb', line 376
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
338
339
340
341
342
343
344
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/pb/test/client.rb', line 338
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
|
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/pb/test/client.rb', line 584
def custom_metadata
req_size, wanted_response_size = 271_828, 314_159
initial_metadata_key = "x-grpc-test-echo-initial"
initial_metadata_value = "test_initial_metadata_value"
trailing_metadata_key = "x-grpc-test-echo-trailing-bin"
trailing_metadata_value = "\x0a\x0b\x0a\x0b\x0a\x0b"
metadata = {
initial_metadata_key => initial_metadata_value,
trailing_metadata_key => trailing_metadata_value
}
payload = Payload.new(type: :COMPRESSABLE, body: nulls(req_size))
req = SimpleRequest.new(response_type: :COMPRESSABLE,
response_size: wanted_response_size,
payload: payload)
op = @stub.unary_call(req, metadata: metadata, return_op: true)
op.execute
if not op.metadata.has_key?(initial_metadata_key)
fail AssertionError, "Expected initial metadata. None received"
elsif op.metadata[initial_metadata_key] != metadata[initial_metadata_key]
fail AssertionError,
"Expected initial metadata: #{metadata[initial_metadata_key]}. "\
"Received: #{op.metadata[initial_metadata_key]}"
end
if not op.trailing_metadata.has_key?(trailing_metadata_key)
fail AssertionError, "Expected trailing metadata. None received"
elsif op.trailing_metadata[trailing_metadata_key] !=
metadata[trailing_metadata_key]
fail AssertionError,
"Expected trailing metadata: #{metadata[trailing_metadata_key]}. "\
"Received: #{op.trailing_metadata[trailing_metadata_key]}"
end
req_cls, p_cls = StreamingOutputCallRequest, ResponseParameters
duplex_req = req_cls.new(payload: Payload.new(body: nulls(req_size)),
response_type: :COMPRESSABLE,
response_parameters: [p_cls.new(size: wanted_response_size)])
duplex_op = @stub.full_duplex_call([duplex_req], metadata: metadata,
return_op: true)
resp = duplex_op.execute
resp.each { |r| } duplex_op.wait
if not duplex_op.metadata.has_key?(initial_metadata_key)
fail AssertionError, "Expected initial metadata. None received"
elsif duplex_op.metadata[initial_metadata_key] !=
metadata[initial_metadata_key]
fail AssertionError,
"Expected initial metadata: #{metadata[initial_metadata_key]}. "\
"Received: #{duplex_op.metadata[initial_metadata_key]}"
end
if not duplex_op.trailing_metadata[trailing_metadata_key]
fail AssertionError, "Expected trailing metadata. None received"
elsif duplex_op.trailing_metadata[trailing_metadata_key] !=
metadata[trailing_metadata_key]
fail AssertionError,
"Expected trailing metadata: #{metadata[trailing_metadata_key]}. "\
"Received: #{duplex_op.trailing_metadata[trailing_metadata_key]}"
end
end
|
#empty_stream ⇒ Object
466
467
468
469
470
471
472
473
474
475
476
477
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/pb/test/client.rb', line 466
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
264
265
266
267
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/pb/test/client.rb', line 264
def empty_unary
resp = @stub.empty_call(Empty.new)
assert('empty_unary: invalid response') { resp.is_a?(Empty) }
end
|
#jwt_token_creds ⇒ Object
331
332
333
334
335
336
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/pb/test/client.rb', line 331
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
269
270
271
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/pb/test/client.rb', line 269
def large_unary
perform_large_unary
end
|
#oauth2_auth_token ⇒ Object
346
347
348
349
350
351
352
353
354
355
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/pb/test/client.rb', line 346
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/pb/test/client.rb', line 357
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
450
451
452
453
454
455
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/pb/test/client.rb', line 450
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
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/pb/test/client.rb', line 433
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/pb/test/client.rb', line 315
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
|
#status_code_and_message ⇒ Object
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/pb/test/client.rb', line 527
def status_code_and_message
message = "test status method"
code = GRPC::Core::StatusCodes::UNKNOWN
payload = Payload.new(type: :COMPRESSABLE, body: nulls(1))
echo_status = EchoStatus.new(code: code, message: message)
req = SimpleRequest.new(response_type: :COMPRESSABLE,
response_size: 1,
payload: payload,
response_status: echo_status)
seen_correct_exception = false
begin
resp = @stub.unary_call(req)
rescue GRPC::Unknown => e
if e.details != message
fail AssertionError,
"Expected message #{message}. Received: #{e.details}"
end
seen_correct_exception = true
rescue Exception => e
fail AssertionError, "Expected BadStatus. Received: #{e.inspect}"
end
if not seen_correct_exception
fail AssertionError, "Did not see expected status from UnaryCall"
end
req_cls, p_cls = StreamingOutputCallRequest, ResponseParameters
duplex_req = req_cls.new(payload: Payload.new(body: nulls(1)),
response_type: :COMPRESSABLE,
response_parameters: [p_cls.new(size: 1)],
response_status: echo_status)
seen_correct_exception = false
begin
resp = @stub.full_duplex_call([duplex_req])
resp.each { |r| }
rescue GRPC::Unknown => e
if e.details != message
fail AssertionError,
"Expected message #{message}. Received: #{e.details}"
end
seen_correct_exception = true
rescue Exception => e
fail AssertionError, "Expected BadStatus. Received: #{e.inspect}"
end
if not seen_correct_exception
fail AssertionError, "Did not see expected status from FullDuplexCall"
end
end
|
#timeout_on_sleeping_server ⇒ Object
457
458
459
460
461
462
463
464
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/pb/test/client.rb', line 457
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::DeadlineExceeded'
rescue GRPC::DeadlineExceeded
end
|
#unimplemented_method ⇒ Object
505
506
507
508
509
510
511
512
513
514
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/pb/test/client.rb', line 505
def unimplemented_method
begin
resp = @stub.unimplemented_call(Empty.new)
rescue GRPC::Unimplemented => e
return
rescue Exception => e
fail AssertionError, "Expected BadStatus. Received: #{e.inspect}"
end
fail AssertionError, "GRPC::Unimplemented should have been raised. Was not."
end
|
#unimplemented_service ⇒ Object
516
517
518
519
520
521
522
523
524
525
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/pb/test/client.rb', line 516
def unimplemented_service
begin
resp = @stub.unimplemented_call(Empty.new)
rescue GRPC::Unimplemented => e
return
rescue Exception => e
fail AssertionError, "Expected BadStatus. Received: #{e.inspect}"
end
fail AssertionError, "GRPC::Unimplemented should have been raised. Was not."
end
|