Add before_checkout/after_release callbacks for resources in pool (#36)

add auto_release to DB::Connection (default true on each pool checkout).
fixes #35.
This commit is contained in:
Brian J. Cardiff 2017-01-16 16:47:58 -03:00 committed by GitHub
parent e3762eec46
commit 09b8997636
5 changed files with 47 additions and 2 deletions

View file

@ -42,9 +42,19 @@ end
class Closable
include DB::Disposable
property before_checkout_called : Bool = false
property after_release_called : Bool = false
protected def do_close
end
def before_checkout
@before_checkout_called = true
end
def after_release
@after_release_called = true
end
end
describe DB::Pool do
@ -56,7 +66,9 @@ describe DB::Pool do
it "should get resource" do
pool = DB::Pool.new { Closable.new }
pool.checkout.should be_a Closable
resource = pool.checkout
resource.should be_a Closable
resource.before_checkout_called.should be_true
end
it "should be available if not checkedout" do
@ -74,8 +86,10 @@ describe DB::Pool do
it "should be available if returned" do
pool = DB::Pool.new { Closable.new }
resource = pool.checkout
resource.after_release_called.should be_false
pool.release resource
pool.is_available?(resource).should be_true
resource.after_release_called.should be_true
end
it "should wait for available resource" do