diff --git a/spec/mysql2/client_spec.rb b/spec/mysql2/client_spec.rb index a6ff3c7..7c5c8ce 100644 --- a/spec/mysql2/client_spec.rb +++ b/spec/mysql2/client_spec.rb @@ -176,6 +176,20 @@ describe Mysql2::Client do }.should_not raise_error(Mysql2::Error) end + it "threaded queries should be supported" do + threads, results = [], {} + connect = lambda{ Mysql2::Client.new(:host => "localhost", :username => "root") } + Timeout.timeout(0.7) do + 5.times { + threads << Thread.new do + results[Thread.current.object_id] = connect.call.query("SELECT sleep(0.5) as result") + end + } + end + threads.each{|t| t.join } + results.keys.sort.should eql(threads.map{|t| t.object_id }.sort) + end + it "evented async queries should be supported" do # should immediately return nil @client.query("SELECT sleep(0.1)", :async => true).should eql(nil) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b50e6cc..0063bb7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,6 +3,7 @@ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..') $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib') require 'mysql2' +require 'timeout' Spec::Runner.configure do |config| config.before(:all) do