diff options
author | Tim Emiola <temiola@google.com> | 2015-04-15 15:26:05 -0700 |
---|---|---|
committer | Tim Emiola <temiola@google.com> | 2015-04-15 17:55:14 -0700 |
commit | b5bcca44df242f7c914e7cc73a67a981f135d3ea (patch) | |
tree | 2586cb5a7a7aeb161f4b4d44413d195414eb890b /src/ruby | |
parent | a10a8432f3a9b05dc3dd2ff4d3cabf9da4781cd7 (diff) |
Adds interop cancellation tests
Diffstat (limited to 'src/ruby')
-rwxr-xr-x | src/ruby/bin/interop/interop_client.rb | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/src/ruby/bin/interop/interop_client.rb b/src/ruby/bin/interop/interop_client.rb index af7a1d5b15..6f1fe2614f 100755 --- a/src/ruby/bin/interop/interop_client.rb +++ b/src/ruby/bin/interop/interop_client.rb @@ -136,12 +136,14 @@ class PingPongPlayer include Grpc::Testing::PayloadType attr_accessor :assertions # required by Minitest::Assertions attr_accessor :queue + attr_accessor :canceller_op # reqs is the enumerator over the requests def initialize(msg_sizes) @queue = Queue.new @msg_sizes = msg_sizes @assertions = 0 # required by Minitest::Assertions + @canceller_op = nil # used to cancel after the first response end def each_item @@ -155,12 +157,15 @@ class PingPongPlayer response_parameters: [p_cls.new(size: resp_size)]) yield req resp = @queue.pop - assert_equal(:COMPRESSABLE, resp.payload.type, - 'payload type is wrong') + assert_equal(:COMPRESSABLE, resp.payload.type, 'payload type is wrong') 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}" count += 1 + unless @canceller_op.nil? + canceller_op.cancel + break + end end end end @@ -260,6 +265,27 @@ class NamedTests p 'OK: ping_pong' 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 all_methods = NamedTests.instance_methods(false).map(&:to_s) all_methods.each do |m| |