-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from crystal-lang/crystal-db/0.7.0
Update to crystal-db 0.7.0
- Loading branch information
Showing
6 changed files
with
86 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,12 @@ version: 0.8.0 | |
dependencies: | ||
db: | ||
github: crystal-lang/crystal-db | ||
version: ~> 0.6.0 | ||
version: ~> 0.7.0 | ||
|
||
authors: | ||
- Juan Wajnerman <[email protected]> | ||
- Brian J. Cardiff <[email protected]> | ||
|
||
crystal: 0.25.0 | ||
crystal: 0.30.0 | ||
|
||
license: MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
require "./spec_helper" | ||
|
||
describe DB::Pool do | ||
it "should write from multiple connections" do | ||
channel = Channel(Nil).new | ||
fibers = 20 | ||
max_pool_size = 5 | ||
max_n = 50 | ||
|
||
with_db "crystal_mysql_test", "max_pool_size=#{max_pool_size}" do |db| | ||
db.exec "create table numbers (n int, fiber int)" | ||
|
||
fibers.times do |f| | ||
spawn do | ||
(1..max_n).each do |n| | ||
db.exec "insert into numbers (n, fiber) values (?, ?)", n, f | ||
sleep 0.01 | ||
end | ||
channel.send nil | ||
end | ||
end | ||
|
||
fibers.times { channel.receive } | ||
|
||
# all numbers were inserted | ||
s = fibers * max_n * (max_n + 1) // 2 | ||
db.scalar("select sum(n) from numbers").should eq(s) | ||
|
||
# numbers were not inserted one fiber at a time | ||
rows = db.query_all "select n, fiber from numbers", as: {Int32, Int32} | ||
rows.map(&.[1]).should_not eq(rows.map(&.[1]).sort) | ||
end | ||
end | ||
|
||
it "starting multiple connections does not exceed max pool size" do | ||
channel = Channel(Nil).new | ||
fibers = 100 | ||
max_pool_size = 5 | ||
|
||
with_db "crystal_mysql_test", "max_pool_size=#{max_pool_size}" do |db| | ||
db.exec "create table numbers (n int, fiber int)" | ||
|
||
max_open_connections = Atomic.new(0) | ||
|
||
fibers.times do |f| | ||
spawn do | ||
cnn = db.checkout | ||
max_open_connections.max(db.pool.stats.open_connections) | ||
sleep 0.01 | ||
cnn.release | ||
channel.send nil | ||
end | ||
end | ||
|
||
fibers.times { channel.receive } | ||
max_open_connections.get.should be <= max_pool_size | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters