invidious/lib/sqlite3/spec/pool_spec.cr
Leon Klingele 40fb17791e
shard: track dependencies
Commit the whole ./lib/ folder which stores the Crystal dependencies.
This has a few benefits:

- Allows to build the project without a connection to the Internet
  to retrieve dependencies.
- Makes the project resistant against dependency re-tags which might
  include malicious code.
2019-08-15 01:51:27 +02:00

33 lines
903 B
Crystal

require "./spec_helper"
describe DB::Pool do
it "should write from multiple connections" do
channel = Channel(Nil).new
fibers = 5
max_n = 50
with_db "#{DB_FILENAME}?max_pool_size=#{fibers}" do |db|
db.exec "create table numbers (n integer, fiber integer)"
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
end