Sha256: 71453ec1129485dc70042fbc1ebce9c3500c0b161869b7065374a031c8d56150

Contents?: true

Size: 1.02 KB

Versions: 18

Compression:

Stored size: 1.02 KB

Contents

# -*- coding: utf-8 -*-

require "timeout"

module Bunny
  # Unit, integration and stress testing toolkit
  class TestKit
    class << self

      def poll_while(timeout = 60, &probe)
        Timeout.timeout(timeout) {
          sleep 0.1 while probe.call
        }
      end
      def poll_until(timeout = 60, &probe)
        Timeout.timeout(timeout) {
          sleep 0.1 until probe.call
        }
      end

      # @return [Integer] Random integer in the range of [a, b]
      # @api private
      def random_in_range(a, b)
        Range.new(a, b).to_a.sample
      end

      # @param  [Integer] a Lower bound of message size, in KB
      # @param  [Integer] b Upper bound of message size, in KB
      # @param  [Integer] i Random number to use in message generation
      # @return [String] Message payload of length in the given range, with non-ASCII characters
      # @api public
      def message_in_kb(a, b, i)
        s = "Ю#{i}"
        n = random_in_range(a, b) / s.bytesize

        s * n * 1024
      end

    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
bunny-2.23.0 lib/bunny/test_kit.rb
bunny-2.22.0 lib/bunny/test_kit.rb
bunny-2.21.0 lib/bunny/test_kit.rb
bunny-2.20.3 lib/bunny/test_kit.rb
bunny-2.20.2 lib/bunny/test_kit.rb
bunny-2.20.1 lib/bunny/test_kit.rb
bunny-2.20.0 lib/bunny/test_kit.rb
garaio_bunny-2.19.2 lib/bunny/test_kit.rb
garaio_bunny-2.19.1 lib/bunny/test_kit.rb
bunny-2.19.0 lib/bunny/test_kit.rb
bunny-2.18.0 lib/bunny/test_kit.rb
bunny-2.17.0 lib/bunny/test_kit.rb
bunny-2.16.1 lib/bunny/test_kit.rb
bunny-2.15.0 lib/bunny/test_kit.rb
bunny-2.14.4 lib/bunny/test_kit.rb
bunny-2.14.3 lib/bunny/test_kit.rb
bunny-2.14.2 lib/bunny/test_kit.rb
bunny-2.14.1 lib/bunny/test_kit.rb