class PingPongPlayer

a PingPongPlayer implements the ping pong bidi test.

Attributes

canceller_op[RW]
queue[RW]

Public Class Methods

new(msg_sizes) click to toggle source

reqs is the enumerator over the requests

# File src/ruby/pb/test/client.rb, line 186
def initialize(msg_sizes)
  @queue = Queue.new
  @msg_sizes = msg_sizes
  @canceller_op = nil  # used to cancel after the first response
end

Public Instance Methods

each_item() { |req| ... } click to toggle source
# File src/ruby/pb/test/client.rb, line 192
def each_item
  return enum_for(:each_item) unless block_given?
  req_cls, p_cls = StreamingOutputCallRequest, ResponseParameters  # short
  count = 0
  @msg_sizes.each do |m|
    req_size, resp_size = m
    req = req_cls.new(payload: Payload.new(body: nulls(req_size)),
                      response_type: :COMPRESSABLE,
                      response_parameters: [p_cls.new(size: resp_size)])
    yield req
    resp = @queue.pop
    assert('payload type is wrong') { :COMPRESSABLE == resp.payload.type }
    assert("payload body #{count} has the wrong length") do
      resp_size == resp.payload.body.length
    end
    p "OK: ping_pong #{count}"
    count += 1
    unless @canceller_op.nil?
      canceller_op.cancel
      break
    end
  end
end