blitz 0.1.26 → 0.1.27

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.
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{blitz}
8
- s.version = "0.1.26"
8
+ s.version = "0.1.27"
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{2012-07-05}
12
+ s.date = %q{2012-08-29}
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{support@blitz.io}
@@ -3,6 +3,7 @@ require 'term/ansicolor'
3
3
  require 'couchrest'
4
4
  require 'hexy'
5
5
  require 'pp'
6
+ require 'csv'
6
7
 
7
8
  class Blitz # :nodoc:
8
9
  require 'blitz/helper'
@@ -157,8 +157,18 @@ class Curl < Command # :nodoc:
157
157
  job.queue
158
158
  msg "rushing from #{yellow(job.region)}..."
159
159
  puts
160
+
161
+ if job.args.member?('output')
162
+ file = CSV.open(job.args['output'] || 'blitz.csv', 'w')
163
+ end
164
+
160
165
  job.result do |result|
161
- print_rush_result job.args, result, last_index
166
+ if file
167
+ csv_rush_result file, result, last_index
168
+ else
169
+ print_rush_result job.args, result, last_index
170
+ end
171
+
162
172
  if not result.timeline.empty?
163
173
  last_index = result.timeline.size
164
174
  end
@@ -173,9 +183,11 @@ class Curl < Command # :nodoc:
173
183
  error "#{yellow(e.region)}: #{red(e.message)}"
174
184
  rescue ::Blitz::Curl::Error => e
175
185
  error red(e.message)
186
+ ensure
187
+ file.close if file
176
188
  end
177
189
  end
178
-
190
+
179
191
  def print_rush_result args, result, last_index
180
192
  if last_index.nil?
181
193
  print yellow("%6s " % "Time")
@@ -188,11 +200,11 @@ class Curl < Command # :nodoc:
188
200
  print "%s" % "Mbps"
189
201
  puts
190
202
  end
191
-
203
+
192
204
  if last_index and result.timeline.size == last_index
193
205
  return
194
206
  end
195
-
207
+
196
208
  last = result.timeline[-2]
197
209
  curr = result.timeline[-1]
198
210
  print yellow("%5.1fs " % curr.timestamp)
@@ -201,7 +213,7 @@ class Curl < Command # :nodoc:
201
213
  print green("%8d " % curr.hits)
202
214
  print magenta("%8d " % curr.timeouts)
203
215
  print red("%8d " % curr.errors)
204
-
216
+
205
217
  if last
206
218
  elapsed = curr.timestamp - last.timestamp
207
219
  mbps = ((curr.txbytes + curr.rxbytes) - (last.txbytes + last.rxbytes))/elapsed/1024.0/1024.0
@@ -209,10 +221,35 @@ class Curl < Command # :nodoc:
209
221
  print green(" %7.2f " % htps)
210
222
  print "%.2f" % mbps
211
223
  end
212
-
224
+
213
225
  print "\n"
214
226
  end
215
227
 
228
+ def csv_rush_result file, result, last_index
229
+ if last_index.nil?
230
+ file << ["Time", "Users", "Response", "Hits", "Timeouts", "Errors", "Hits/s", "Mbps"]
231
+ end
232
+
233
+ if last_index and result.timeline.size == last_index
234
+ return
235
+ end
236
+
237
+ last = result.timeline[-2]
238
+ curr = result.timeline[-1]
239
+ arr = [curr.timestamp, curr.volume, curr.duration, curr.hits, curr.timeouts, curr.errors ]
240
+
241
+ if last
242
+ elapsed = curr.timestamp - last.timestamp
243
+ mbps = ((curr.txbytes + curr.rxbytes) - (last.txbytes + last.rxbytes))/elapsed/1024.0/1024.0
244
+ htps = (curr.hits - last.hits)/elapsed
245
+ arr << htps
246
+ arr << mbps
247
+ end
248
+
249
+ file << arr
250
+ file.flush
251
+ end
252
+
216
253
  def help
217
254
  helps = [
218
255
  { :short => '-A', :long => '--user-agent', :value => '<string>', :help => 'User-Agent to send to server' },
@@ -230,6 +267,7 @@ class Curl < Command # :nodoc:
230
267
  { :short => '-X', :long => '--request', :value => '<string>', :help => 'Request method to use (GET, HEAD, PUT, etc.)' },
231
268
  { :short => '-v', :long => '--variable', :value => '<string>', :help => 'Define a variable to use' },
232
269
  { :short => '-V', :long => '--verbose', :value => '', :help => 'Print the request/response headers' },
270
+ { :short => '-o', :long => '--output', :value => '<filename>', :help => 'Output to file (CSV)' },
233
271
  { :short => '-1', :long => '--tlsv1', :value => '', :help => 'Use TLSv1 (SSL)' },
234
272
  { :short => '-2', :long => '--sslv2', :value => '', :help => 'Use SSLv2 (SSL)' },
235
273
  { :short => '-3', :long => '--sslv3', :value => '', :help => 'Use SSLv3 (SSL)' }
@@ -200,6 +200,11 @@ class Curl
200
200
  next
201
201
  end
202
202
 
203
+ if [ '-o', '--output'].member? k
204
+ hash['output'] = shift(k, argv)
205
+ next
206
+ end
207
+
203
208
  raise ArgumentError, "Unknown option #{k}"
204
209
  end
205
210
 
@@ -19,7 +19,7 @@ describe Blitz::Command::Curl do
19
19
  }
20
20
  }
21
21
  }
22
-
22
+
23
23
  def mocked_sprint_request
24
24
  Blitz::Curl::Sprint::Request.new(sprint_data)
25
25
  end
@@ -48,6 +48,30 @@ describe Blitz::Command::Curl do
48
48
  }
49
49
  Blitz::Curl::Sprint::Result.new(sprint)
50
50
  end
51
+
52
+ def mocked_rush
53
+ rush = {
54
+ 'result' => {
55
+ 'region' => 'california',
56
+ 'timeline' => [
57
+ 'timestamp' => 1.50353,
58
+ 'volume' => 2,
59
+ 'duration' => 0.42632,
60
+ 'executed' => 2,
61
+ 'timeouts' => 0,
62
+ 'errors' => 0,
63
+ 'steps' => [
64
+ 'duration' => 0.0,
65
+ 'connect' => 0.0,
66
+ 'errors' => 0,
67
+ 'timeouts' => 5,
68
+ 'asserts' => 0
69
+ ]
70
+ ]
71
+ }
72
+ }
73
+ Blitz::Curl::Rush::Result.new(rush)
74
+ end
51
75
 
52
76
  context "#print_sprint_header" do
53
77
  def check_print_sprint_header path="/mocked/path/head.txt"
@@ -90,7 +114,31 @@ describe Blitz::Command::Curl do
90
114
  }
91
115
  end
92
116
  end
93
-
117
+
118
+ context "#csv_rush_result" do
119
+
120
+ it "should check if the rush results get dumped in csv format" do
121
+ file = CSV.open('blitztest.csv', 'w')
122
+
123
+ result = mocked_rush
124
+ obj = Blitz::Command::Curl.new
125
+ obj.send(:csv_rush_result, file, result, nil)
126
+ file.close
127
+
128
+ file = CSV.open('blitztest.csv', 'r').read()
129
+ output = file.last
130
+ timeline = result.timeline.last
131
+
132
+ output[0].to_f.should eq(timeline.timestamp)
133
+ output[1].to_f.should eq(timeline.volume)
134
+ output[2].to_f.should eq(timeline.duration)
135
+ output[3].to_f.should eq(timeline.hits)
136
+ output[4].to_f.should eq(timeline.timeouts)
137
+
138
+ File.delete('blitztest.csv')
139
+ end
140
+ end
141
+
94
142
  context "#print_sprint_result" do
95
143
  def check_print_sprint_result args
96
144
  result = mocked_sprint
@@ -98,6 +146,7 @@ describe Blitz::Command::Curl do
98
146
  yield(obj, result)
99
147
  obj.send(:print_sprint_result, args, result)
100
148
  end
149
+
101
150
  it "should not dump-header and verbose when they are not available" do
102
151
  args = mocked_sprint_args
103
152
  args.delete "verbose"
@@ -136,5 +185,5 @@ describe Blitz::Command::Curl do
136
185
  }
137
186
  end
138
187
  end
139
-
140
- end
188
+
189
+ end
@@ -238,6 +238,17 @@ describe Blitz::Curl do
238
238
  hash['steps'][1]['request'] == 'POST'
239
239
  end
240
240
  end
241
+
242
+ context "output" do
243
+ it "should check that a output is given" do
244
+ lambda { Blitz::Curl.parse_cli %w[--output] }.should raise_error(MiniTest::Assertion, /missing value/)
245
+ end
246
+
247
+ it "should support export to output file" do
248
+ hash = Blitz::Curl.parse_cli %w[-o test.csv /faq]
249
+ hash['output'].should == 'test.csv'
250
+ end
251
+ end
241
252
  end
242
253
 
243
254
  describe "xargv" do
@@ -270,4 +281,4 @@ describe Blitz::Curl do
270
281
  end
271
282
  end
272
283
  end
273
- end
284
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blitz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.26
4
+ version: 0.1.27
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-07-05 00:00:00.000000000 Z
12
+ date: 2012-08-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: couchrest