Class: PerfCheck::TestCase

Inherits:
Object
  • Object
show all
Defined in:
lib/perf_check/test_case.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#actionObject

Returns the value of attribute action.



5
6
7
# File 'lib/perf_check/test_case.rb', line 5

def action
  @action
end

#controllerObject

Returns the value of attribute controller.



5
6
7
# File 'lib/perf_check/test_case.rb', line 5

def controller
  @controller
end

Returns the value of attribute cookie.



6
7
8
# File 'lib/perf_check/test_case.rb', line 6

def cookie
  @cookie
end

#latenciesObject

Returns the value of attribute latencies.



6
7
8
# File 'lib/perf_check/test_case.rb', line 6

def latencies
  @latencies
end

#reference_latenciesObject

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

#resourceObject

Returns the value of attribute resource.



5
6
7
# File 'lib/perf_check/test_case.rb', line 5

def resource
  @resource
end

#this_latenciesObject

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

Returns:

  • (Boolean)


65
66
67
# File 'lib/perf_check/test_case.rb', line 65

def eql?(test)
  resource == test.resource
end

#hashObject



69
70
71
# File 'lib/perf_check/test_case.rb', line 69

def hash
  resource.hash
end

#latency_differenceObject



57
58
59
# File 'lib/perf_check/test_case.rb', line 57

def latency_difference
  this_latency - reference_latency
end

#latency_factorObject



61
62
63
# File 'lib/perf_check/test_case.rb', line 61

def latency_factor
  reference_latency / this_latency
end

#reference_latencyObject



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' => 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_latencyObject



49
50
51
# File 'lib/perf_check/test_case.rb', line 49

def this_latency
  this_latencies.inject(0.0, :+) / this_latencies.size
end