summaryrefslogtreecommitdiff
path: root/test/spec_builder.rb
diff options
context:
space:
mode:
authorAman Gupta <aman@tmm1.net>2013-09-26 19:18:01 -0700
committerAman Gupta <aman@tmm1.net>2013-09-26 19:18:01 -0700
commitf791197f501776480a67211afbca0b32c628b2c9 (patch)
tree44da24a8da5587e4c3217b582ab2271aff8cc3fc /test/spec_builder.rb
parent65bf5e717dc60a045a048dd8af8743d2cc03c6c4 (diff)
downloadrack-f791197f501776480a67211afbca0b32c628b2c9.tar.gz
Add Rack::Builder#warmup method for app preloading.
This new `warmup` method takes a block which is invoked after the app is built. The block can be used to make mock requests that ensure all application dependencies are loaded before the app starts serving traffic. With complex frameworks like Rails, many dependencies are auto-loaded and data like mime-type and i18n is not loaded into memory by default. This often means the first few requests handled by an application are quite slow. With this patch, config.ru can simply make requests via warmup to exercise the app before it is used: $ tail -4 config.ru warmup do |app| client = Rack::MockRequest.new(app) client.get('/') end
Diffstat (limited to 'test/spec_builder.rb')
-rw-r--r--test/spec_builder.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/test/spec_builder.rb b/test/spec_builder.rb
index 0774f597..20ea6681 100644
--- a/test/spec_builder.rb
+++ b/test/spec_builder.rb
@@ -130,6 +130,17 @@ describe Rack::Builder do
Rack::MockRequest.new(app).get("/foo").should.be.server_error
end
+ it "yields the generated app to a block for warmup" do
+ warmed_up_app = nil
+
+ app = Rack::Builder.new do
+ warmup { |a| warmed_up_app = a }
+ run lambda { |env| [200, {}, []] }
+ end.to_app
+
+ warmed_up_app.should.equal app
+ end
+
should "initialize apps once" do
app = builder do
class AppClass