2009-12-19 03:16:58 +01:00
|
|
|
require 'rack/lock'
|
2010-06-14 06:09:24 +02:00
|
|
|
require 'rack/mock'
|
2009-12-19 03:16:58 +01:00
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
class Lock
|
|
|
|
attr_reader :synchronized
|
2009-12-19 03:16:58 +01:00
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
def initialize
|
|
|
|
@synchronized = false
|
|
|
|
end
|
2009-12-19 03:16:58 +01:00
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
def synchronize
|
|
|
|
@synchronized = true
|
|
|
|
yield
|
2009-12-19 03:16:58 +01:00
|
|
|
end
|
2010-06-14 06:09:24 +02:00
|
|
|
end
|
2009-12-19 03:16:58 +01:00
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
describe Rack::Lock do
|
|
|
|
should "call synchronize on lock" do
|
2009-12-19 03:16:58 +01:00
|
|
|
lock = Lock.new
|
|
|
|
env = Rack::MockRequest.env_for("/")
|
2010-06-14 06:09:24 +02:00
|
|
|
app = Rack::Lock.new(lambda { |inner_env| }, lock)
|
2009-12-19 03:16:58 +01:00
|
|
|
lock.synchronized.should.equal false
|
|
|
|
app.call(env)
|
|
|
|
lock.synchronized.should.equal true
|
|
|
|
end
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
should "set multithread flag to false" do
|
2009-12-19 03:16:58 +01:00
|
|
|
app = Rack::Lock.new(lambda { |env| env['rack.multithread'] })
|
|
|
|
app.call(Rack::MockRequest.env_for("/")).should.equal false
|
|
|
|
end
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
should "reset original multithread flag when exiting lock" do
|
2009-12-19 03:16:58 +01:00
|
|
|
app = Rack::Lock.new(lambda { |env| env })
|
|
|
|
app.call(Rack::MockRequest.env_for("/"))['rack.multithread'].should.equal true
|
|
|
|
end
|
|
|
|
end
|