performance_tester 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in performance_tester.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Donald Ball
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # PerformanceTester
2
+
3
+ PerformanceTester is a library that provides a system for capturing performance
4
+ data for web applications using capybara poltergeist.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module PerformanceTester
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,199 @@
1
+ # encoding: UTF-8
2
+ require "capybara"
3
+ require "capybara/dsl"
4
+ require "capybara/poltergeist"
5
+ require "uri"
6
+
7
+ module PerformanceTester
8
+ # Describe an execution environment - server, credentials, etc.
9
+ class Environment
10
+ attr_reader :options
11
+
12
+ def initialize(options = {})
13
+ @options = options
14
+ browser.run_server = false
15
+ browser.current_driver = :poltergeist
16
+ browser.register_driver :poltergeist do |app|
17
+ driver.new(app, :debug => false)
18
+ end
19
+ end
20
+
21
+ def hosts
22
+ options.fetch(:hosts) { {} }
23
+ end
24
+
25
+ def browser
26
+ options.fetch(:browser) { Capybara }
27
+ end
28
+
29
+ def driver
30
+ options.fetch(:driver) { Capybara::Poltergeist::Driver }
31
+ end
32
+ end
33
+
34
+ # Describes a sequence of browser actions
35
+ class Scenario
36
+ def initialize(&block)
37
+ @block = block
38
+ end
39
+
40
+ def to_proc
41
+ @block
42
+ end
43
+ end
44
+
45
+ # Executes a scenario in an environment and creates outcomes
46
+ class Runner
47
+ include Capybara::DSL
48
+
49
+ attr_reader :environment, :options
50
+
51
+ def initialize(environment, options = {})
52
+ @environment = environment
53
+ @options = options
54
+ end
55
+
56
+ def run(scenario)
57
+ start = time_now
58
+ begin
59
+ instance_eval(&scenario)
60
+ rescue => error
61
+ end
62
+ stop = time_now
63
+ outcome = create_outcome(start, stop, error)
64
+ log_outcome(outcome)
65
+ outcome
66
+ end
67
+
68
+ def create_outcome(start, stop, error)
69
+ network_traffic = page.driver.network_traffic
70
+ total_time_elapsed = stop - start
71
+ outcome.new(network_traffic, total_time_elapsed, hosts, error)
72
+ end
73
+
74
+ def outcome
75
+ options.fetch(:outcome) { Outcome }
76
+ end
77
+
78
+ def log_outcome(outcome)
79
+ logger.new(outcome).log
80
+ end
81
+
82
+ def logger
83
+ options.fetch(:logger) { PutsAggregateLogger }
84
+ end
85
+
86
+ def time_now
87
+ clock.now
88
+ end
89
+
90
+ def clock
91
+ options.fetch(:clock) { Time }
92
+ end
93
+
94
+ def env
95
+ environment.options
96
+ end
97
+
98
+ def hosts
99
+ environment.hosts
100
+ end
101
+ end
102
+
103
+ class PutsAggregateLogger
104
+ attr_reader :outcome
105
+
106
+ def initialize(outcome)
107
+ @outcome = outcome
108
+ end
109
+
110
+ def log
111
+ puts "Number of requests: #{number_of_requests}"
112
+ puts "Sum of request times: #{sum_of_times_of_all_requests}"
113
+ puts "Total time elapsed: #{total_time_elapsed}"
114
+ end
115
+
116
+ def total_time_elapsed
117
+ outcome.total_time_elapsed
118
+ end
119
+
120
+ def number_of_requests
121
+ outcome.requests.length
122
+ end
123
+
124
+ def sum_of_times_of_all_requests
125
+ outcome.requests.map(&:time_elapsed).reduce(&:+)
126
+ end
127
+ end
128
+
129
+ # Documents the outcome of a scenario
130
+ class Outcome
131
+ attr_reader :requests, :error, :total_time_elapsed
132
+
133
+ def initialize(network_traffic, total_time_elapsed, hosts, error = false)
134
+ @requests = network_traffic.map { |request| Request.new(request, hosts) }
135
+ @total_time_elapsed = total_time_elapsed
136
+ @error = error
137
+ end
138
+
139
+ def success?
140
+ !error
141
+ end
142
+
143
+ def to_s
144
+ error ? error.to_s : requests.map(&:to_s).inspect
145
+ end
146
+
147
+ class Request
148
+ attr_reader :url, :request_time, :response, :host_aliases
149
+
150
+ def initialize(request, hosts)
151
+ @url = URI.parse(request.url)
152
+ @request_time = request.time
153
+ @response = Response.new(request.response_parts)
154
+ @host_aliases = hosts.invert
155
+ end
156
+
157
+ def host_alias
158
+ host_aliases.fetch(host) { host }
159
+ end
160
+
161
+ def host
162
+ url.host
163
+ end
164
+
165
+ def path
166
+ url.path
167
+ end
168
+
169
+ def time_elapsed
170
+ response_time - request_time
171
+ end
172
+
173
+ def to_s
174
+ [host_alias, path, status, content_type, time_elapsed].inspect
175
+ end
176
+
177
+ def response_time
178
+ response.time
179
+ end
180
+
181
+ def status
182
+ response.status
183
+ end
184
+
185
+ def content_type
186
+ response.content_type
187
+ end
188
+ end
189
+
190
+ class Response < SimpleDelegator
191
+ def initialize(response_parts)
192
+ if !response_parts || response_parts.empty?
193
+ raise ArgumentError, "Response parts are invalid"
194
+ end
195
+ super(response_parts.last)
196
+ end
197
+ end
198
+ end
199
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'performance_tester/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "performance_tester"
8
+ gem.version = PerformanceTester::VERSION
9
+ gem.authors = ["Donald Ball"]
10
+ gem.email = ["donald.ball@gmail.com"]
11
+ gem.description = %q{A performance test harness for web applications.}
12
+ gem.summary = %q{A performance test harness for web applications that uses capybara poltergeist to capture http performance metrics.}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "poltergeist"
21
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: performance_tester
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Donald Ball
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: poltergeist
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: A performance test harness for web applications.
31
+ email:
32
+ - donald.ball@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - lib/performance_tester.rb
43
+ - lib/performance_tester/version.rb
44
+ - performance_tester.gemspec
45
+ homepage: ''
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.24
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: A performance test harness for web applications that uses capybara poltergeist
69
+ to capture http performance metrics.
70
+ test_files: []
71
+ has_rdoc: