performance_tester 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,4 @@
1
1
  # encoding: UTF-8
2
- require 'performance_tester/environment'
3
2
  require 'performance_tester/runner'
4
3
  require 'performance_tester/scenario'
5
4
  require 'performance_tester/version'
@@ -3,9 +3,10 @@ require 'csv'
3
3
 
4
4
  module PerformanceTester
5
5
  class CsvLogger
6
- attr_reader :outcome, :path
6
+ attr_reader :name, :outcome, :path
7
7
 
8
- def initialize(outcome, options = {})
8
+ def initialize(name, outcome, options = {})
9
+ @name = name
9
10
  @outcome = outcome
10
11
  @path = options.fetch(:path) { 'performance_test.csv' }
11
12
  end
@@ -21,6 +22,7 @@ module PerformanceTester
21
22
 
22
23
  def header_line
23
24
  [
25
+ 'Run name',
24
26
  'Run datetime',
25
27
  'Host alias',
26
28
  'Path',
@@ -31,6 +33,7 @@ module PerformanceTester
31
33
 
32
34
  def request_line(request)
33
35
  [
36
+ name,
34
37
  outcome.started_at,
35
38
  request.host_alias,
36
39
  request.path,
@@ -40,7 +43,7 @@ module PerformanceTester
40
43
  end
41
44
 
42
45
  def total_line
43
- [outcome.started_at, '', '', '', outcome.total_time_elapsed]
46
+ [name, outcome.started_at, '', '', '', outcome.total_time_elapsed]
44
47
  end
45
48
 
46
49
  def with_csv
@@ -2,13 +2,15 @@
2
2
 
3
3
  module PerformanceTester
4
4
  class PutsAggregateLogger
5
- attr_reader :outcome
5
+ attr_reader :name, :outcome
6
6
 
7
- def initialize(outcome)
7
+ def initialize(name, outcome)
8
+ @name = name
8
9
  @outcome = outcome
9
10
  end
10
11
 
11
12
  def log
13
+ puts "Test run: #{name}"
12
14
  puts "Success: #{outcome.success?}"
13
15
  puts "Number of requests: #{number_of_requests}"
14
16
  puts "Sum of request times: #{sprintf("%.02f", sum_of_times_of_all_requests)}"
@@ -1,6 +1,7 @@
1
1
  # encoding: UTF-8
2
2
  require 'capybara'
3
3
  require 'capybara/dsl'
4
+ require 'capybara/poltergeist'
4
5
  require 'performance_tester/outcome'
5
6
  require 'performance_tester/puts_aggregate_logger'
6
7
  require 'performance_tester/csv_logger'
@@ -8,61 +9,101 @@ require 'performance_tester/csv_logger'
8
9
  module PerformanceTester
9
10
  # Executes a scenario in an environment and creates outcomes
10
11
  class Runner
11
- include Capybara::DSL
12
+ attr_reader :options
12
13
 
13
- attr_reader :environment, :options
14
-
15
- def initialize(environment, options = {})
16
- @environment = environment
14
+ def initialize(options = {})
17
15
  @options = options
16
+ initialize_browser
18
17
  end
19
18
 
20
19
  def run(scenario)
21
20
  start = time_now
22
- begin
23
- instance_eval(&scenario)
24
- rescue => error
25
- end
21
+ context = build_context
22
+ context.execute(scenario)
26
23
  stop = time_now
27
24
  period = (start .. stop)
28
- outcome = create_outcome(period, error)
25
+ outcome = create_outcome(period, context)
29
26
  log_outcome(outcome)
30
27
  outcome
31
28
  end
32
29
 
33
- def create_outcome(period, error)
34
- network_traffic = page.driver.network_traffic
35
- outcome.new(network_traffic, period, hosts, error)
30
+ def initialize_browser
31
+ browser.run_server = false
32
+ browser.current_driver = :poltergeist
33
+ browser.register_driver :poltergeist do |app|
34
+ driver.new(app, :debug => false)
35
+ end
36
36
  end
37
37
 
38
- def outcome
39
- options.fetch(:outcome) { Outcome }
38
+ def create_outcome(period, context)
39
+ outcome.new(context.network_traffic, period, hosts, context.error)
40
40
  end
41
41
 
42
42
  def log_outcome(outcome)
43
43
  loggers.each do |logger|
44
- logger.new(outcome).log
44
+ logger.new(name, outcome).log
45
45
  end
46
46
  end
47
47
 
48
- def loggers
49
- options.fetch(:loggers) { [PutsAggregateLogger, CsvLogger] }
48
+ def build_context
49
+ Context.new(params, hosts)
50
50
  end
51
51
 
52
52
  def time_now
53
53
  clock.now
54
54
  end
55
55
 
56
+ def name
57
+ options.fetch(:name) { '' }
58
+ end
59
+
60
+ def params
61
+ options.fetch(:params) { {} }
62
+ end
63
+
64
+ def hosts
65
+ options.fetch(:hosts) { {} }
66
+ end
67
+
68
+ def outcome
69
+ options.fetch(:outcome) { Outcome }
70
+ end
71
+
72
+ def loggers
73
+ options.fetch(:loggers) { [PutsAggregateLogger, CsvLogger] }
74
+ end
75
+
56
76
  def clock
57
77
  options.fetch(:clock) { Time }
58
78
  end
59
79
 
60
- def env
61
- environment.options
80
+ def browser
81
+ options.fetch(:browser) { Capybara }
62
82
  end
63
83
 
64
- def hosts
65
- environment.hosts
84
+ def driver
85
+ options.fetch(:driver) { Capybara::Poltergeist::Driver }
86
+ end
87
+
88
+ class Context
89
+ include Capybara::DSL
90
+
91
+ attr_reader :params, :hosts, :error
92
+
93
+ def initialize(params, hosts)
94
+ @params = params
95
+ @hosts = hosts
96
+ end
97
+
98
+ def execute(scenario)
99
+ instance_eval(&scenario)
100
+ rescue => error
101
+ @error = error
102
+ end
103
+
104
+ def network_traffic
105
+ page.driver.network_traffic
106
+ end
66
107
  end
67
108
  end
68
109
  end
@@ -1,3 +1,3 @@
1
1
  module PerformanceTester
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
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.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-09 00:00:00.000000000 Z
12
+ date: 2012-10-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: poltergeist
@@ -41,7 +41,6 @@ files:
41
41
  - Rakefile
42
42
  - lib/performance_tester.rb
43
43
  - lib/performance_tester/csv_logger.rb
44
- - lib/performance_tester/environment.rb
45
44
  - lib/performance_tester/outcome.rb
46
45
  - lib/performance_tester/puts_aggregate_logger.rb
47
46
  - lib/performance_tester/runner.rb
@@ -1,31 +0,0 @@
1
- # encoding: UTF-8
2
- require "capybara"
3
- require "capybara/poltergeist"
4
-
5
- module PerformanceTester
6
- # Describe an execution environment - server, credentials, etc.
7
- class Environment
8
- attr_reader :options
9
-
10
- def initialize(options = {})
11
- @options = options
12
- browser.run_server = false
13
- browser.current_driver = :poltergeist
14
- browser.register_driver :poltergeist do |app|
15
- driver.new(app, :debug => false)
16
- end
17
- end
18
-
19
- def hosts
20
- options.fetch(:hosts) { {} }
21
- end
22
-
23
- def browser
24
- options.fetch(:browser) { Capybara }
25
- end
26
-
27
- def driver
28
- options.fetch(:driver) { Capybara::Poltergeist::Driver }
29
- end
30
- end
31
- end