Sha256: e392d4163b5da6ecb3ceb29c49c3c283afdd6d4d60ec78b755e34930deb62e8c

Contents?: true

Size: 780 Bytes

Versions: 9

Compression:

Stored size: 780 Bytes

Contents

require_relative 'helper'

describe 'Adapter' do
  supported_by Swift::Adapter::Postgres, Swift::Adapter::Mysql do
    describe 'async operations' do
      it 'can runs queries async' do
        rows = []
        pool = 3.times.map.with_index {|n| Swift.setup n, Swift.db.class, db: 'swift_test' }
        func = case Swift.db
          when Swift::Adapter::Mysql    then 'sleep'
          when Swift::Adapter::Postgres then 'pg_sleep'
        end

        3.times do |n|
          Thread.new do
            pool[n].query("select #{func}(#{(3 - n) / 10.0}), #{n + 1} as query_id") {|row| rows << row[:query_id]}
          end
        end

        Thread.list.reject {|thread| Thread.current == thread}.each(&:join)
        assert_equal [3, 2, 1], rows
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
swift-1.2.3 test/test_async.rb
swift-1.2.2 test/test_async.rb
swift-1.2.1 test/test_async.rb
swift-1.2.0 test/test_async.rb
swift-1.1.0 test/test_async.rb
swift-1.0.3 test/test_async.rb
swift-1.0.2 test/test_async.rb
swift-1.0.1 test/test_async.rb
swift-1.0.0 test/test_async.rb