skaes-railsbench 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,7 +18,13 @@ class RailsBenchmark
18
18
  end
19
19
 
20
20
  def relative_url_root=(value)
21
- ActionController::AbstractRequest.relative_url_root = value
21
+ if ActionController::Base.respond_to?(:relative_url_root=)
22
+ # rails 2.3
23
+ ActionController::Base.relative_url_root = value
24
+ else
25
+ # earlier railses
26
+ ActionController::AbstractRequest.relative_url_root = value
27
+ end
22
28
  @relative_url_root = value
23
29
  end
24
30
 
@@ -42,6 +48,16 @@ class RailsBenchmark
42
48
  begin
43
49
  require ENV['RAILS_ROOT'] + "/config/environment"
44
50
  require 'dispatcher' # make edge rails happy
51
+
52
+ if Rails::VERSION::STRING >= "2.3"
53
+ require 'cgi/session'
54
+ CGI.class_eval <<-"end_eval"
55
+ def env_table
56
+ @env_table ||= ENV.to_hash
57
+ end
58
+ end_eval
59
+ end
60
+
45
61
  rescue => e
46
62
  $stderr.puts "failed to load application environment"
47
63
  e.backtrace.each{|line| $stderr.puts line}
@@ -139,26 +155,60 @@ class RailsBenchmark
139
155
  end
140
156
 
141
157
  def establish_test_session
142
- session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.stringify_keys
143
- session_options = session_options.merge('new_session' => true)
144
- @session = CGI::Session.new(Hash.new, session_options)
145
- @session_data.each{ |k,v| @session[k] = v }
146
- @session.update
147
- @session_id = @session.session_id
158
+ if Rails::VERSION::STRING >= "2.3"
159
+ session_options = ActionController::Base.session_options
160
+ # puts "the options: #{session_options.inspect}"
161
+ @session_id = ActiveSupport::SecureRandom.hex(16)
162
+ do_not_do_much = lambda do |env|
163
+ env["rack.session"] = @session_data
164
+ env["rack.session.options"] = {:id => @session_id}
165
+ [200, {}, ""]
166
+ end
167
+ @session_store = ActionController::Base.session_store.new(do_not_do_much, session_options)
168
+ @session_store.call({})
169
+ else
170
+ session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.stringify_keys
171
+ session_options = session_options.merge('new_session' => true)
172
+ @session = CGI::Session.new(Hash.new, session_options)
173
+ @session_data.each{ |k,v| @session[k] = v }
174
+ @session.update
175
+ @session_id = @session.session_id
176
+ end
148
177
  end
149
178
 
150
179
  def update_test_session_data(session_data)
180
+ # puts ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.inspect
151
181
  dbman = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS[:database_manager]
152
- old_session_data = dbman.new(@session).restore
153
- # $stderr.puts old_session_data.inspect
154
- new_session_data = old_session_data.merge(session_data || {})
155
- new_session_data.each{ |k,v| @session[k] = v }
156
- @session.update
182
+ if dbman # before rails 2.3
183
+ old_session_data = dbman.new(@session).restore
184
+ # $stderr.puts old_session_data.inspect
185
+ new_session_data = old_session_data.merge(session_data || {})
186
+ new_session_data.each{ |k,v| @session[k] = v }
187
+ @session.update
188
+ else
189
+ session_options = ActionController::Base.session_options
190
+ merge_url_specific_session_data = lambda do |env|
191
+ old_session_data = env["rack.session"]
192
+ # $stderr.puts "data in old session: #{old_session_data.inspect}"
193
+ new_session_data = old_session_data.merge(session_data || {})
194
+ # $stderr.puts "data in new session: #{new_session_data.inspect}"
195
+ env["rack.session"] = new_session_data
196
+ [200, {}, ""]
197
+ end
198
+ @session_store.instance_eval { @app = merge_url_specific_session_data }
199
+ env = {}
200
+ env["HTTP_COOKIE"] = cookie
201
+ # debugger
202
+ @session_store.call(env)
203
+ end
157
204
  end
158
205
 
159
206
  def delete_test_session
160
- @session.delete
161
- @session = nil
207
+ # no way to delete a session by going through the session adpater in rails 2.3
208
+ if @session
209
+ @session.delete
210
+ @session = nil
211
+ end
162
212
  end
163
213
 
164
214
  # can be redefined in subclasses to clean out test sessions
@@ -215,7 +265,7 @@ class RailsBenchmark
215
265
  @urls.each do |entry|
216
266
  error_exit "No uri given for benchmark entry: #{entry.inspect}" unless entry.uri
217
267
  setup_request_env(entry)
218
- Dispatcher.dispatch
268
+ Dispatcher.dispatch(CGI.new)
219
269
  end
220
270
  end
221
271
 
@@ -367,7 +417,7 @@ class RailsBenchmark
367
417
  request_count = 0
368
418
  n.times do
369
419
  before_dispatch_hook(entry)
370
- Dispatcher.dispatch
420
+ Dispatcher.dispatch(CGI.new)
371
421
  if (request_count += 1) == gc_frequency
372
422
  GC.enable; GC.start; GC.disable
373
423
  request_count = 0
@@ -381,7 +431,7 @@ class RailsBenchmark
381
431
  setup_request_env(entry)
382
432
  n.times do
383
433
  before_dispatch_hook(entry)
384
- Dispatcher.dispatch
434
+ Dispatcher.dispatch(CGI.new)
385
435
  end
386
436
  end
387
437
  end
@@ -398,7 +448,7 @@ class RailsBenchmark
398
448
  GC.enable_stats if gc_stats
399
449
  n.times do
400
450
  before_dispatch_hook(entry)
401
- Dispatcher.dispatch
451
+ Dispatcher.dispatch(CGI.new)
402
452
  if (request_count += 1) == gc_freq
403
453
  GC.enable; GC.start; GC.disable
404
454
  request_count = 0
@@ -424,7 +474,7 @@ class RailsBenchmark
424
474
  test.report(entry.name) do
425
475
  n.times do
426
476
  before_dispatch_hook(entry)
427
- Dispatcher.dispatch
477
+ Dispatcher.dispatch(CGI.new)
428
478
  end
429
479
  end
430
480
  end
@@ -446,7 +496,7 @@ class RailsBenchmark
446
496
  urls.each do |entry|
447
497
  setup_request_env(entry)
448
498
  before_dispatch_hook(entry)
449
- Dispatcher.dispatch
499
+ Dispatcher.dispatch(CGI.new)
450
500
  end
451
501
  end
452
502
  end
@@ -469,7 +519,7 @@ class RailsBenchmark
469
519
  urls.each do |entry|
470
520
  setup_request_env(entry)
471
521
  before_dispatch_hook(entry)
472
- Dispatcher.dispatch
522
+ Dispatcher.dispatch(CGI.new)
473
523
  if (request_count += 1) == gc_frequency
474
524
  GC.enable; GC.start; GC.disable
475
525
  request_count = 0
@@ -2,7 +2,7 @@ module Railsbench #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 9
5
- TINY = 4
5
+ TINY = 5
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skaes-railsbench
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Kaes
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-17 00:00:00 -07:00
12
+ date: 2009-06-25 00:00:00 -07:00
13
13
  default_executable: railsbench
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency