blitz 0.1.5 → 0.1.6
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/blitz.gemspec +2 -2
- data/lib/blitz.rb +2 -2
- data/lib/blitz/client.rb +1 -1
- data/lib/blitz/command.rb +14 -8
- data/lib/blitz/command/api.rb +1 -1
- data/lib/blitz/command/couch.rb +1 -1
- data/lib/blitz/command/curl.rb +3 -3
- data/lib/blitz/command/help.rb +1 -1
- data/lib/blitz/curl/error.rb +22 -3
- data/lib/blitz/curl/rush.rb +63 -11
- data/lib/blitz/curl/sprint.rb +58 -8
- data/lib/blitz/helper.rb +1 -1
- metadata +4 -4
data/blitz.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{blitz}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["pcapr"]
|
12
|
-
s.date = %q{2011-04-
|
12
|
+
s.date = %q{2011-04-20}
|
13
13
|
s.default_executable = %q{blitz}
|
14
14
|
s.description = %q{Make load and performance testing a fun sport}
|
15
15
|
s.email = %q{kowsik@gmail.com}
|
data/lib/blitz.rb
CHANGED
data/lib/blitz/client.rb
CHANGED
data/lib/blitz/command.rb
CHANGED
@@ -3,23 +3,29 @@ require 'test/unit/assertions'
|
|
3
3
|
# The default template string contains what was sent and received. Strip
|
4
4
|
# these out since we don't need them
|
5
5
|
unless RUBY_VERSION =~ /^1.9/
|
6
|
-
|
7
|
-
|
6
|
+
module Test # :nodoc:
|
7
|
+
module Unit # :nodoc:
|
8
|
+
module Assertions # :nodoc:
|
9
|
+
class AssertionMessage # :nodoc:
|
10
|
+
alias :old_template :template
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
def template
|
13
|
+
@template_string = ''
|
14
|
+
@parameters = []
|
15
|
+
old_template
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
13
19
|
end
|
14
20
|
end
|
15
21
|
else
|
16
|
-
module ::Test::Unit
|
22
|
+
module ::Test::Unit # :nodoc:
|
17
23
|
AssertionFailedError = MiniTest::Assertion
|
18
24
|
end
|
19
25
|
end
|
20
26
|
|
21
27
|
class Blitz
|
22
|
-
class Command
|
28
|
+
class Command # :nodoc:
|
23
29
|
include Test::Unit::Assertions
|
24
30
|
include Helper
|
25
31
|
end
|
data/lib/blitz/command/api.rb
CHANGED
data/lib/blitz/command/couch.rb
CHANGED
data/lib/blitz/command/curl.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Blitz
|
2
2
|
class Command
|
3
|
-
class Curl < Command
|
3
|
+
class Curl < Command # :nodoc:
|
4
4
|
def cmd_help argv
|
5
5
|
help
|
6
6
|
end
|
@@ -42,7 +42,7 @@ class Curl < Command
|
|
42
42
|
|
43
43
|
def sprint args
|
44
44
|
begin
|
45
|
-
job = ::Blitz::Curl::Sprint.
|
45
|
+
job = ::Blitz::Curl::Sprint.queue args
|
46
46
|
result = job.result
|
47
47
|
print_sprint_result args, result
|
48
48
|
rescue ::Blitz::Curl::Error::Authorize => e
|
@@ -106,7 +106,7 @@ class Curl < Command
|
|
106
106
|
[ 'INT', 'STOP', 'HUP' ].each do |s|
|
107
107
|
trap(s) { continue = false }
|
108
108
|
end
|
109
|
-
job = ::Blitz::Curl::Rush.
|
109
|
+
job = ::Blitz::Curl::Rush.queue args
|
110
110
|
msg "rushing from #{job.region}..."
|
111
111
|
job.result do |result|
|
112
112
|
print_rush_result result
|
data/lib/blitz/command/help.rb
CHANGED
data/lib/blitz/curl/error.rb
CHANGED
@@ -1,12 +1,23 @@
|
|
1
1
|
class Blitz
|
2
2
|
module Curl
|
3
|
-
class Error < StandardError
|
3
|
+
class Error < StandardError # :nodoc:
|
4
4
|
def initialize json={}
|
5
5
|
super json['reason'] || "Hmmm, something went wrong. Try again in a little bit?"
|
6
6
|
end
|
7
7
|
|
8
|
+
# This exception is raised when you haven't authorized a rush against your app
|
8
9
|
class Authorize < Error
|
9
|
-
|
10
|
+
# The scheme used in the rush (http or httpss)
|
11
|
+
attr_reader :scheme
|
12
|
+
|
13
|
+
# The host in the URL
|
14
|
+
attr_reader :host
|
15
|
+
|
16
|
+
# The port (if specified) in the URL
|
17
|
+
attr_reader :port
|
18
|
+
|
19
|
+
# The unique ID to use a URL path in your app for authorization to succeed
|
20
|
+
attr_reader :uuid
|
10
21
|
|
11
22
|
def initialize json
|
12
23
|
@scheme = json['scheme']
|
@@ -17,27 +28,35 @@ class Error < StandardError
|
|
17
28
|
end
|
18
29
|
end
|
19
30
|
|
31
|
+
# The base class for all exceptions thrown by the distributed scale engines
|
20
32
|
class Region < Error
|
33
|
+
# The region from which the test was run
|
21
34
|
attr_reader :region
|
22
35
|
|
23
|
-
def initialize json
|
36
|
+
def initialize json # :nodoc:
|
24
37
|
@region = json['region']
|
25
38
|
super
|
26
39
|
end
|
27
40
|
end
|
28
41
|
|
42
|
+
# This exception is raised when the DNS resolution fails
|
29
43
|
class DNS < Region
|
30
44
|
end
|
31
45
|
|
46
|
+
# This exception is raised when the connection to your app fails
|
32
47
|
class Connect < Region
|
33
48
|
end
|
34
49
|
|
50
|
+
# This exception is raised when the connection or the response times out
|
35
51
|
class Timeout < Region
|
36
52
|
end
|
37
53
|
|
54
|
+
# This exception is raised when the arguments to sprint or rush is invalid
|
38
55
|
class Parse < Region
|
39
56
|
end
|
40
57
|
|
58
|
+
# This exception is raised when you have an explicit status code check and
|
59
|
+
# the assertion fails
|
41
60
|
class Status < Region
|
42
61
|
end
|
43
62
|
end
|
data/lib/blitz/curl/rush.rb
CHANGED
@@ -1,18 +1,40 @@
|
|
1
1
|
class Blitz
|
2
|
-
module Curl
|
2
|
+
module Curl # :nodoc:
|
3
|
+
# Use this to run a rush (a load test) against your app. The return values
|
4
|
+
# include the entire timeline containing the average duration, the concurrency,
|
5
|
+
# the bytes sent/received, etc.
|
3
6
|
class Rush
|
7
|
+
# Snapshot of a rush at time[i] containing information about hits, errors
|
8
|
+
# timeouts, etc.
|
4
9
|
class Point
|
10
|
+
# The timestamp of this snapshot
|
5
11
|
attr_reader :timestamp
|
12
|
+
|
13
|
+
# The average response time at this time
|
6
14
|
attr_reader :duration
|
15
|
+
|
16
|
+
# The total number of hits that were generated
|
7
17
|
attr_reader :total
|
18
|
+
|
19
|
+
# The number of successful hits
|
8
20
|
attr_reader :hits
|
21
|
+
|
22
|
+
# The number of errors
|
9
23
|
attr_reader :errors
|
24
|
+
|
25
|
+
# The number of timeouts
|
10
26
|
attr_reader :timeouts
|
27
|
+
|
28
|
+
# The concurrency level at this time
|
11
29
|
attr_reader :volume
|
30
|
+
|
31
|
+
# The total number of bytes sent
|
12
32
|
attr_reader :txbytes
|
33
|
+
|
34
|
+
# The total number of bytes received
|
13
35
|
attr_reader :rxbytes
|
14
36
|
|
15
|
-
def initialize json
|
37
|
+
def initialize json # :nodoc:
|
16
38
|
@timestamp = json['timestamp']
|
17
39
|
@duration = json['duration']
|
18
40
|
@total = json['total']
|
@@ -25,19 +47,49 @@ class Rush
|
|
25
47
|
end
|
26
48
|
end
|
27
49
|
|
50
|
+
# Represents the results returned by the rush. Contains the entire timeline
|
51
|
+
# of snapshot values from the rush as well as the region from which the
|
52
|
+
# rush was executed.
|
28
53
|
class Result
|
54
|
+
# The region from which the rush was executed
|
29
55
|
attr_reader :region
|
56
|
+
|
57
|
+
# The timeline of the rush containing various statistics.
|
30
58
|
attr_reader :timeline
|
31
59
|
|
32
|
-
def initialize json
|
60
|
+
def initialize json # :nodoc:
|
33
61
|
result = json['result']
|
34
62
|
@region = result['region']
|
35
63
|
@timeline = result['timeline'].map { |p| Point.new p }
|
36
64
|
end
|
37
65
|
end
|
38
66
|
|
39
|
-
|
40
|
-
|
67
|
+
# Primary method for running a rush. The args is very similar to what
|
68
|
+
# the Sprint.execute method accepts, except this should also contain
|
69
|
+
# the pattern. If a block is given, it's invoked periodically with the
|
70
|
+
# partial results of the run (to report progress, perhaps)
|
71
|
+
#
|
72
|
+
# args = {
|
73
|
+
# :url => 'http://www.mudynamics.com',
|
74
|
+
# :headers => [ 'X-API-Token: foo' ],
|
75
|
+
# :region => 'california',
|
76
|
+
# :pattern => {
|
77
|
+
# :intervals => [{ :start => 1, :end => 10000, :duration => 60 }]
|
78
|
+
# }
|
79
|
+
# }
|
80
|
+
#
|
81
|
+
# result = Blitz::Curl::Sprint.execute args do |partial|
|
82
|
+
# pp [ partial.region, partial.timeline.last.hits ]
|
83
|
+
# end
|
84
|
+
#
|
85
|
+
# You can easily export the result to JSON, XML or compute the various
|
86
|
+
# rates, etc.
|
87
|
+
def self.execute args, &block # |result|
|
88
|
+
self.queue(args).result &block
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.queue args # :nodoc:
|
92
|
+
if not args.member? 'pattern' and not args.member? :pattern
|
41
93
|
raise ArgumentError, 'missing pattern'
|
42
94
|
end
|
43
95
|
|
@@ -46,15 +98,15 @@ class Rush
|
|
46
98
|
return self.new res
|
47
99
|
end
|
48
100
|
|
49
|
-
attr_reader :job_id
|
50
|
-
attr_reader :region
|
101
|
+
attr_reader :job_id # :nodoc:
|
102
|
+
attr_reader :region # :nodoc:
|
51
103
|
|
52
|
-
def initialize json
|
104
|
+
def initialize json # :nodoc:
|
53
105
|
@job_id = json['job_id']
|
54
106
|
@region = json['region']
|
55
107
|
end
|
56
108
|
|
57
|
-
def result
|
109
|
+
def result &block # :nodoc:
|
58
110
|
last = nil
|
59
111
|
while true
|
60
112
|
sleep 2.0
|
@@ -83,7 +135,7 @@ class Rush
|
|
83
135
|
|
84
136
|
last = Result.new(job)
|
85
137
|
continue = yield last rescue false
|
86
|
-
if
|
138
|
+
if continue == false
|
87
139
|
abort!
|
88
140
|
break
|
89
141
|
end
|
@@ -94,7 +146,7 @@ class Rush
|
|
94
146
|
return last
|
95
147
|
end
|
96
148
|
|
97
|
-
def abort!
|
149
|
+
def abort! # :nodoc:
|
98
150
|
Command::API.client.abort_job job_id rescue nil
|
99
151
|
end
|
100
152
|
end
|
data/lib/blitz/curl/sprint.rb
CHANGED
@@ -1,14 +1,28 @@
|
|
1
1
|
class Blitz
|
2
|
-
module Curl
|
2
|
+
module Curl # :nodoc:
|
3
|
+
# Use this to run a sprint against your app. The return values include the response
|
4
|
+
# time, the region from which the sprint was run along with the full request
|
5
|
+
# and response headers and the response body.
|
3
6
|
class Sprint
|
7
|
+
# Represents the request object generated by the sprint. Contains all
|
8
|
+
# of the headers and POST/PUT data, if any.
|
4
9
|
class Request
|
10
|
+
# The entire request line (GET / HTTP/1.1, for example)
|
5
11
|
attr_reader :line
|
12
|
+
|
13
|
+
# The method used in the request
|
6
14
|
attr_reader :method
|
15
|
+
|
16
|
+
# The URL, including path, query arguments and hash fragments
|
7
17
|
attr_reader :url
|
18
|
+
|
19
|
+
# All of the request headers (as a Hash of name/value pairs)
|
8
20
|
attr_reader :headers
|
21
|
+
|
22
|
+
# POST/PUT content, if any
|
9
23
|
attr_reader :content
|
10
24
|
|
11
|
-
def initialize json
|
25
|
+
def initialize json # :nodoc:
|
12
26
|
@line = json['line']
|
13
27
|
@method = json['method']
|
14
28
|
@url = json['url']
|
@@ -17,14 +31,25 @@ class Sprint
|
|
17
31
|
end
|
18
32
|
end
|
19
33
|
|
34
|
+
# Represents the response object generated by the sprint. Contains all
|
35
|
+
# of the headers and the response payload, if any.
|
20
36
|
class Response
|
37
|
+
# The entire response line (HTTP/1.1 200 Okay, for example)
|
21
38
|
attr_reader :line
|
39
|
+
|
40
|
+
# The response status
|
22
41
|
attr_reader :status
|
42
|
+
|
43
|
+
# The message in the response line
|
23
44
|
attr_reader :message
|
45
|
+
|
46
|
+
# All of the response headers (as a Hash of name/value pairs)
|
24
47
|
attr_reader :headers
|
48
|
+
|
49
|
+
# The response content, if any
|
25
50
|
attr_reader :content
|
26
51
|
|
27
|
-
def initialize json
|
52
|
+
def initialize json # :nodoc:
|
28
53
|
@line = json['line']
|
29
54
|
@status = json['status']
|
30
55
|
@message = json['message']
|
@@ -33,14 +58,24 @@ class Sprint
|
|
33
58
|
end
|
34
59
|
end
|
35
60
|
|
61
|
+
# Contains the result from a successful sprint
|
36
62
|
class Result
|
63
|
+
# The region from which this sprint was executed
|
37
64
|
attr_reader :region
|
65
|
+
|
66
|
+
# The overall response time for the successful hit
|
38
67
|
attr_reader :duration
|
68
|
+
|
69
|
+
# The time it took for the TCP connection
|
39
70
|
attr_reader :connect
|
71
|
+
|
72
|
+
# The request object containing the URL, headers and content, if any
|
40
73
|
attr_reader :request
|
74
|
+
|
75
|
+
# The response object containing the status code, headers and content, if any
|
41
76
|
attr_reader :response
|
42
77
|
|
43
|
-
def initialize json
|
78
|
+
def initialize json # :nodoc:
|
44
79
|
result = json['result']
|
45
80
|
@region = result['region']
|
46
81
|
@duration = result['duration']
|
@@ -50,21 +85,36 @@ class Sprint
|
|
50
85
|
end
|
51
86
|
end
|
52
87
|
|
88
|
+
# The primary method to execute a sprint from region. This method supports
|
89
|
+
# all of the arguments that the blitz bar supports. For example:
|
90
|
+
#
|
91
|
+
# args = {
|
92
|
+
# :url => 'http://www.mudynamics.com',
|
93
|
+
# :headers => [ 'X-API-Token: foo' ],
|
94
|
+
# :region => 'california'
|
95
|
+
# }
|
96
|
+
#
|
97
|
+
# result = Blitz::Curl::Sprint.execute args
|
53
98
|
def self.execute args
|
99
|
+
self.queue(args).result
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.queue args # :nodoc:
|
54
103
|
args.delete 'pattern'
|
104
|
+
args.delete :pattern
|
55
105
|
|
56
106
|
res = Command::API.client.curl_execute args
|
57
107
|
raise Error.new(res) if res['error']
|
58
108
|
return self.new res['job_id']
|
59
109
|
end
|
60
110
|
|
61
|
-
attr_reader :job_id
|
111
|
+
attr_reader :job_id # :nodoc:
|
62
112
|
|
63
|
-
def initialize job_id
|
113
|
+
def initialize job_id # :nodoc:
|
64
114
|
@job_id = job_id
|
65
115
|
end
|
66
116
|
|
67
|
-
def result
|
117
|
+
def result # :nodoc:
|
68
118
|
while true
|
69
119
|
sleep 2.0
|
70
120
|
|
@@ -100,7 +150,7 @@ class Sprint
|
|
100
150
|
end
|
101
151
|
end
|
102
152
|
|
103
|
-
def abort
|
153
|
+
def abort # :nodoc:
|
104
154
|
Command::API.client.abort_job job_id rescue nil
|
105
155
|
end
|
106
156
|
end
|
data/lib/blitz/helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blitz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 6
|
10
|
+
version: 0.1.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- pcapr
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-04-
|
18
|
+
date: 2011-04-20 00:00:00 -07:00
|
19
19
|
default_executable: blitz
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|