performance_tester 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,3 +2,4 @@
2
2
  require 'performance_tester/runner'
3
3
  require 'performance_tester/scenario'
4
4
  require 'performance_tester/version'
5
+ require 'performance_tester/logger'
@@ -2,13 +2,9 @@
2
2
  require 'csv'
3
3
 
4
4
  module PerformanceTester
5
- class CsvLogger
6
- attr_reader :name, :outcome, :path
7
-
8
- def initialize(name, outcome, options = {})
9
- @name = name
10
- @outcome = outcome
11
- @path = options.fetch(:path) { 'performance_test.csv' }
5
+ class CsvLogger < Logger
6
+ def path
7
+ options.fetch(:path) { 'performance_test.csv' }
12
8
  end
13
9
 
14
10
  def log
@@ -20,6 +16,15 @@ module PerformanceTester
20
16
  end
21
17
  end
22
18
 
19
+ def with_csv
20
+ append = File.exists?(path)
21
+ flags = append ? 'ab' : 'wb'
22
+ CSV.open(path, flags) do |csv|
23
+ csv << header_line unless append
24
+ yield csv
25
+ end
26
+ end
27
+
23
28
  def header_line
24
29
  [
25
30
  'Run name',
@@ -33,7 +38,7 @@ module PerformanceTester
33
38
 
34
39
  def request_line(request)
35
40
  [
36
- name,
41
+ run_name,
37
42
  outcome.started_at,
38
43
  request.host_alias,
39
44
  request.path,
@@ -43,16 +48,7 @@ module PerformanceTester
43
48
  end
44
49
 
45
50
  def total_line
46
- [name, outcome.started_at, '', '', '', outcome.total_time_elapsed]
47
- end
48
-
49
- def with_csv
50
- append = File.exists?(path)
51
- flags = append ? 'ab' : 'wb'
52
- CSV.open(path, flags) do |csv|
53
- csv << header_line unless append
54
- yield csv
55
- end
51
+ [run_name, outcome.started_at, '', '', '', outcome.total_time_elapsed]
56
52
  end
57
53
  end
58
54
  end
@@ -0,0 +1,39 @@
1
+ # encoding: UTF-8
2
+
3
+ module PerformanceTester
4
+ module_function
5
+
6
+ def loggers
7
+ @loggers ||= {}
8
+ end
9
+
10
+ def register_logger(name, klass)
11
+ loggers[name] = klass
12
+ end
13
+
14
+ def registered_logger(name)
15
+ loggers.fetch(name)
16
+ rescue KeyError
17
+ raise ArgumentError, "Unregistered logger: #{name}"
18
+ end
19
+
20
+ class Logger
21
+ attr_reader :run_name, :outcome, :options
22
+
23
+ def initialize(run_name, outcome, options = {})
24
+ @run_name = run_name
25
+ @outcome = outcome
26
+ @options = options
27
+ end
28
+
29
+ def log
30
+ end
31
+ end
32
+ end
33
+
34
+ require 'performance_tester/puts_aggregate_logger'
35
+ require 'performance_tester/csv_logger'
36
+
37
+ PerformanceTester.register_logger(
38
+ :summary, PerformanceTester::PutsAggregateLogger)
39
+ PerformanceTester.register_logger(:csv, PerformanceTester::CsvLogger)
@@ -51,7 +51,7 @@ module PerformanceTester
51
51
  end
52
52
 
53
53
  def path
54
- url.path
54
+ url.request_uri
55
55
  end
56
56
 
57
57
  def time_elapsed
@@ -1,16 +1,9 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module PerformanceTester
4
- class PutsAggregateLogger
5
- attr_reader :name, :outcome
6
-
7
- def initialize(name, outcome)
8
- @name = name
9
- @outcome = outcome
10
- end
11
-
4
+ class PutsAggregateLogger < Logger
12
5
  def log
13
- puts "Test run: #{name}"
6
+ puts "Test run: #{run_name}"
14
7
  puts "Success: #{outcome.success?}"
15
8
  puts "Number of requests: #{number_of_requests}"
16
9
  puts "Sum of request times: #{sprintf("%.02f", sum_of_times_of_all_requests)}"
@@ -3,11 +3,9 @@ require 'capybara'
3
3
  require 'capybara/dsl'
4
4
  require 'capybara/poltergeist'
5
5
  require 'performance_tester/outcome'
6
- require 'performance_tester/puts_aggregate_logger'
7
- require 'performance_tester/csv_logger'
8
6
 
9
7
  module PerformanceTester
10
- # Executes a scenario in an environment and creates outcomes
8
+ # Executes a scenario, then creates and logs outcomes
11
9
  class Runner
12
10
  attr_reader :options
13
11
 
@@ -17,8 +15,8 @@ module PerformanceTester
17
15
  end
18
16
 
19
17
  def run(scenario)
20
- start = time_now
21
18
  context = build_context
19
+ start = time_now
22
20
  context.execute(scenario)
23
21
  stop = time_now
24
22
  period = (start .. stop)
@@ -40,8 +38,9 @@ module PerformanceTester
40
38
  end
41
39
 
42
40
  def log_outcome(outcome)
43
- loggers.each do |logger|
44
- logger.new(name, outcome).log
41
+ loggers.each do |logger_name, logger_options|
42
+ logger = PerformanceTester.registered_logger(logger_name)
43
+ logger.new(run_name, outcome, logger_options).log
45
44
  end
46
45
  end
47
46
 
@@ -53,7 +52,7 @@ module PerformanceTester
53
52
  clock.now
54
53
  end
55
54
 
56
- def name
55
+ def run_name
57
56
  options.fetch(:name) { '' }
58
57
  end
59
58
 
@@ -65,12 +64,12 @@ module PerformanceTester
65
64
  options.fetch(:hosts) { {} }
66
65
  end
67
66
 
68
- def outcome
69
- options.fetch(:outcome) { Outcome }
67
+ def loggers
68
+ options.fetch(:loggers) { {} }
70
69
  end
71
70
 
72
- def loggers
73
- options.fetch(:loggers) { [PutsAggregateLogger, CsvLogger] }
71
+ def outcome
72
+ options.fetch(:outcome) { Outcome }
74
73
  end
75
74
 
76
75
  def clock
@@ -1,3 +1,3 @@
1
1
  module PerformanceTester
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: performance_tester
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -41,6 +41,7 @@ files:
41
41
  - Rakefile
42
42
  - lib/performance_tester.rb
43
43
  - lib/performance_tester/csv_logger.rb
44
+ - lib/performance_tester/logger.rb
44
45
  - lib/performance_tester/outcome.rb
45
46
  - lib/performance_tester/puts_aggregate_logger.rb
46
47
  - lib/performance_tester/runner.rb