Class: PerfCheck::TestCase
- Inherits:
-
Object
- Object
- PerfCheck::TestCase
- Defined in:
- lib/perf_check/test_case.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#controller ⇒ Object
Returns the value of attribute controller.
-
#cookie ⇒ Object
Returns the value of attribute cookie.
-
#latencies ⇒ Object
Returns the value of attribute latencies.
-
#reference_latencies ⇒ Object
Returns the value of attribute reference_latencies.
-
#resource ⇒ Object
Returns the value of attribute resource.
-
#this_latencies ⇒ Object
Returns the value of attribute this_latencies.
Instance Method Summary collapse
- #eql?(test) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(route) ⇒ TestCase
constructor
A new instance of TestCase.
- #latency_difference ⇒ Object
- #latency_factor ⇒ Object
- #reference_latency ⇒ Object
- #run(server, count) ⇒ Object
- #this_latency ⇒ Object
Constructor Details
#initialize(route) ⇒ TestCase
Returns a new instance of TestCase.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/perf_check/test_case.rb', line 9 def initialize(route) params = Rails.application.routes.recognize_path(route) self.this_latencies = [] self.reference_latencies = [] self.latencies = this_latencies self.controller = params[:controller].split('/')[-1] self.action = params[:action] self.resource = route end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
5 6 7 |
# File 'lib/perf_check/test_case.rb', line 5 def action @action end |
#controller ⇒ Object
Returns the value of attribute controller.
5 6 7 |
# File 'lib/perf_check/test_case.rb', line 5 def controller @controller end |
#cookie ⇒ Object
Returns the value of attribute cookie.
6 7 8 |
# File 'lib/perf_check/test_case.rb', line 6 def @cookie end |
#latencies ⇒ Object
Returns the value of attribute latencies.
6 7 8 |
# File 'lib/perf_check/test_case.rb', line 6 def latencies @latencies end |
#reference_latencies ⇒ Object
Returns the value of attribute reference_latencies.
7 8 9 |
# File 'lib/perf_check/test_case.rb', line 7 def reference_latencies @reference_latencies end |
#resource ⇒ Object
Returns the value of attribute resource.
5 6 7 |
# File 'lib/perf_check/test_case.rb', line 5 def resource @resource end |
#this_latencies ⇒ Object
Returns the value of attribute this_latencies.
7 8 9 |
# File 'lib/perf_check/test_case.rb', line 7 def this_latencies @this_latencies end |
Instance Method Details
#eql?(test) ⇒ Boolean
65 66 67 |
# File 'lib/perf_check/test_case.rb', line 65 def eql?(test) resource == test.resource end |
#hash ⇒ Object
69 70 71 |
# File 'lib/perf_check/test_case.rb', line 69 def hash resource.hash end |
#latency_difference ⇒ Object
57 58 59 |
# File 'lib/perf_check/test_case.rb', line 57 def latency_difference this_latency - reference_latency end |
#latency_factor ⇒ Object
61 62 63 |
# File 'lib/perf_check/test_case.rb', line 61 def latency_factor reference_latency / this_latency end |
#reference_latency ⇒ Object
53 54 55 |
# File 'lib/perf_check/test_case.rb', line 53 def reference_latency reference_latencies.inject(0.0, :+) / reference_latencies.size end |
#run(server, count) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/perf_check/test_case.rb', line 21 def run(server, count) (count+1).times do |i| errors = 0 begin profile = server.profile do |http| http.get(resource, {'Cookie' => }) end rescue Server::ApplicationError => e File.open("public/perf_check_failed_request.html", 'w') do |error_dump| error_dump.write(e.body) end printf("\tRequest %2i: —— FAILURE (HTTP %s): %s\n", i, e.code, '/perf_check_failed_request.html') exit(1) end # Disregard initial request, since in dev. mode it includes # all the autoload overhead (?) next if i.zero? printf("\tRequest %2i: %.1fms\t%4dMB\t%s\n", i, profile.latency, server.mem, profile.profile_url) self.latencies << profile.latency end puts end |
#this_latency ⇒ Object
49 50 51 |
# File 'lib/perf_check/test_case.rb', line 49 def this_latency this_latencies.inject(0.0, :+) / this_latencies.size end |