test/test_pool.rb in swift-0.6.1 vs test/test_pool.rb in swift-0.7.0
- old
+ new
@@ -4,31 +4,35 @@
describe 'Adapter' do
supported_by Swift::DB::Postgres, Swift::DB::Mysql do
describe 'Asynchronous connection pool' do
before do
Swift.db do |db|
- db.execute %q{drop table if exists users}
- db.execute %Q{create table users(id serial, name text)}
+ db.execute %q{drop table users} rescue nil
+ db.execute %Q{create table users(name varchar(64))}
end
end
- it 'creates connection pool' do
- driver = Swift.db.kind_of?(Swift::DB::Mysql) ? 'mysql' : 'postgresql'
- assert Swift::Pool.new 5, db: 'swift_test', driver: driver
- end
-
- describe 'Running queries' do
- it 'should select data' do
- rows = []
+ it 'creates connection pool and runs queries' do
+ rows = []
+ Swift.pool(5) do |pool|
+ assert pool
assert Swift.db.write('users', %w{name}, StringIO.new("user1\nuser2\nuser3\n"))
- Swift.pool 5 do |pool|
- pool.execute('select * from users') do |rs|
- rows += rs.to_a
- pool.execute('select * from users') {|rs| rows += rs.to_a }
+ pool.execute('select * from users') do |rs|
+ rows += rs.to_a
+ Thread.new do
+ sleep 0.25
+ pool.execute('select * from users order by name desc') {|rs| rows += rs.to_a; EM.stop }
end
end
- assert_equal 6, rows.length
+ pool.execute('select * from users') do |rs|
+ rows += rs.to_a
+ end
end
+
+ data = %w(user1 user2 user3)
+
+ assert_equal 9, rows.length
+ assert_equal data*2 + data.reverse, rows.map {|r| r[:name] }
end
end
end
end