mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
Add specs and update comment
This commit is contained in:
parent
0780916845
commit
9d2e601f53
3 changed files with 20 additions and 2 deletions
|
@ -179,6 +179,25 @@ describe DB::Database do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should not checkout multiple connections if there is a statement error" do
|
||||||
|
with_dummy "dummy://localhost:1027?initial_pool_size=1&max_pool_size=10&retry_attempts=10" do |db|
|
||||||
|
expect_raises DB::Error do
|
||||||
|
db.exec("syntax error")
|
||||||
|
end
|
||||||
|
DummyDriver::DummyConnection.connections.size.should eq(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should attempt all retries if connection is lost" do
|
||||||
|
with_dummy "dummy://localhost:1027?initial_pool_size=1&max_pool_size=1&retry_attempts=10" do |db|
|
||||||
|
expect_raises DB::PoolRetryAttemptsExceeded do
|
||||||
|
db.exec("raise ConnectionLost")
|
||||||
|
end
|
||||||
|
# 1 initial + 10 retries
|
||||||
|
DummyDriver::DummyConnection.connections.size.should eq(11)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "prepared_statements connection option" do
|
describe "prepared_statements connection option" do
|
||||||
it "defaults to true" do
|
it "defaults to true" do
|
||||||
with_dummy "dummy://localhost:1027" do |db|
|
with_dummy "dummy://localhost:1027" do |db|
|
||||||
|
|
|
@ -142,6 +142,7 @@ class DummyDriver < DB::Driver
|
||||||
super(connection, command)
|
super(connection, command)
|
||||||
@@statements_count.add(1)
|
@@statements_count.add(1)
|
||||||
raise DB::Error.new(command) if command == "syntax error"
|
raise DB::Error.new(command) if command == "syntax error"
|
||||||
|
raise DB::ConnectionLost.new(connection) if command == "raise ConnectionLost"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.statements_count
|
def self.statements_count
|
||||||
|
|
|
@ -206,8 +206,6 @@ module DB
|
||||||
# if the connection is lost it will be closed by
|
# if the connection is lost it will be closed by
|
||||||
# the exception to release resources
|
# the exception to release resources
|
||||||
# we still need to remove it from the known pool.
|
# we still need to remove it from the known pool.
|
||||||
# Closed connection will be evicted from statement cache
|
|
||||||
# in PoolPreparedStatement#clean_connections
|
|
||||||
sync { delete(e.resource) }
|
sync { delete(e.resource) }
|
||||||
rescue e : PoolResourceRefused
|
rescue e : PoolResourceRefused
|
||||||
# a ConnectionRefused means a new connection
|
# a ConnectionRefused means a new connection
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue