@ -16,36 +16,8 @@ require 'spec_helper'
include GRPC :: Core
shared_context 'setup: tags' do
let ( :sent_message ) { 'sent message' }
let ( :reply_text ) { 'the reply' }
def deadline
Time . now + 5
end
def server_allows_client_to_proceed ( metadata = { } )
recvd_rpc = @server . request_call
expect ( recvd_rpc ) . to_not eq nil
server_call = recvd_rpc . call
ops = { CallOps :: SEND_INITIAL_METADATA = > metadata }
server_batch = server_call . run_batch ( ops )
expect ( server_batch . send_metadata ) . to be true
server_call
end
def new_client_call
@ch . create_call ( nil , nil , '/method' , nil , deadline )
end
def ok_status
Struct :: Status . new ( StatusCodes :: OK , 'OK' )
end
end
shared_examples 'basic GRPC message delivery is OK' do
include GRPC :: Core
include_context 'setup: tags'
context 'the test channel' do
it 'should have a target' do
@ -53,272 +25,45 @@ shared_examples 'basic GRPC message delivery is OK' do
end
end
context 'a client call' do
it 'should have a peer' do
expect ( new_client_call . peer ) . to be_a ( String )
end
end
it 'calls have peer info' do
call = new_client_call
expect ( call . peer ) . to be_a ( String )
end
it 'servers receive requests from clients and can respond' do
call = new_client_call
server_call = nil
server_thread = Thread . new do
server_call = server_allows_client_to_proceed
end
client_ops = {
CallOps :: SEND_INITIAL_METADATA = > { } ,
CallOps :: SEND_MESSAGE = > sent_message ,
CallOps :: SEND_CLOSE_FROM_CLIENT = > nil
}
client_batch = call . run_batch ( client_ops )
expect ( client_batch . send_metadata ) . to be true
expect ( client_batch . send_message ) . to be true
expect ( client_batch . send_close ) . to be true
# confirm the server can read the inbound message
server_thread . join
server_ops = {
CallOps :: RECV_MESSAGE = > nil
}
server_batch = server_call . run_batch ( server_ops )
expect ( server_batch . message ) . to eq ( sent_message )
server_ops = {
CallOps :: RECV_CLOSE_ON_SERVER = > nil ,
CallOps :: SEND_STATUS_FROM_SERVER = > ok_status
}
server_batch = server_call . run_batch ( server_ops )
expect ( server_batch . send_close ) . to be true
expect ( server_batch . send_status ) . to be true
# finish the call
final_client_batch = call . run_batch (
CallOps :: RECV_INITIAL_METADATA = > nil ,
CallOps :: RECV_STATUS_ON_CLIENT = > nil )
expect ( final_client_batch . metadata ) . to eq ( { } )
expect ( final_client_batch . status . code ) . to eq ( 0 )
end
it 'responses written by servers are received by the client' do
call = new_client_call
server_call = nil
server_thread = Thread . new do
server_call = server_allows_client_to_proceed
end
client_ops = {
CallOps :: SEND_INITIAL_METADATA = > { } ,
CallOps :: SEND_MESSAGE = > sent_message ,
CallOps :: SEND_CLOSE_FROM_CLIENT = > nil
}
client_batch = call . run_batch ( client_ops )
expect ( client_batch . send_metadata ) . to be true
expect ( client_batch . send_message ) . to be true
expect ( client_batch . send_close ) . to be true
# confirm the server can read the inbound message
server_thread . join
server_ops = {
CallOps :: RECV_MESSAGE = > nil
}
server_batch = server_call . run_batch ( server_ops )
expect ( server_batch . message ) . to eq ( sent_message )
server_ops = {
CallOps :: RECV_CLOSE_ON_SERVER = > nil ,
CallOps :: SEND_MESSAGE = > reply_text ,
CallOps :: SEND_STATUS_FROM_SERVER = > ok_status
}
server_batch = server_call . run_batch ( server_ops )
expect ( server_batch . send_close ) . to be true
expect ( server_batch . send_message ) . to be true
expect ( server_batch . send_status ) . to be true
# finish the call
final_client_batch = call . run_batch (
CallOps :: RECV_INITIAL_METADATA = > nil ,
CallOps :: RECV_MESSAGE = > nil ,
CallOps :: RECV_STATUS_ON_CLIENT = > nil )
expect ( final_client_batch . metadata ) . to eq ( { } )
expect ( final_client_batch . message ) . to eq ( reply_text )
expect ( final_client_batch . status . code ) . to eq ( 0 )
end
it 'compressed messages can be sent and received' do
call = new_client_call
server_call = nil
long_request_str = '0' * 2000
long_response_str = '1' * 2000
md = { 'grpc-internal-encoding-request' = > 'gzip' }
server_thread = Thread . new do
server_call = server_allows_client_to_proceed ( md )
it 'unary calls work' do
run_services_on_server ( @server , services : [ EchoService ] ) do
call = @stub . an_rpc ( EchoMsg . new , return_op : true )
expect ( call . execute ) . to be_a ( EchoMsg )
end
client_ops = {
CallOps :: SEND_INITIAL_METADATA = > md ,
CallOps :: SEND_MESSAGE = > long_request_str ,
CallOps :: SEND_CLOSE_FROM_CLIENT = > nil
}
client_batch = call . run_batch ( client_ops )
expect ( client_batch . send_metadata ) . to be true
expect ( client_batch . send_message ) . to be true
expect ( client_batch . send_close ) . to be true
# confirm the server can read the inbound message
server_thread . join
server_ops = {
CallOps :: RECV_MESSAGE = > nil
}
server_batch = server_call . run_batch ( server_ops )
expect ( server_batch . message ) . to eq ( long_request_str )
server_ops = {
CallOps :: RECV_CLOSE_ON_SERVER = > nil ,
CallOps :: SEND_MESSAGE = > long_response_str ,
CallOps :: SEND_STATUS_FROM_SERVER = > ok_status
}
server_batch = server_call . run_batch ( server_ops )
expect ( server_batch . send_close ) . to be true
expect ( server_batch . send_message ) . to be true
expect ( server_batch . send_status ) . to be true
client_ops = {
CallOps :: RECV_INITIAL_METADATA = > nil ,
CallOps :: RECV_MESSAGE = > nil ,
CallOps :: RECV_STATUS_ON_CLIENT = > nil
}
final_client_batch = call . run_batch ( client_ops )
expect ( final_client_batch . metadata ) . to eq ( { } )
expect ( final_client_batch . message ) . to eq long_response_str
expect ( final_client_batch . status . code ) . to eq ( 0 )
end
it 'servers can ignore a client write and send a status' do
call = new_client_call
server_call = nil
server_thread = Thread . new do
server_call = server_allows_client_to_proceed
it 'unary calls work when enabling compression' do
run_services_on_server ( @server , services : [ EchoService ] ) do
long_request_str = '0' * 2000
md = { 'grpc-internal-encoding-request' = > 'gzip' }
call = @stub . an_rpc ( EchoMsg . new ( msg : long_request_str ) ,
return_op : true ,
metadata : md )
response = call . execute
expect ( response ) . to be_a ( EchoMsg )
expect ( response . msg ) . to eq ( long_request_str )
end
client_ops = {
CallOps :: SEND_INITIAL_METADATA = > { } ,
CallOps :: SEND_MESSAGE = > sent_message ,
CallOps :: SEND_CLOSE_FROM_CLIENT = > nil
}
client_batch = call . run_batch ( client_ops )
expect ( client_batch . send_metadata ) . to be true
expect ( client_batch . send_message ) . to be true
expect ( client_batch . send_close ) . to be true
# confirm the server can read the inbound message
the_status = Struct :: Status . new ( StatusCodes :: OK , 'OK' )
server_thread . join
server_ops = {
CallOps :: SEND_STATUS_FROM_SERVER = > the_status
}
server_batch = server_call . run_batch ( server_ops )
expect ( server_batch . message ) . to eq nil
expect ( server_batch . send_status ) . to be true
final_client_batch = call . run_batch (
CallOps :: RECV_INITIAL_METADATA = > nil ,
CallOps :: RECV_STATUS_ON_CLIENT = > nil )
expect ( final_client_batch . metadata ) . to eq ( { } )
expect ( final_client_batch . status . code ) . to eq ( 0 )
end
it 'completes calls by sending status to client and server' do
call = new_client_call
server_call = nil
server_thread = Thread . new do
server_call = server_allows_client_to_proceed
end
client_ops = {
CallOps :: SEND_INITIAL_METADATA = > { } ,
CallOps :: SEND_MESSAGE = > sent_message
}
client_batch = call . run_batch ( client_ops )
expect ( client_batch . send_metadata ) . to be true
expect ( client_batch . send_message ) . to be true
# confirm the server can read the inbound message and respond
the_status = Struct :: Status . new ( StatusCodes :: OK , 'OK' , { } )
server_thread . join
server_ops = {
CallOps :: RECV_MESSAGE = > nil
}
server_batch = server_call . run_batch ( server_ops )
expect ( server_batch . message ) . to eq sent_message
server_ops = {
CallOps :: SEND_MESSAGE = > reply_text ,
CallOps :: SEND_STATUS_FROM_SERVER = > the_status
}
server_batch = server_call . run_batch ( server_ops )
expect ( server_batch . send_status ) . to be true
expect ( server_batch . send_message ) . to be true
# confirm the client can receive the server response and status.
client_ops = {
CallOps :: SEND_CLOSE_FROM_CLIENT = > nil ,
CallOps :: RECV_INITIAL_METADATA = > nil ,
CallOps :: RECV_MESSAGE = > nil ,
CallOps :: RECV_STATUS_ON_CLIENT = > nil
}
final_client_batch = call . run_batch ( client_ops )
expect ( final_client_batch . send_close ) . to be true
expect ( final_client_batch . message ) . to eq reply_text
expect ( final_client_batch . status ) . to eq the_status
# confirm the server can receive the client close.
server_ops = {
CallOps :: RECV_CLOSE_ON_SERVER = > nil
}
final_server_batch = server_call . run_batch ( server_ops )
expect ( final_server_batch . send_close ) . to be true
end
def client_cancel_test ( cancel_proc , expected_code ,
expected_details )
call = new_client_call
server_call = nil
server_thread = Thread . new do
server_call = server_allows_client_to_proceed
call = @stub . an_rpc ( EchoMsg . new , return_op : true )
run_services_on_server ( @server , services : [ EchoService ] ) do
# start the call, but don't send a message yet
call . start_call
# cancel the call
cancel_proc . call ( call )
# check the client's status
failed = false
begin
call . execute
rescue GRPC :: BadStatus = > e
failed = true
expect ( e . code ) . to be expected_code
expect ( e . details ) . to eq expected_details
end
expect ( failed ) . to be ( true )
end
client_ops = {
CallOps :: SEND_INITIAL_METADATA = > { } ,
CallOps :: RECV_INITIAL_METADATA = > nil
}
client_batch = call . run_batch ( client_ops )
expect ( client_batch . send_metadata ) . to be true
expect ( client_batch . metadata ) . to eq ( { } )
cancel_proc . call ( call )
server_thread . join
server_ops = {
CallOps :: RECV_CLOSE_ON_SERVER = > nil
}
server_batch = server_call . run_batch ( server_ops )
expect ( server_batch . send_close ) . to be true
client_ops = {
CallOps :: RECV_STATUS_ON_CLIENT = > { }
}
client_batch = call . run_batch ( client_ops )
expect ( client_batch . status . code ) . to be expected_code
expect ( client_batch . status . details ) . to eq expected_details
end
it 'clients can cancel a call on the server' do
@ -344,8 +89,6 @@ shared_examples 'basic GRPC message delivery is OK' do
end
shared_examples 'GRPC metadata delivery works OK' do
include_context 'setup: tags'
describe 'from client => server' do
before ( :example ) do
n = 7 # arbitrary number of metadata
@ -364,53 +107,31 @@ shared_examples 'GRPC metadata delivery works OK' do
it 'raises an exception if a metadata key is invalid' do
@bad_keys . each do | md |
call = new_client_call
client_ops = {
CallOps :: SEND_INITIAL_METADATA = > md
}
blk = proc do
call . run_batch ( client_ops )
# NOTE: no need to run a server in this test b/c the failure
# happens while validating metadata to send.
failed = false
begin
@stub . an_rpc ( EchoMsg . new , metadata : md )
rescue TypeError = > e
failed = true
expect ( e . message ) . to eq ( 'grpc_rb_md_ary_fill_hash_cb: bad type for key parameter' )
end
expect ( & blk ) . to raise_error
expect ( failed ) . to be ( true )
end
end
it 'sends all the metadata pairs when keys and values are valid' do
@valid_metadata . each do | md |
recvd_rpc = nil
rcv_thread = Thread . new do
recvd_rpc = @server . request_call
service = EchoService . new
run_services_on_server ( @server , services : [ service ] ) do
@valid_metadata . each_with_index do | md , i |
expect ( @stub . an_rpc ( EchoMsg . new , metadata : md ) ) . to be_a ( EchoMsg )
# confirm the server can receive the client metadata
# finish the call
expect ( service . received_md . length ) . to eq ( i + 1 )
md . each do | k , v |
expect ( service . received_md [ i ] [ k . to_s ] ) . to eq ( v )
end
end
call = new_client_call
client_ops = {
CallOps :: SEND_INITIAL_METADATA = > md ,
CallOps :: SEND_CLOSE_FROM_CLIENT = > nil
}
client_batch = call . run_batch ( client_ops )
expect ( client_batch . send_metadata ) . to be true
# confirm the server can receive the client metadata
rcv_thread . join
expect ( recvd_rpc ) . to_not eq nil
recvd_md = recvd_rpc . metadata
replace_symbols = Hash [ md . each_pair . collect { | x , y | [ x . to_s , y ] } ]
expect ( recvd_md ) . to eq ( recvd_md . merge ( replace_symbols ) )
# finish the call
final_server_batch = recvd_rpc . call . run_batch (
CallOps :: RECV_CLOSE_ON_SERVER = > nil ,
CallOps :: SEND_INITIAL_METADATA = > nil ,
CallOps :: SEND_STATUS_FROM_SERVER = > ok_status )
expect ( final_server_batch . send_close ) . to be ( true )
expect ( final_server_batch . send_metadata ) . to be ( true )
expect ( final_server_batch . send_status ) . to be ( true )
final_client_batch = call . run_batch (
CallOps :: RECV_INITIAL_METADATA = > nil ,
CallOps :: RECV_STATUS_ON_CLIENT = > nil )
expect ( final_client_batch . metadata ) . to eq ( { } )
expect ( final_client_batch . status . code ) . to eq ( 0 )
end
end
end
@ -432,120 +153,61 @@ shared_examples 'GRPC metadata delivery works OK' do
end
it 'raises an exception if a metadata key is invalid' do
@bad_keys . each do | md |
recvd_rpc = nil
rcv_thread = Thread . new do
recvd_rpc = @server . request_call
end
call = new_client_call
# client signals that it's done sending metadata to allow server to
# respond
client_ops = {
CallOps :: SEND_INITIAL_METADATA = > nil
}
call . run_batch ( client_ops )
# server gets the invocation
rcv_thread . join
expect ( recvd_rpc ) . to_not eq nil
server_ops = {
CallOps :: SEND_INITIAL_METADATA = > md
}
blk = proc do
recvd_rpc . call . run_batch ( server_ops )
service = EchoService . new
run_services_on_server ( @server , services : [ service ] ) do
@bad_keys . each do | md |
proceed = Queue . new
server_exception = nil
service . on_call_started = proc do | call |
call . send_initial_metadata ( md )
rescue TypeError = > e
server_exception = e
ensure
proceed . push ( 1 )
end
client_exception = nil
client_call = @stub . an_rpc ( EchoMsg . new , return_op : true )
thr = Thread . new do
client_call . execute
rescue GRPC :: BadStatus = > e
client_exception = e
end
proceed . pop
# TODO(apolcyn): we shouldn't need this cancel here. It's
# only currently needed b/c the server does not seem to properly
# terminate the RPC if it fails to send initial metadata. That
# should be fixed, in which case this cancellation can be removed.
client_call . cancel
thr . join
p client_exception
expect ( client_exception . nil? ) . to be ( false )
expect ( server_exception . nil? ) . to be ( false )
expect ( server_exception . message ) . to eq (
'grpc_rb_md_ary_fill_hash_cb: bad type for key parameter' )
end
expect ( & blk ) . to raise_error
# cancel the call so the server can shut down immediately
call . cancel
end
end
it 'sends an empty hash if no metadata is added' do
recvd_rpc = nil
rcv_thread = Thread . new do
recvd_rpc = @server . request_call
run_services_on_server ( @server , services : [ EchoService ] ) do
call = @stub . an_rpc ( EchoMsg . new , return_op : true )
expect ( call . execute ) . to be_a ( EchoMsg )
expect ( call . metadata ) . to eq ( { } )
end
call = new_client_call
# client signals that it's done sending metadata to allow server to
# respond
client_ops = {
CallOps :: SEND_INITIAL_METADATA = > nil ,
CallOps :: SEND_CLOSE_FROM_CLIENT = > nil
}
client_batch = call . run_batch ( client_ops )
expect ( client_batch . send_metadata ) . to be true
expect ( client_batch . send_close ) . to be true
# server gets the invocation but sends no metadata back
rcv_thread . join
expect ( recvd_rpc ) . to_not eq nil
server_call = recvd_rpc . call
server_ops = {
# receive close and send status to finish the call
CallOps :: RECV_CLOSE_ON_SERVER = > nil ,
CallOps :: SEND_INITIAL_METADATA = > nil ,
CallOps :: SEND_STATUS_FROM_SERVER = > ok_status
}
srv_batch = server_call . run_batch ( server_ops )
expect ( srv_batch . send_close ) . to be true
expect ( srv_batch . send_metadata ) . to be true
expect ( srv_batch . send_status ) . to be true
# client receives nothing as expected
client_ops = {
CallOps :: RECV_INITIAL_METADATA = > nil ,
# receive status to finish the call
CallOps :: RECV_STATUS_ON_CLIENT = > nil
}
final_client_batch = call . run_batch ( client_ops )
expect ( final_client_batch . metadata ) . to eq ( { } )
expect ( final_client_batch . status . code ) . to eq ( 0 )
end
it 'sends all the pairs when keys and values are valid' do
@valid_metadata . each do | md |
recvd_rpc = nil
rcv_thread = Thread . new do
recvd_rpc = @server . request_call
service = EchoService . new
run_services_on_server ( @server , services : [ service ] ) do
@valid_metadata . each do | md |
service . on_call_started = proc do | call |
call . send_initial_metadata ( md )
end
call = @stub . an_rpc ( EchoMsg . new , return_op : true )
call . execute
replace_symbols = Hash [ md . each_pair . collect { | x , y | [ x . to_s , y ] } ]
expect ( call . metadata ) . to eq ( replace_symbols )
end
call = new_client_call
# client signals that it's done sending metadata to allow server to
# respond
client_ops = {
CallOps :: SEND_INITIAL_METADATA = > nil ,
CallOps :: SEND_CLOSE_FROM_CLIENT = > nil
}
client_batch = call . run_batch ( client_ops )
expect ( client_batch . send_metadata ) . to be true
expect ( client_batch . send_close ) . to be true
# server gets the invocation but sends no metadata back
rcv_thread . join
expect ( recvd_rpc ) . to_not eq nil
server_call = recvd_rpc . call
server_ops = {
CallOps :: RECV_CLOSE_ON_SERVER = > nil ,
CallOps :: SEND_INITIAL_METADATA = > md ,
CallOps :: SEND_STATUS_FROM_SERVER = > ok_status
}
srv_batch = server_call . run_batch ( server_ops )
expect ( srv_batch . send_close ) . to be true
expect ( srv_batch . send_metadata ) . to be true
expect ( srv_batch . send_status ) . to be true
# client receives nothing as expected
client_ops = {
CallOps :: RECV_INITIAL_METADATA = > nil ,
CallOps :: RECV_STATUS_ON_CLIENT = > nil
}
final_client_batch = call . run_batch ( client_ops )
replace_symbols = Hash [ md . each_pair . collect { | x , y | [ x . to_s , y ] } ]
expect ( final_client_batch . metadata ) . to eq ( replace_symbols )
expect ( final_client_batch . status . code ) . to eq ( 0 )
end
end
end
@ -554,16 +216,11 @@ end
describe 'the http client/server' do
before ( :example ) do
server_host = '0.0.0.0:0'
@server = new_core _server_for_testing ( nil )
@server = new_rp c_server_for_testing
server_port = @server . add_http2_port ( server_host , :this_port_is_insecure )
@server . start
@ch = Channel . new ( " 0.0.0.0: #{ server_port } " , nil , :this_channel_is_insecure )
end
after ( :example ) do
@ch . close
@server . shutdown_and_notify ( deadline )
@server . close
@stub = EchoStub . new (
" 0.0.0.0: #{ server_port } " , nil , channel_override : @ch )
end
it_behaves_like 'basic GRPC message delivery is OK' do
@ -574,8 +231,6 @@ describe 'the http client/server' do
end
describe 'the secure http client/server' do
include_context 'setup: tags'
def load_test_certs
test_root = File . join ( File . dirname ( __FILE__ ) , 'testdata' )
files = [ 'ca.pem' , 'server1.key' , 'server1.pem' ]
@ -587,17 +242,14 @@ describe 'the secure http client/server' do
server_host = '0.0.0.0:0'
server_creds = GRPC :: Core :: ServerCredentials . new (
nil , [ { private_key : certs [ 1 ] , cert_chain : certs [ 2 ] } ] , false )
@server = new_core _server_for_testing ( nil )
@server = new_rp c_server_for_testing
server_port = @server . add_http2_port ( server_host , server_creds )
@server . start
args = { Channel :: SSL_TARGET = > 'foo.test.google.fr' }
@ch = Channel . new ( " 0.0.0.0: #{ server_port } " , args ,
GRPC :: Core :: ChannelCredentials . new ( certs [ 0 ] , nil , nil ) )
end
after ( :example ) do
@server . shutdown_and_notify ( deadline )
@server . close
@ch = Channel . new (
" 0.0.0.0: #{ server_port } " , args ,
GRPC :: Core :: ChannelCredentials . new ( certs [ 0 ] , nil , nil ) )
@stub = EchoStub . new (
" 0.0.0.0: #{ server_port } " , nil , channel_override : @ch )
end
it_behaves_like 'basic GRPC message delivery is OK' do
@ -606,59 +258,25 @@ describe 'the secure http client/server' do
it_behaves_like 'GRPC metadata delivery works OK' do
end
def credentials_update_test ( creds_update_md )
auth_proc = proc { creds_update_md }
it 'modifies metadata with CallCredentials' do
# create call creds
auth_proc = proc { { 'k1' = > 'v1' } }
call_creds = GRPC :: Core :: CallCredentials . new ( auth_proc )
initial_md_key = 'k2'
initial_md_val = 'v2'
initial_md = { initial_md_key = > initial_md_val }
expected_md = creds_update_md . clone
fail 'bad test param' unless expected_md [ initial_md_key ] . nil?
expected_md [ initial_md_key ] = initial_md_val
recvd_rpc = nil
rcv_thread = Thread . new do
recvd_rpc = @server . request_call
# create arbitrary custom metadata
custom_md = { 'k2' = > 'v2' }
# perform an RPC
echo_service = EchoService . new
run_services_on_server ( @server , services : [ echo_service ] ) do
expect ( @stub . an_rpc ( EchoMsg . new ,
credentials : call_creds ,
metadata : custom_md ) ) . to be_a ( EchoMsg )
end
# call creds metadata should be merged with custom MD
expect ( echo_service . received_md . length ) . to eq ( 1 )
expected_md = { 'k1' = > 'v1' , 'k2' = > 'v2' }
expected_md . each do | k , v |
expect ( echo_service . received_md [ 0 ] [ k ] ) . to eq ( v )
end
call = new_client_call
call . set_credentials! call_creds
client_batch = call . run_batch (
CallOps :: SEND_INITIAL_METADATA = > initial_md ,
CallOps :: SEND_CLOSE_FROM_CLIENT = > nil )
expect ( client_batch . send_metadata ) . to be true
expect ( client_batch . send_close ) . to be true
# confirm the server can receive the client metadata
rcv_thread . join
expect ( recvd_rpc ) . to_not eq nil
recvd_md = recvd_rpc . metadata
replace_symbols = Hash [ expected_md . each_pair . collect { | x , y | [ x . to_s , y ] } ]
expect ( recvd_md ) . to eq ( recvd_md . merge ( replace_symbols ) )
credentials_update_test_finish_call ( call , recvd_rpc . call )
end
def credentials_update_test_finish_call ( client_call , server_call )
final_server_batch = server_call . run_batch (
CallOps :: RECV_CLOSE_ON_SERVER = > nil ,
CallOps :: SEND_INITIAL_METADATA = > nil ,
CallOps :: SEND_STATUS_FROM_SERVER = > ok_status )
expect ( final_server_batch . send_close ) . to be ( true )
expect ( final_server_batch . send_metadata ) . to be ( true )
expect ( final_server_batch . send_status ) . to be ( true )
final_client_batch = client_call . run_batch (
CallOps :: RECV_INITIAL_METADATA = > nil ,
CallOps :: RECV_STATUS_ON_CLIENT = > nil )
expect ( final_client_batch . metadata ) . to eq ( { } )
expect ( final_client_batch . status . code ) . to eq ( 0 )
end
it 'modifies metadata with CallCredentials' do
credentials_update_test ( 'k1' = > 'updated-v1' )
end
it 'modifies large metadata with CallCredentials' do
@ -666,11 +284,34 @@ describe 'the secure http client/server' do
'00000000000000000000000000000000000000000000000000000000000000' ,
'11111111111111111111111111111111111111111111111111111111111111' ,
)
md = {
k3 : val_array ,
k4 : '0000000000000000000000000000000000000000000000000000000000' ,
keeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeey5 : 'v1'
# create call creds
auth_proc = proc do
{
k2 : val_array ,
k3 : '0000000000000000000000000000000000000000000000000000000000' ,
keeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeey4 : 'v4'
}
end
call_creds = GRPC :: Core :: CallCredentials . new ( auth_proc )
# create arbitrary custom metadata
custom_md = { k1 : 'v1' }
# perform an RPC
echo_service = EchoService . new
run_services_on_server ( @server , services : [ echo_service ] ) do
expect ( @stub . an_rpc ( EchoMsg . new ,
credentials : call_creds ,
metadata : custom_md ) ) . to be_a ( EchoMsg )
end
# call creds metadata should be merged with custom MD
expect ( echo_service . received_md . length ) . to eq ( 1 )
expected_md = {
k1 : 'v1' ,
k2 : val_array ,
k3 : '0000000000000000000000000000000000000000000000000000000000' ,
keeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeey4 : 'v4'
}
credentials_update_test ( md )
expected_md . each do | k , v |
expect ( echo_service . received_md [ 0 ] [ k . to_s ] ) . to eq ( v )
end
end
end