bigbench 0.0.1 → 0.0.2
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/README.textile +60 -22
- data/Rakefile +7 -0
- data/bigbench.gemspec +5 -0
- data/dev/net_http.rb +78 -0
- data/dev/test.rb +13 -0
- data/dev/tracking.rb +49 -0
- data/doc/BigBench.html +22 -17
- data/doc/BigBench/Benchmark.html +12 -8
- data/doc/BigBench/Benchmark/Benchmark.html +17 -27
- data/doc/BigBench/Benchmark/Looper.html +340 -0
- data/doc/BigBench/Bot.html +4 -2
- data/doc/BigBench/Configuration.html +20 -11
- data/doc/BigBench/Configuration/Config.html +23 -8
- data/doc/BigBench/Configuration/InvalidOptions.html +5 -3
- data/doc/BigBench/Executor.html +4 -2
- data/doc/BigBench/Executor/InvalidCommand.html +4 -2
- data/doc/BigBench/Fragment.html +46 -29
- data/doc/BigBench/Fragment/Fragment.html +18 -28
- data/doc/BigBench/Output.html +4 -2
- data/doc/BigBench/Runner.html +12 -9
- data/doc/BigBench/Runner/NoBenchmarksDefined.html +4 -2
- data/doc/BigBench/Store.html +4 -2
- data/doc/BigBench/Tracker.html +4 -2
- data/doc/BigBench/Tracker/Tracker.html +5 -3
- data/doc/EventMachineLoop.html +296 -0
- data/doc/Float.html +4 -2
- data/doc/Gemfile.html +4 -2
- data/doc/Helpers.html +4 -2
- data/doc/Object.html +87 -2
- data/doc/Rakefile.html +10 -3
- data/doc/created.rid +36 -31
- data/doc/index.html +4 -2
- data/doc/js/search_index.js +1 -1
- data/doc/lib/bigbench/help/executor_txt.html +4 -2
- data/doc/table_of_contents.html +31 -16
- data/lib/bigbench.rb +3 -0
- data/lib/bigbench/benchmark.rb +11 -21
- data/lib/bigbench/benchmark/looper.rb +43 -0
- data/lib/bigbench/configuration.rb +17 -10
- data/lib/bigbench/fragment.rb +47 -34
- data/lib/bigbench/runner.rb +8 -7
- data/lib/bigbench/tracker.rb +3 -3
- data/lib/bigbench/version.rb +1 -1
- data/spec/benchmark_spec.rb +14 -7
- data/spec/configure_spec.rb +3 -3
- data/spec/fragment_spec.rb +186 -24
- data/spec/helpers.rb +2 -4
- data/spec/lib/test_web_server.rb +44 -15
- data/spec/looper_spec.rb +47 -0
- data/spec/tests/local.rb +1 -1
- data/spec/webserver_spec.rb +91 -21
- metadata +77 -15
data/spec/fragment_spec.rb
CHANGED
@@ -30,7 +30,7 @@ describe BigBench::Fragment do
|
|
30
30
|
fragments.size.should == 1
|
31
31
|
fragments.first.uri.to_s.should == "http://localhost:3001/"
|
32
32
|
fragments.first.method.should == :get
|
33
|
-
fragments.first.
|
33
|
+
fragments.first.options.should == {}
|
34
34
|
end
|
35
35
|
|
36
36
|
it "POST" do
|
@@ -38,7 +38,7 @@ describe BigBench::Fragment do
|
|
38
38
|
fragments.size.should == 1
|
39
39
|
fragments.first.uri.to_s.should == "http://localhost:3001/login"
|
40
40
|
fragments.first.method.should == :post
|
41
|
-
fragments.first.
|
41
|
+
fragments.first.options.should == { :user => "tommy@test.com", :password => "secret" }
|
42
42
|
end
|
43
43
|
|
44
44
|
it "PUT" do
|
@@ -46,7 +46,7 @@ describe BigBench::Fragment do
|
|
46
46
|
fragments.size.should == 1
|
47
47
|
fragments.first.uri.to_s.should == "http://localhost:3001/books"
|
48
48
|
fragments.first.method.should == :put
|
49
|
-
fragments.first.
|
49
|
+
fragments.first.options.should == { :book => "A Book" }
|
50
50
|
end
|
51
51
|
|
52
52
|
it "DELETE" do
|
@@ -54,7 +54,7 @@ describe BigBench::Fragment do
|
|
54
54
|
fragments.size.should == 1
|
55
55
|
fragments.first.uri.to_s.should == "http://localhost:3001/books/5"
|
56
56
|
fragments.first.method.should == :delete
|
57
|
-
fragments.first.
|
57
|
+
fragments.first.options.should == { :user => "tommy@test.com", :password => "secret" }
|
58
58
|
end
|
59
59
|
|
60
60
|
end
|
@@ -64,45 +64,207 @@ describe BigBench::Fragment do
|
|
64
64
|
it "GET" do
|
65
65
|
fragment = BigBench::Fragment.parse(@benchmark){ get "/" }.first
|
66
66
|
result = nil
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
67
|
+
|
68
|
+
EventMachine.run { |http|
|
69
|
+
start = Time.now
|
70
|
+
http = fragment.run!
|
71
|
+
|
72
|
+
http.callback {
|
73
|
+
fragment.track!(start, Time.now, http)
|
74
|
+
http.response_header.status.should == 200
|
75
|
+
http.response.should match(/Test/)
|
76
|
+
EventMachine.stop
|
77
|
+
}
|
78
|
+
|
79
|
+
http.errback { puts "Error"; EventMachine.stop }
|
80
|
+
}
|
81
|
+
|
72
82
|
@benchmark.tracker.trackings.size.should == 1
|
73
83
|
end
|
74
84
|
|
75
85
|
it "POST" do
|
76
86
|
fragment = BigBench::Fragment.parse(@benchmark){ post "/" }.first
|
77
87
|
result = nil
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
88
|
+
|
89
|
+
EventMachine.run { |http|
|
90
|
+
start = Time.now
|
91
|
+
http = fragment.run!
|
92
|
+
|
93
|
+
http.callback {
|
94
|
+
fragment.track!(start, Time.now, http)
|
95
|
+
http.response_header.status.should == 200
|
96
|
+
http.response.should match(/Test/)
|
97
|
+
EventMachine.stop
|
98
|
+
}
|
99
|
+
|
100
|
+
http.errback { puts "Error"; EventMachine.stop }
|
101
|
+
}
|
102
|
+
|
83
103
|
@benchmark.tracker.trackings.size.should == 1
|
84
104
|
end
|
85
105
|
|
86
106
|
it "PUT" do
|
87
107
|
fragment = BigBench::Fragment.parse(@benchmark){ put "/" }.first
|
88
108
|
result = nil
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
109
|
+
|
110
|
+
EventMachine.run { |http|
|
111
|
+
start = Time.now
|
112
|
+
http = fragment.run!
|
113
|
+
|
114
|
+
http.callback {
|
115
|
+
fragment.track!(start, Time.now, http)
|
116
|
+
http.response_header.status.should == 200
|
117
|
+
http.response.should match(/Test/)
|
118
|
+
EventMachine.stop
|
119
|
+
}
|
120
|
+
|
121
|
+
http.errback { puts "Error"; EventMachine.stop }
|
122
|
+
}
|
123
|
+
|
94
124
|
@benchmark.tracker.trackings.size.should == 1
|
95
125
|
end
|
96
126
|
|
97
127
|
it "DELETE" do
|
98
128
|
fragment = BigBench::Fragment.parse(@benchmark){ delete "/" }.first
|
99
129
|
result = nil
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
130
|
+
|
131
|
+
EventMachine.run { |http|
|
132
|
+
start = Time.now
|
133
|
+
http = fragment.run!
|
134
|
+
|
135
|
+
http.callback {
|
136
|
+
fragment.track!(start, Time.now, http)
|
137
|
+
http.response_header.status.should == 200
|
138
|
+
http.response.should match(/Test/)
|
139
|
+
EventMachine.stop
|
140
|
+
}
|
141
|
+
|
142
|
+
http.errback { puts "Error"; EventMachine.stop }
|
143
|
+
}
|
144
|
+
|
145
|
+
@benchmark.tracker.trackings.size.should == 1
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
context "should run basic auth fragments" do
|
151
|
+
|
152
|
+
it "and track a 401 if no authorization was provided" do
|
153
|
+
fragment = BigBench::Fragment.parse(@benchmark){ get "/basic/auth" }.first
|
154
|
+
result = nil
|
155
|
+
|
156
|
+
EventMachine.run { |http|
|
157
|
+
start = Time.now
|
158
|
+
http = fragment.run!
|
159
|
+
|
160
|
+
http.callback {
|
161
|
+
fragment.track!(start, Time.now, http)
|
162
|
+
http.response_header.status.should == 401
|
163
|
+
EventMachine.stop
|
164
|
+
}
|
165
|
+
|
166
|
+
http.errback { puts "Error"; EventMachine.stop }
|
167
|
+
}
|
168
|
+
|
169
|
+
@benchmark.tracker.trackings.size.should == 1
|
170
|
+
@benchmark.tracker.trackings.first[:status] == 401
|
171
|
+
end
|
172
|
+
|
173
|
+
it "and work with fragment authorization" do
|
174
|
+
fragment = BigBench::Fragment.parse(@benchmark){
|
175
|
+
get "/basic/auth", :basic_auth => ['admin', 'secret']
|
176
|
+
}.first
|
177
|
+
result = nil
|
178
|
+
|
179
|
+
EventMachine.run { |http|
|
180
|
+
start = Time.now
|
181
|
+
http = fragment.run!
|
182
|
+
|
183
|
+
http.callback {
|
184
|
+
fragment.track!(start, Time.now, http)
|
185
|
+
http.response_header.status.should == 200
|
186
|
+
http.response.should match(/Test/)
|
187
|
+
EventMachine.stop
|
188
|
+
}
|
189
|
+
|
190
|
+
http.errback { puts "Error"; EventMachine.stop }
|
191
|
+
}
|
192
|
+
|
193
|
+
@benchmark.tracker.trackings.size.should == 1
|
194
|
+
@benchmark.tracker.trackings.first[:status] == 200
|
195
|
+
end
|
196
|
+
|
197
|
+
it "and work with config authorization" do
|
198
|
+
BigBench.config.basic_auth = ['admin', 'secret']
|
199
|
+
fragment = BigBench::Fragment.parse(@benchmark){
|
200
|
+
get "/basic/auth"
|
201
|
+
}.first
|
202
|
+
result = nil
|
203
|
+
|
204
|
+
EventMachine.run { |http|
|
205
|
+
start = Time.now
|
206
|
+
http = fragment.run!
|
207
|
+
|
208
|
+
http.callback {
|
209
|
+
fragment.track!(start, Time.now, http)
|
210
|
+
http.response_header.status.should == 200
|
211
|
+
http.response.should match(/Test/)
|
212
|
+
EventMachine.stop
|
213
|
+
}
|
214
|
+
|
215
|
+
http.errback { puts "Error"; EventMachine.stop }
|
216
|
+
}
|
217
|
+
|
218
|
+
@benchmark.tracker.trackings.size.should == 1
|
219
|
+
@benchmark.tracker.trackings.first[:status] == 200
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
context "should send params in body" do
|
224
|
+
|
225
|
+
it "and track a 406 if no params were provided" do
|
226
|
+
fragment = BigBench::Fragment.parse(@benchmark){ post "/post/content" }.first
|
227
|
+
result = nil
|
228
|
+
|
229
|
+
EventMachine.run { |http|
|
230
|
+
start = Time.now
|
231
|
+
http = fragment.run!
|
232
|
+
|
233
|
+
http.callback {
|
234
|
+
fragment.track!(start, Time.now, http)
|
235
|
+
http.response_header.status.should == 406
|
236
|
+
EventMachine.stop
|
237
|
+
}
|
238
|
+
|
239
|
+
http.errback { puts "Error"; EventMachine.stop }
|
240
|
+
}
|
241
|
+
|
242
|
+
@benchmark.tracker.trackings.size.should == 1
|
243
|
+
@benchmark.tracker.trackings.first[:status] == 406
|
244
|
+
end
|
245
|
+
|
246
|
+
it "and work with params supplied" do
|
247
|
+
fragment = BigBench::Fragment.parse(@benchmark){
|
248
|
+
post "/post/content", :params => { :name => "bigbench", :id => 1 }
|
249
|
+
}.first
|
250
|
+
result = nil
|
251
|
+
|
252
|
+
EventMachine.run { |http|
|
253
|
+
start = Time.now
|
254
|
+
http = fragment.run!
|
255
|
+
|
256
|
+
http.callback {
|
257
|
+
fragment.track!(start, Time.now, http)
|
258
|
+
http.response_header.status.should == 200
|
259
|
+
http.response.should match(/Test/)
|
260
|
+
EventMachine.stop
|
261
|
+
}
|
262
|
+
|
263
|
+
http.errback { puts "Error"; EventMachine.stop }
|
264
|
+
}
|
265
|
+
|
105
266
|
@benchmark.tracker.trackings.size.should == 1
|
267
|
+
@benchmark.tracker.trackings.first[:status] == 200
|
106
268
|
end
|
107
269
|
|
108
270
|
end
|
data/spec/helpers.rb
CHANGED
@@ -2,16 +2,14 @@ require 'bigbench'
|
|
2
2
|
require 'rack'
|
3
3
|
require 'active_support/all'
|
4
4
|
require 'net/http'
|
5
|
-
require '
|
6
|
-
require '
|
5
|
+
require 'eventmachine'
|
6
|
+
require 'em-http'
|
7
7
|
|
8
8
|
module Helpers
|
9
9
|
end
|
10
10
|
|
11
11
|
RSpec.configure do |config|
|
12
12
|
config.include Helpers
|
13
|
-
config.before(:all) { TestWebServer.start }
|
14
|
-
config.after(:all) { TestWebServer.stop }
|
15
13
|
config.before(:each) {
|
16
14
|
BigBench::Configuration.reset!
|
17
15
|
BigBench::Benchmark.reset!
|
data/spec/lib/test_web_server.rb
CHANGED
@@ -1,18 +1,47 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sinatra'
|
3
|
+
|
4
|
+
set :port, 3001
|
5
|
+
|
6
|
+
helpers do
|
7
|
+
def protected!
|
8
|
+
unless authorized?
|
9
|
+
response['WWW-Authenticate'] = %(Basic realm="BigBench TestWebServer")
|
10
|
+
throw(:halt, [401, "Not authorized\n"])
|
11
|
+
end
|
11
12
|
end
|
12
|
-
|
13
|
-
def
|
14
|
-
|
15
|
-
|
13
|
+
|
14
|
+
def authorized?
|
15
|
+
@auth ||= Rack::Auth::Basic::Request.new(request.env)
|
16
|
+
@auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == ['admin', 'secret']
|
16
17
|
end
|
17
|
-
|
18
|
+
end
|
19
|
+
|
20
|
+
# Base HTTP Verbs
|
21
|
+
get "/" do
|
22
|
+
"Test"
|
23
|
+
end
|
24
|
+
|
25
|
+
put "/" do
|
26
|
+
"Test"
|
27
|
+
end
|
28
|
+
|
29
|
+
post "/" do
|
30
|
+
"Test"
|
31
|
+
end
|
32
|
+
|
33
|
+
delete "/" do
|
34
|
+
"Test"
|
35
|
+
end
|
36
|
+
|
37
|
+
# Basic Auth URL
|
38
|
+
get "/basic/auth" do
|
39
|
+
protected!
|
40
|
+
"Test"
|
41
|
+
end
|
42
|
+
|
43
|
+
# Needs Body Params
|
44
|
+
post "/post/content" do
|
45
|
+
status 406 unless params[:name] == "bigbench" and params[:id] == "1"
|
46
|
+
"Test"
|
18
47
|
end
|
data/spec/looper_spec.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require_relative "./helpers"
|
2
|
+
|
3
|
+
describe BigBench::Benchmark::Looper do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@benchmark = BigBench::Benchmark::Benchmark.new("a test benchmark", "http://localhost:3001", {}) do
|
7
|
+
get "/"
|
8
|
+
get "/logout"
|
9
|
+
end
|
10
|
+
@benchmark.start = Time.now
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should get the next fragment" do
|
14
|
+
looper = BigBench::Benchmark::Looper.new(@benchmark)
|
15
|
+
looper.next_fragment.path.should == "/"
|
16
|
+
looper.next_fragment.path.should == "/logout"
|
17
|
+
looper.next_fragment.path.should == "/"
|
18
|
+
looper.next_fragment.path.should == "/logout"
|
19
|
+
looper.next_fragment.path.should == "/"
|
20
|
+
looper.next_fragment.path.should == "/logout"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should do nothing if benchmark is not running" do
|
24
|
+
looper = BigBench::Benchmark::Looper.new(@benchmark)
|
25
|
+
looper.loop!
|
26
|
+
|
27
|
+
looper.loops.should == 0
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
it "should loop through the fragments as long as the benchmark is running" do
|
32
|
+
looper = BigBench::Benchmark::Looper.new(@benchmark)
|
33
|
+
|
34
|
+
EventMachine.run {
|
35
|
+
|
36
|
+
timer = Thread.new{ sleep(5); @benchmark.is_running = false; EventMachine.stop }
|
37
|
+
@benchmark.is_running = true
|
38
|
+
@benchmark.start = Time.now
|
39
|
+
|
40
|
+
looper.loop!
|
41
|
+
}
|
42
|
+
|
43
|
+
looper.loops.should > 1000
|
44
|
+
@benchmark.tracker.trackings.size.should == looper.loops
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/spec/tests/local.rb
CHANGED
data/spec/webserver_spec.rb
CHANGED
@@ -1,34 +1,104 @@
|
|
1
1
|
require_relative "./helpers"
|
2
2
|
|
3
|
-
describe TestWebServer do
|
3
|
+
describe "TestWebServer" do
|
4
4
|
|
5
5
|
it "should respond to mock GET requests" do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
EventMachine.run {
|
7
|
+
http = EventMachine::HttpRequest.new('http://localhost:3001/').get
|
8
|
+
|
9
|
+
http.callback {
|
10
|
+
http.response_header.status.should == 200
|
11
|
+
http.response.should match(/Test/)
|
12
|
+
EventMachine.stop
|
13
|
+
}
|
14
|
+
|
15
|
+
http.errback { puts "Error"; EventMachine.stop }
|
16
|
+
}
|
13
17
|
end
|
14
18
|
|
15
19
|
it "should respond to mock POST requests" do
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
EventMachine.run {
|
21
|
+
http = EventMachine::HttpRequest.new('http://localhost:3001/').put
|
22
|
+
|
23
|
+
http.callback {
|
24
|
+
http.response_header.status.should == 200
|
25
|
+
http.response.should match(/Test/)
|
26
|
+
EventMachine.stop
|
27
|
+
}
|
28
|
+
|
29
|
+
http.errback { puts "Error"; EventMachine.stop }
|
30
|
+
}
|
23
31
|
end
|
24
32
|
|
25
33
|
it "should respond to mock PUT requests" do
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
34
|
+
EventMachine.run {
|
35
|
+
http = EventMachine::HttpRequest.new('http://localhost:3001/').post
|
36
|
+
|
37
|
+
http.callback {
|
38
|
+
http.response_header.status.should == 200
|
39
|
+
http.response.should match(/Test/)
|
40
|
+
EventMachine.stop
|
41
|
+
}
|
42
|
+
|
43
|
+
http.errback { puts "Error"; EventMachine.stop }
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
context "should need basic auth" do
|
48
|
+
it "and fail without basic auth credentials" do
|
49
|
+
EventMachine.run {
|
50
|
+
http = EventMachine::HttpRequest.new('http://localhost:3001/basic/auth').get
|
51
|
+
|
52
|
+
http.callback {
|
53
|
+
http.response_header.status.should == 401
|
54
|
+
EventMachine.stop
|
55
|
+
}
|
56
|
+
|
57
|
+
http.errback { puts "Error"; EventMachine.stop }
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
it "and work with basic auth supplied" do
|
62
|
+
EventMachine.run {
|
63
|
+
http = EventMachine::HttpRequest.new('http://localhost:3001/basic/auth').get :head => {'authorization' => ['admin', 'secret']}
|
64
|
+
|
65
|
+
http.callback {
|
66
|
+
http.response_header.status.should == 200
|
67
|
+
http.response.should match(/Test/)
|
68
|
+
EventMachine.stop
|
69
|
+
}
|
70
|
+
|
71
|
+
http.errback { puts "Error"; EventMachine.stop }
|
72
|
+
}
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "should need a body" do
|
77
|
+
it "and fail without the right params set" do
|
78
|
+
EventMachine.run {
|
79
|
+
http = EventMachine::HttpRequest.new('http://localhost:3001/post/content').post
|
80
|
+
|
81
|
+
http.callback {
|
82
|
+
http.response_header.status.should == 406
|
83
|
+
EventMachine.stop
|
84
|
+
}
|
85
|
+
|
86
|
+
http.errback { puts "Error"; EventMachine.stop }
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
it "and work with params set" do
|
91
|
+
EventMachine.run {
|
92
|
+
http = EventMachine::HttpRequest.new('http://localhost:3001/post/content').post :body => { :name => "bigbench", :id => 1 }
|
93
|
+
|
94
|
+
http.callback {
|
95
|
+
http.response_header.status.should == 200
|
96
|
+
http.response.should match(/Test/)
|
97
|
+
EventMachine.stop
|
98
|
+
}
|
99
|
+
|
100
|
+
http.errback { puts "Error"; EventMachine.stop }
|
101
|
+
}
|
32
102
|
end
|
33
103
|
end
|
34
104
|
|