Sha256: 76e70e52b9640713b60821197fdc93b39185792e5d5f4a582918bb2845a82caa

Contents?: true

Size: 1.38 KB

Versions: 16

Compression:

Stored size: 1.38 KB

Contents

# encoding: UTF-8
require 'spec_helper'
begin
  require 'eventmachine'
  require 'mysql2/em'

  describe Mysql2::EM::Client do
    it "should support async queries" do
      results = []
      EM.run do
        client1 = Mysql2::EM::Client.new
        defer1 = client1.query "SELECT sleep(0.1) as first_query"
        defer1.callback do |result|
          results << result.first
          EM.stop_event_loop
        end

        client2 = Mysql2::EM::Client.new
        defer2 = client2.query "SELECT sleep(0.025) second_query"
        defer2.callback do |result|
          results << result.first
        end
      end

      results[0].keys.should include("second_query")
      results[1].keys.should include("first_query")
    end

    it "should support queries in callbacks" do
      results = []
      EM.run do
        client = Mysql2::EM::Client.new
        defer1 = client.query "SELECT sleep(0.025) as first_query"
        defer1.callback do |result|
          results << result.first
          defer2 = client.query "SELECT sleep(0.025) as second_query"
          defer2.callback do |result|
            results << result.first
            EM.stop_event_loop
          end
        end
      end

      results[0].keys.should include("first_query")
      results[1].keys.should include("second_query")
    end
  end
rescue LoadError
  puts "EventMachine not installed, skipping the specs that use it"
end

Version data entries

16 entries across 16 versions & 4 rubygems

Version Path
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.11/spec/em/em_spec.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.11/spec/em/em_spec.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.11/spec/em/em_spec.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.11/spec/em/em_spec.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.11/spec/em/em_spec.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.11/spec/em/em_spec.rb
mysql2-sp-0.3.10 spec/em/em_spec.rb
solaris-mysql2-0.3.11 spec/em/em_spec.rb
mysql2-0.3.11-x86-mswin32-60 spec/em/em_spec.rb
mysql2-0.3.11-x86-mingw32 spec/em/em_spec.rb
mysql2-0.3.11 spec/em/em_spec.rb
mysql2-0.3.10 spec/em/em_spec.rb
mysql2-0.3.9 spec/em/em_spec.rb
mysql2-0.3.9-x86-mswin32-60 spec/em/em_spec.rb
mysql2-0.3.9-x86-mingw32 spec/em/em_spec.rb
mysql2-0.3.8 spec/em/em_spec.rb