Class: CelluloidBenchmark::Benchmark
- Inherits:
-
Object
- Object
- CelluloidBenchmark::Benchmark
- Defined in:
- lib/celluloid_benchmark/benchmark.rb
Overview
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.
Instance Attribute Summary collapse
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#response_codes ⇒ Object
readonly
Returns the value of attribute response_codes.
-
#response_times ⇒ Object
readonly
Returns the value of attribute response_times.
-
#threshold ⇒ Object
readonly
Returns the value of attribute threshold.
Instance Method Summary collapse
- #average_response_time ⇒ Object
-
#initialize(label, threshold, response_times, response_codes) ⇒ Benchmark
constructor
A new instance of Benchmark.
- #max_response_time ⇒ Object
- #min_response_time ⇒ Object
- #ok? ⇒ Boolean
-
#response_codes_ok? ⇒ Boolean
200 OK is …
-
#response_times_ok? ⇒ Boolean
Consider average response time.
- #responses ⇒ Object
Constructor Details
#initialize(label, threshold, response_times, response_codes) ⇒ Benchmark
Returns a new instance of Benchmark.
14 15 16 17 18 19 20 21 22 23 |
# 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 |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
9 10 11 |
# File 'lib/celluloid_benchmark/benchmark.rb', line 9 def label @label end |
#response_codes ⇒ Object (readonly)
Returns the value of attribute response_codes.
10 11 12 |
# File 'lib/celluloid_benchmark/benchmark.rb', line 10 def response_codes @response_codes end |
#response_times ⇒ Object (readonly)
Returns the value of attribute response_times.
11 12 13 |
# File 'lib/celluloid_benchmark/benchmark.rb', line 11 def response_times @response_times end |
#threshold ⇒ Object (readonly)
Returns the value of attribute threshold.
12 13 14 |
# File 'lib/celluloid_benchmark/benchmark.rb', line 12 def threshold @threshold end |
Instance Method Details
#average_response_time ⇒ Object
43 44 45 |
# File 'lib/celluloid_benchmark/benchmark.rb', line 43 def average_response_time response_times.reduce(:+) / responses end |
#max_response_time ⇒ Object
51 52 53 |
# File 'lib/celluloid_benchmark/benchmark.rb', line 51 def max_response_time response_times.max end |
#min_response_time ⇒ Object
47 48 49 |
# File 'lib/celluloid_benchmark/benchmark.rb', line 47 def min_response_time response_times.min end |
#ok? ⇒ Boolean
25 26 27 |
# File 'lib/celluloid_benchmark/benchmark.rb', line 25 def ok? response_times_ok? && response_codes_ok? end |
#response_codes_ok? ⇒ Boolean
200 OK is … OK, as is a redirect, not modified, or auth required
39 40 41 |
# File 'lib/celluloid_benchmark/benchmark.rb', line 39 def response_codes_ok? response_codes.all? { |code| code == 200 || code == 201 || code == 302 || code == 304 || code == 401 } end |
#response_times_ok? ⇒ Boolean
Consider average response time. Do not check for outlying slow times.
30 31 32 33 34 35 36 |
# File 'lib/celluloid_benchmark/benchmark.rb', line 30 def response_times_ok? if response_times.size > 0 average_response_time <= threshold else true end end |
#responses ⇒ Object
55 56 57 |
# File 'lib/celluloid_benchmark/benchmark.rb', line 55 def responses response_times.size end |