active_call_spec.rb 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. # Copyright 2015 gRPC authors.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. require 'spec_helper'
  15. include GRPC::Core::StatusCodes
  16. describe GRPC::ActiveCall do
  17. ActiveCall = GRPC::ActiveCall
  18. Call = GRPC::Core::Call
  19. CallOps = GRPC::Core::CallOps
  20. WriteFlags = GRPC::Core::WriteFlags
  21. def ok_status
  22. Struct::Status.new(OK, 'OK')
  23. end
  24. def send_and_receive_close_and_status(client_call, server_call)
  25. client_call.run_batch(CallOps::SEND_CLOSE_FROM_CLIENT => nil)
  26. server_call.run_batch(CallOps::RECV_CLOSE_ON_SERVER => nil,
  27. CallOps::SEND_STATUS_FROM_SERVER => ok_status)
  28. client_call.run_batch(CallOps::RECV_STATUS_ON_CLIENT => nil)
  29. end
  30. def inner_call_of_active_call(active_call)
  31. active_call.instance_variable_get(:@call)
  32. end
  33. before(:each) do
  34. @pass_through = proc { |x| x }
  35. host = '0.0.0.0:0'
  36. @server = new_core_server_for_testing(nil)
  37. server_port = @server.add_http2_port(host, :this_port_is_insecure)
  38. @server.start
  39. @ch = GRPC::Core::Channel.new("0.0.0.0:#{server_port}", nil,
  40. :this_channel_is_insecure)
  41. end
  42. after(:each) do
  43. @server.shutdown_and_notify(deadline)
  44. @server.close
  45. end
  46. describe 'restricted view methods' do
  47. before(:each) do
  48. call = make_test_call
  49. ActiveCall.client_invoke(call)
  50. @client_call = ActiveCall.new(call, @pass_through,
  51. @pass_through, deadline)
  52. end
  53. describe '#multi_req_view' do
  54. it 'exposes a fixed subset of the ActiveCall.methods' do
  55. want = %w(cancelled?, deadline, each_remote_read, metadata, \
  56. shutdown, peer, peer_cert, send_initial_metadata, \
  57. initial_metadata_sent)
  58. v = @client_call.multi_req_view
  59. want.each do |w|
  60. expect(v.methods.include?(w))
  61. end
  62. end
  63. end
  64. describe '#single_req_view' do
  65. it 'exposes a fixed subset of the ActiveCall.methods' do
  66. want = %w(cancelled?, deadline, metadata, shutdown, \
  67. send_initial_metadata, metadata_to_send, \
  68. merge_metadata_to_send, initial_metadata_sent)
  69. v = @client_call.single_req_view
  70. want.each do |w|
  71. expect(v.methods.include?(w))
  72. end
  73. end
  74. end
  75. describe '#interceptable' do
  76. it 'exposes a fixed subset of the ActiveCall.methods' do
  77. want = %w(deadline)
  78. v = @client_call.interceptable
  79. want.each do |w|
  80. expect(v.methods.include?(w))
  81. end
  82. end
  83. end
  84. end
  85. describe '#remote_send' do
  86. it 'allows a client to send a payload to the server', test: true do
  87. call = make_test_call
  88. ActiveCall.client_invoke(call)
  89. client_call = ActiveCall.new(call, @pass_through,
  90. @pass_through, deadline)
  91. msg = 'message is a string'
  92. client_call.remote_send(msg)
  93. # check that server rpc new was received
  94. recvd_rpc = @server.request_call
  95. expect(recvd_rpc).to_not eq nil
  96. recvd_call = recvd_rpc.call
  97. # Accept the call, and verify that the server reads the response ok.
  98. server_call = ActiveCall.new(recvd_call, @pass_through,
  99. @pass_through, deadline,
  100. metadata_received: true,
  101. started: false)
  102. expect(server_call.remote_read).to eq(msg)
  103. # finish the call
  104. server_call.send_initial_metadata
  105. call.run_batch(CallOps::RECV_INITIAL_METADATA => nil)
  106. send_and_receive_close_and_status(call, recvd_call)
  107. end
  108. it 'marshals the payload using the marshal func' do
  109. call = make_test_call
  110. ActiveCall.client_invoke(call)
  111. marshal = proc { |x| 'marshalled:' + x }
  112. client_call = ActiveCall.new(call, marshal, @pass_through, deadline)
  113. msg = 'message is a string'
  114. client_call.remote_send(msg)
  115. # confirm that the message was marshalled
  116. recvd_rpc = @server.request_call
  117. recvd_call = recvd_rpc.call
  118. server_ops = {
  119. CallOps::SEND_INITIAL_METADATA => nil
  120. }
  121. recvd_call.run_batch(server_ops)
  122. server_call = ActiveCall.new(recvd_call, @pass_through,
  123. @pass_through, deadline,
  124. metadata_received: true)
  125. expect(server_call.remote_read).to eq('marshalled:' + msg)
  126. # finish the call
  127. call.run_batch(CallOps::RECV_INITIAL_METADATA => nil)
  128. send_and_receive_close_and_status(call, recvd_call)
  129. end
  130. TEST_WRITE_FLAGS = [WriteFlags::BUFFER_HINT, WriteFlags::NO_COMPRESS]
  131. TEST_WRITE_FLAGS.each do |f|
  132. it "successfully makes calls with write_flag set to #{f}" do
  133. call = make_test_call
  134. ActiveCall.client_invoke(call)
  135. marshal = proc { |x| 'marshalled:' + x }
  136. client_call = ActiveCall.new(call, marshal,
  137. @pass_through, deadline)
  138. msg = 'message is a string'
  139. client_call.write_flag = f
  140. client_call.remote_send(msg)
  141. # flush the message in case writes are set to buffered
  142. call.run_batch(CallOps::SEND_CLOSE_FROM_CLIENT => nil) if f == 1
  143. # confirm that the message was marshalled
  144. recvd_rpc = @server.request_call
  145. recvd_call = recvd_rpc.call
  146. server_ops = {
  147. CallOps::SEND_INITIAL_METADATA => nil
  148. }
  149. recvd_call.run_batch(server_ops)
  150. server_call = ActiveCall.new(recvd_call, @pass_through,
  151. @pass_through, deadline,
  152. metadata_received: true)
  153. expect(server_call.remote_read).to eq('marshalled:' + msg)
  154. # finish the call
  155. server_call.send_status(OK, '', true)
  156. client_call.receive_and_check_status
  157. end
  158. end
  159. end
  160. describe 'sending initial metadata', send_initial_metadata: true do
  161. it 'sends metadata before sending a message if it hasnt been sent yet' do
  162. call = make_test_call
  163. @client_call = ActiveCall.new(
  164. call,
  165. @pass_through,
  166. @pass_through,
  167. deadline,
  168. started: false)
  169. metadata = { key: 'dummy_val', other: 'other_val' }
  170. expect(@client_call.metadata_sent).to eq(false)
  171. @client_call.merge_metadata_to_send(metadata)
  172. message = 'dummy message'
  173. expect(call).to(
  174. receive(:run_batch)
  175. .with(
  176. hash_including(
  177. CallOps::SEND_INITIAL_METADATA => metadata)).once)
  178. expect(call).to(
  179. receive(:run_batch).with(hash_including(
  180. CallOps::SEND_MESSAGE => message)).once)
  181. @client_call.remote_send(message)
  182. expect(@client_call.metadata_sent).to eq(true)
  183. end
  184. it 'doesnt send metadata if it thinks its already been sent' do
  185. call = make_test_call
  186. @client_call = ActiveCall.new(call,
  187. @pass_through,
  188. @pass_through,
  189. deadline)
  190. expect(@client_call.metadata_sent).to eql(true)
  191. expect(call).to(
  192. receive(:run_batch).with(hash_including(
  193. CallOps::SEND_INITIAL_METADATA)).never)
  194. @client_call.remote_send('test message')
  195. end
  196. it 'sends metadata if it is explicitly sent and ok to do so' do
  197. call = make_test_call
  198. @client_call = ActiveCall.new(call,
  199. @pass_through,
  200. @pass_through,
  201. deadline,
  202. started: false)
  203. expect(@client_call.metadata_sent).to eql(false)
  204. metadata = { test_key: 'val' }
  205. @client_call.merge_metadata_to_send(metadata)
  206. expect(@client_call.metadata_to_send).to eq(metadata)
  207. expect(call).to(
  208. receive(:run_batch).with(hash_including(
  209. CallOps::SEND_INITIAL_METADATA =>
  210. metadata)).once)
  211. @client_call.send_initial_metadata
  212. end
  213. it 'explicit sending does nothing if metadata has already been sent' do
  214. call = make_test_call
  215. @client_call = ActiveCall.new(call,
  216. @pass_through,
  217. @pass_through,
  218. deadline)
  219. expect(@client_call.metadata_sent).to eql(true)
  220. blk = proc do
  221. @client_call.send_initial_metadata
  222. end
  223. expect { blk.call }.to_not raise_error
  224. end
  225. end
  226. describe '#merge_metadata_to_send', merge_metadata_to_send: true do
  227. it 'adds to existing metadata when there is existing metadata to send' do
  228. call = make_test_call
  229. starting_metadata = {
  230. k1: 'key1_val',
  231. k2: 'key2_val',
  232. k3: 'key3_val'
  233. }
  234. @client_call = ActiveCall.new(
  235. call,
  236. @pass_through, @pass_through,
  237. deadline,
  238. started: false,
  239. metadata_to_send: starting_metadata)
  240. expect(@client_call.metadata_to_send).to eq(starting_metadata)
  241. @client_call.merge_metadata_to_send(
  242. k3: 'key3_new_val',
  243. k4: 'key4_val')
  244. expected_md_to_send = {
  245. k1: 'key1_val',
  246. k2: 'key2_val',
  247. k3: 'key3_new_val',
  248. k4: 'key4_val' }
  249. expect(@client_call.metadata_to_send).to eq(expected_md_to_send)
  250. @client_call.merge_metadata_to_send(k5: 'key5_val')
  251. expected_md_to_send.merge!(k5: 'key5_val')
  252. expect(@client_call.metadata_to_send).to eq(expected_md_to_send)
  253. end
  254. it 'fails when initial metadata has already been sent' do
  255. call = make_test_call
  256. @client_call = ActiveCall.new(
  257. call,
  258. @pass_through,
  259. @pass_through,
  260. deadline,
  261. started: true)
  262. expect(@client_call.metadata_sent).to eq(true)
  263. blk = proc do
  264. @client_call.merge_metadata_to_send(k1: 'key1_val')
  265. end
  266. expect { blk.call }.to raise_error
  267. end
  268. end
  269. describe '#client_invoke' do
  270. it 'sends metadata to the server when present' do
  271. call = make_test_call
  272. metadata = { k1: 'v1', k2: 'v2' }
  273. ActiveCall.client_invoke(call, metadata)
  274. recvd_rpc = @server.request_call
  275. recvd_call = recvd_rpc.call
  276. expect(recvd_call).to_not be_nil
  277. expect(recvd_rpc.metadata).to_not be_nil
  278. expect(recvd_rpc.metadata['k1']).to eq('v1')
  279. expect(recvd_rpc.metadata['k2']).to eq('v2')
  280. # finish the call
  281. recvd_call.run_batch(CallOps::SEND_INITIAL_METADATA => {})
  282. call.run_batch(CallOps::RECV_INITIAL_METADATA => nil)
  283. send_and_receive_close_and_status(call, recvd_call)
  284. end
  285. end
  286. describe '#send_status', send_status: true do
  287. it 'works when no metadata or messages have been sent yet' do
  288. call = make_test_call
  289. ActiveCall.client_invoke(call)
  290. recvd_rpc = @server.request_call
  291. server_call = ActiveCall.new(
  292. recvd_rpc.call,
  293. @pass_through,
  294. @pass_through,
  295. deadline,
  296. started: false)
  297. expect(server_call.metadata_sent).to eq(false)
  298. blk = proc { server_call.send_status(OK) }
  299. expect { blk.call }.to_not raise_error
  300. end
  301. end
  302. describe '#remote_read', remote_read: true do
  303. it 'reads the response sent by a server' do
  304. call = make_test_call
  305. ActiveCall.client_invoke(call)
  306. client_call = ActiveCall.new(call, @pass_through,
  307. @pass_through, deadline)
  308. msg = 'message is a string'
  309. client_call.remote_send(msg)
  310. server_call = expect_server_to_receive(msg)
  311. server_call.remote_send('server_response')
  312. expect(client_call.remote_read).to eq('server_response')
  313. send_and_receive_close_and_status(
  314. call, inner_call_of_active_call(server_call))
  315. end
  316. it 'saves no metadata when the server adds no metadata' do
  317. call = make_test_call
  318. ActiveCall.client_invoke(call)
  319. client_call = ActiveCall.new(call, @pass_through,
  320. @pass_through, deadline)
  321. msg = 'message is a string'
  322. client_call.remote_send(msg)
  323. server_call = expect_server_to_receive(msg)
  324. server_call.remote_send('ignore me')
  325. expect(client_call.metadata).to be_nil
  326. client_call.remote_read
  327. expect(client_call.metadata).to eq({})
  328. send_and_receive_close_and_status(
  329. call, inner_call_of_active_call(server_call))
  330. end
  331. it 'saves metadata add by the server' do
  332. call = make_test_call
  333. ActiveCall.client_invoke(call)
  334. client_call = ActiveCall.new(call, @pass_through,
  335. @pass_through, deadline)
  336. msg = 'message is a string'
  337. client_call.remote_send(msg)
  338. server_call = expect_server_to_receive(msg, k1: 'v1', k2: 'v2')
  339. server_call.remote_send('ignore me')
  340. expect(client_call.metadata).to be_nil
  341. client_call.remote_read
  342. expected = { 'k1' => 'v1', 'k2' => 'v2' }
  343. expect(client_call.metadata).to eq(expected)
  344. send_and_receive_close_and_status(
  345. call, inner_call_of_active_call(server_call))
  346. end
  347. it 'get a status from server when nothing else sent from server' do
  348. client_call = make_test_call
  349. ActiveCall.client_invoke(client_call)
  350. recvd_rpc = @server.request_call
  351. recvd_call = recvd_rpc.call
  352. server_call = ActiveCall.new(
  353. recvd_call,
  354. @pass_through,
  355. @pass_through,
  356. deadline,
  357. started: false)
  358. server_call.send_status(OK, 'OK')
  359. # Check that we can receive initial metadata and a status
  360. client_call.run_batch(
  361. CallOps::RECV_INITIAL_METADATA => nil)
  362. batch_result = client_call.run_batch(
  363. CallOps::RECV_STATUS_ON_CLIENT => nil)
  364. expect(batch_result.status.code).to eq(OK)
  365. end
  366. it 'get a nil msg before a status when an OK status is sent' do
  367. call = make_test_call
  368. ActiveCall.client_invoke(call)
  369. client_call = ActiveCall.new(call, @pass_through,
  370. @pass_through, deadline)
  371. msg = 'message is a string'
  372. client_call.remote_send(msg)
  373. call.run_batch(CallOps::SEND_CLOSE_FROM_CLIENT => nil)
  374. server_call = expect_server_to_receive(msg)
  375. server_call.remote_send('server_response')
  376. server_call.send_status(OK, 'OK')
  377. expect(client_call.remote_read).to eq('server_response')
  378. res = client_call.remote_read
  379. expect(res).to be_nil
  380. end
  381. it 'unmarshals the response using the unmarshal func' do
  382. call = make_test_call
  383. ActiveCall.client_invoke(call)
  384. unmarshal = proc { |x| 'unmarshalled:' + x }
  385. client_call = ActiveCall.new(call, @pass_through,
  386. unmarshal, deadline)
  387. # confirm the client receives the unmarshalled message
  388. msg = 'message is a string'
  389. client_call.remote_send(msg)
  390. server_call = expect_server_to_receive(msg)
  391. server_call.remote_send('server_response')
  392. expect(client_call.remote_read).to eq('unmarshalled:server_response')
  393. send_and_receive_close_and_status(
  394. call, inner_call_of_active_call(server_call))
  395. end
  396. end
  397. describe '#each_remote_read' do
  398. it 'creates an Enumerator' do
  399. call = make_test_call
  400. client_call = ActiveCall.new(call, @pass_through,
  401. @pass_through, deadline)
  402. expect(client_call.each_remote_read).to be_a(Enumerator)
  403. # finish the call
  404. client_call.cancel
  405. end
  406. it 'the returned enumerator can read n responses' do
  407. call = make_test_call
  408. ActiveCall.client_invoke(call)
  409. client_call = ActiveCall.new(call, @pass_through,
  410. @pass_through, deadline)
  411. msg = 'message is a string'
  412. reply = 'server_response'
  413. client_call.remote_send(msg)
  414. server_call = expect_server_to_receive(msg)
  415. e = client_call.each_remote_read
  416. n = 3 # arbitrary value > 1
  417. n.times do
  418. server_call.remote_send(reply)
  419. expect(e.next).to eq(reply)
  420. end
  421. send_and_receive_close_and_status(
  422. call, inner_call_of_active_call(server_call))
  423. end
  424. it 'the returns an enumerator that stops after an OK Status' do
  425. call = make_test_call
  426. ActiveCall.client_invoke(call)
  427. client_call = ActiveCall.new(call, @pass_through,
  428. @pass_through, deadline)
  429. msg = 'message is a string'
  430. reply = 'server_response'
  431. client_call.remote_send(msg)
  432. call.run_batch(CallOps::SEND_CLOSE_FROM_CLIENT => nil)
  433. server_call = expect_server_to_receive(msg)
  434. e = client_call.each_remote_read
  435. n = 3 # arbitrary value > 1
  436. n.times do
  437. server_call.remote_send(reply)
  438. expect(e.next).to eq(reply)
  439. end
  440. server_call.send_status(OK, 'OK', true)
  441. expect { e.next }.to raise_error(StopIteration)
  442. end
  443. end
  444. describe '#closing the call from the client' do
  445. it 'finishes ok if the server sends a status response' do
  446. call = make_test_call
  447. ActiveCall.client_invoke(call)
  448. client_call = ActiveCall.new(call, @pass_through,
  449. @pass_through, deadline)
  450. msg = 'message is a string'
  451. client_call.remote_send(msg)
  452. expect do
  453. call.run_batch(CallOps::SEND_CLOSE_FROM_CLIENT => nil)
  454. end.to_not raise_error
  455. server_call = expect_server_to_receive(msg)
  456. server_call.remote_send('server_response')
  457. expect(client_call.remote_read).to eq('server_response')
  458. server_call.send_status(OK, 'status code is OK')
  459. expect { client_call.receive_and_check_status }.to_not raise_error
  460. end
  461. it 'finishes ok if the server sends an early status response' do
  462. call = make_test_call
  463. ActiveCall.client_invoke(call)
  464. client_call = ActiveCall.new(call, @pass_through,
  465. @pass_through, deadline)
  466. msg = 'message is a string'
  467. client_call.remote_send(msg)
  468. server_call = expect_server_to_receive(msg)
  469. server_call.remote_send('server_response')
  470. server_call.send_status(OK, 'status code is OK')
  471. expect(client_call.remote_read).to eq('server_response')
  472. expect do
  473. call.run_batch(CallOps::SEND_CLOSE_FROM_CLIENT => nil)
  474. end.to_not raise_error
  475. expect { client_call.receive_and_check_status }.to_not raise_error
  476. end
  477. it 'finishes ok if SEND_CLOSE and RECV_STATUS has been sent' do
  478. call = make_test_call
  479. ActiveCall.client_invoke(call)
  480. client_call = ActiveCall.new(call, @pass_through,
  481. @pass_through, deadline)
  482. msg = 'message is a string'
  483. client_call.remote_send(msg)
  484. server_call = expect_server_to_receive(msg)
  485. server_call.remote_send('server_response')
  486. server_call.send_status(OK, 'status code is OK')
  487. expect(client_call.remote_read).to eq('server_response')
  488. expect do
  489. call.run_batch(
  490. CallOps::SEND_CLOSE_FROM_CLIENT => nil,
  491. CallOps::RECV_STATUS_ON_CLIENT => nil)
  492. end.to_not raise_error
  493. end
  494. end
  495. # Test sending of the initial metadata in #run_server_bidi
  496. # from the server handler both implicitly and explicitly.
  497. describe '#run_server_bidi metadata sending tests', run_server_bidi: true do
  498. before(:each) do
  499. @requests = ['first message', 'second message']
  500. @server_to_client_metadata = { 'test_key' => 'test_val' }
  501. @server_status = OK
  502. @client_call = make_test_call
  503. @client_call.run_batch(CallOps::SEND_INITIAL_METADATA => {})
  504. recvd_rpc = @server.request_call
  505. recvd_call = recvd_rpc.call
  506. @server_call = ActiveCall.new(
  507. recvd_call,
  508. @pass_through,
  509. @pass_through,
  510. deadline,
  511. metadata_received: true,
  512. started: false,
  513. metadata_to_send: @server_to_client_metadata)
  514. end
  515. after(:each) do
  516. # Send the requests and send a close so the server can send a status
  517. @requests.each do |message|
  518. @client_call.run_batch(CallOps::SEND_MESSAGE => message)
  519. end
  520. @client_call.run_batch(CallOps::SEND_CLOSE_FROM_CLIENT => nil)
  521. @server_thread.join
  522. # Expect that initial metadata was sent,
  523. # the requests were echoed, and a status was sent
  524. batch_result = @client_call.run_batch(
  525. CallOps::RECV_INITIAL_METADATA => nil)
  526. expect(batch_result.metadata).to eq(@server_to_client_metadata)
  527. @requests.each do |message|
  528. batch_result = @client_call.run_batch(
  529. CallOps::RECV_MESSAGE => nil)
  530. expect(batch_result.message).to eq(message)
  531. end
  532. batch_result = @client_call.run_batch(
  533. CallOps::RECV_STATUS_ON_CLIENT => nil)
  534. expect(batch_result.status.code).to eq(@server_status)
  535. end
  536. it 'sends the initial metadata implicitly if not already sent' do
  537. # Server handler that doesn't have access to a "call"
  538. # It echoes the requests
  539. fake_gen_each_reply_with_no_call_param = proc do |msgs|
  540. msgs
  541. end
  542. int_ctx = GRPC::InterceptionContext.new
  543. @server_thread = Thread.new do
  544. @server_call.run_server_bidi(
  545. fake_gen_each_reply_with_no_call_param, int_ctx)
  546. @server_call.send_status(@server_status)
  547. end
  548. end
  549. it 'sends the metadata when sent explicitly and not already sent' do
  550. # Fake server handler that has access to a "call" object and
  551. # uses it to explicitly update and send the initial metadata
  552. fake_gen_each_reply_with_call_param = proc do |msgs, call_param|
  553. call_param.merge_metadata_to_send(@server_to_client_metadata)
  554. call_param.send_initial_metadata
  555. msgs
  556. end
  557. int_ctx = GRPC::InterceptionContext.new
  558. @server_thread = Thread.new do
  559. @server_call.run_server_bidi(
  560. fake_gen_each_reply_with_call_param, int_ctx)
  561. @server_call.send_status(@server_status)
  562. end
  563. end
  564. end
  565. def expect_server_to_receive(sent_text, **kw)
  566. c = expect_server_to_be_invoked(**kw)
  567. expect(c.remote_read).to eq(sent_text)
  568. c
  569. end
  570. def expect_server_to_be_invoked(**kw)
  571. recvd_rpc = @server.request_call
  572. expect(recvd_rpc).to_not eq nil
  573. recvd_call = recvd_rpc.call
  574. recvd_call.run_batch(CallOps::SEND_INITIAL_METADATA => kw)
  575. ActiveCall.new(recvd_call, @pass_through, @pass_through, deadline,
  576. metadata_received: true, started: true)
  577. end
  578. def make_test_call
  579. @ch.create_call(nil, nil, '/method', nil, deadline)
  580. end
  581. def deadline
  582. Time.now + 2 # in 2 seconds; arbitrary
  583. end
  584. end