class CelluloidBenchmark::Benchmark

List of responses for a benchmark defined in test scenario.

For example, requests for /offers/1001, /offers/1001-burgerville-deal, /offers/2200 might all be grouped under the “offer_show” label

Call ok? to check that responses were OK and fast enough.

Attributes

label[R]
response_codes[R]
response_times[R]
threshold[R]

Public Class Methods

new(label, threshold, response_times, response_codes) click to toggle source
# File lib/celluloid_benchmark/benchmark.rb, line 14
def initialize(label, threshold, response_times, response_codes)
  raise(ArgumentError, "label cannot be blank") if label.nil? || label == ""

  @label = label
  @response_times = response_times || []
  @threshold = threshold || 3.0
  @response_codes = response_codes || []

  raise(ArgumentError, "threshold must be greater than zero") if self.threshold <= 0
end

Public Instance Methods

average_response_time() click to toggle source
# File lib/celluloid_benchmark/benchmark.rb, line 47
def average_response_time
  response_times.reduce(:+) / responses
end
error?() click to toggle source
# File lib/celluloid_benchmark/benchmark.rb, line 29
def error?
  !response_codes_ok?
end
max_response_time() click to toggle source
# File lib/celluloid_benchmark/benchmark.rb, line 55
def max_response_time
  response_times.max
end
min_response_time() click to toggle source
# File lib/celluloid_benchmark/benchmark.rb, line 51
def min_response_time
  response_times.min
end
ok?() click to toggle source
# File lib/celluloid_benchmark/benchmark.rb, line 25
def ok?
  response_times_ok? && response_codes_ok?
end
response_codes_ok?() click to toggle source

200 OK is … OK, as is a redirect, not modified, or auth required

# File lib/celluloid_benchmark/benchmark.rb, line 43
def response_codes_ok?
  response_codes.all? { |code| code == 200 || code == 201 || code == 302 || code == 304 || code == 401 }
end
response_times_ok?() click to toggle source

Consider average response time. Do not check for outlying slow times.

# File lib/celluloid_benchmark/benchmark.rb, line 34
def response_times_ok?
  if response_times.size > 0
    average_response_time <= threshold
  else
    true
  end
end
responses() click to toggle source
# File lib/celluloid_benchmark/benchmark.rb, line 59
def responses
  response_times.size
end