Skip to content
Snippets Groups Projects
Commit b5bcca44 authored by Tim Emiola's avatar Tim Emiola
Browse files

Adds interop cancellation tests

parent a10a8432
No related branches found
No related tags found
No related merge requests found
...@@ -136,12 +136,14 @@ class PingPongPlayer ...@@ -136,12 +136,14 @@ class PingPongPlayer
include Grpc::Testing::PayloadType include Grpc::Testing::PayloadType
attr_accessor :assertions # required by Minitest::Assertions attr_accessor :assertions # required by Minitest::Assertions
attr_accessor :queue attr_accessor :queue
attr_accessor :canceller_op
# reqs is the enumerator over the requests # reqs is the enumerator over the requests
def initialize(msg_sizes) def initialize(msg_sizes)
@queue = Queue.new @queue = Queue.new
@msg_sizes = msg_sizes @msg_sizes = msg_sizes
@assertions = 0 # required by Minitest::Assertions @assertions = 0 # required by Minitest::Assertions
@canceller_op = nil # used to cancel after the first response
end end
def each_item def each_item
...@@ -155,12 +157,15 @@ class PingPongPlayer ...@@ -155,12 +157,15 @@ class PingPongPlayer
response_parameters: [p_cls.new(size: resp_size)]) response_parameters: [p_cls.new(size: resp_size)])
yield req yield req
resp = @queue.pop resp = @queue.pop
assert_equal(:COMPRESSABLE, resp.payload.type, assert_equal(:COMPRESSABLE, resp.payload.type, 'payload type is wrong')
'payload type is wrong')
assert_equal(resp_size, resp.payload.body.length, assert_equal(resp_size, resp.payload.body.length,
'payload body #{i} has the wrong length') "payload body #{count} has the wrong length")
p "OK: ping_pong #{count}" p "OK: ping_pong #{count}"
count += 1 count += 1
unless @canceller_op.nil?
canceller_op.cancel
break
end
end end
end end
end end
...@@ -260,6 +265,27 @@ class NamedTests ...@@ -260,6 +265,27 @@ class NamedTests
p 'OK: ping_pong' p 'OK: ping_pong'
end end
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
assert_raises(GRPC::Cancelled) { op.execute }
p 'OK: cancel_after_begin'
end
def cancel_after_first
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
assert_raises(GRPC::Cancelled) { op.execute.each { |r| ppp.queue.push(r) } }
p 'OK: cancel_after_first'
end
def all def all
all_methods = NamedTests.instance_methods(false).map(&:to_s) all_methods = NamedTests.instance_methods(false).map(&:to_s)
all_methods.each do |m| all_methods.each do |m|
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment