Introduce test case for Mysql2::Client in multi-threaded environments

This commit is contained in:
Lourens Naudé 2010-08-07 21:52:46 +01:00 committed by Brian Lopez
parent 9f19b958b0
commit c5d9b7ff65
2 changed files with 15 additions and 0 deletions

View File

@ -176,6 +176,20 @@ describe Mysql2::Client do
}.should_not raise_error(Mysql2::Error) }.should_not raise_error(Mysql2::Error)
end 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 it "evented async queries should be supported" do
# should immediately return nil # should immediately return nil
@client.query("SELECT sleep(0.1)", :async => true).should eql(nil) @client.query("SELECT sleep(0.1)", :async => true).should eql(nil)

View File

@ -3,6 +3,7 @@ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib') $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
require 'mysql2' require 'mysql2'
require 'timeout'
Spec::Runner.configure do |config| Spec::Runner.configure do |config|
config.before(:all) do config.before(:all) do