Decouple native Ruby Mysql#async_query from the C extension as per Roger's suggestion.Remove no-op c_mysql_query flag for evented tests.
This commit is contained in:
parent
f6f460a542
commit
ea2965270c
@ -31,6 +31,10 @@ else
|
|||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if have_func('rb_thread_blocking_region') and have_macro('RB_UBF_DFL', 'ruby.h')
|
||||||
|
flags << "-DHAVE_TBR"
|
||||||
|
end
|
||||||
|
|
||||||
# make mysql constant
|
# make mysql constant
|
||||||
File.open("conftest.c", "w") do |f|
|
File.open("conftest.c", "w") do |f|
|
||||||
f.puts src
|
f.puts src
|
||||||
|
@ -2143,7 +2143,7 @@ void Init_mysql(void)
|
|||||||
#endif
|
#endif
|
||||||
rb_define_method(cMysql, "query", query, 1);
|
rb_define_method(cMysql, "query", query, 1);
|
||||||
rb_define_method(cMysql, "real_query", query, 1);
|
rb_define_method(cMysql, "real_query", query, 1);
|
||||||
rb_define_method(cMysql, "async_query", async_query, -1);
|
rb_define_method(cMysql, "c_async_query", async_query, -1);
|
||||||
rb_define_method(cMysql, "send_query", send_query, 1);
|
rb_define_method(cMysql, "send_query", send_query, 1);
|
||||||
rb_define_method(cMysql, "get_result", get_result, 0);
|
rb_define_method(cMysql, "get_result", get_result, 0);
|
||||||
rb_define_method(cMysql, "readable?", readable, -1);
|
rb_define_method(cMysql, "readable?", readable, -1);
|
||||||
|
@ -2,11 +2,7 @@ require 'mysql'
|
|||||||
|
|
||||||
class Mysql
|
class Mysql
|
||||||
|
|
||||||
alias_method :c_async_query, :async_query
|
|
||||||
|
|
||||||
def async_query(sql, timeout = nil)
|
def async_query(sql, timeout = nil)
|
||||||
puts "** Blocking ? #{blocking?().inspect}" if ENV['MYSQL_BLOCKING_STATUS'] == '1'
|
|
||||||
return c_async_query(sql, timeout) if ENV['MYSQL_C_ASYNC_QUERY'] == '1'
|
|
||||||
send_query(sql)
|
send_query(sql)
|
||||||
select [ (@sockets ||= {})[socket] ||= IO.new(socket) ], nil, nil, nil
|
select [ (@sockets ||= {})[socket] ||= IO.new(socket) ], nil, nil, nil
|
||||||
get_result
|
get_result
|
||||||
|
@ -2,12 +2,5 @@ require File.dirname(__FILE__) + '/test_helper'
|
|||||||
|
|
||||||
EventedMysqlTest.new( 10 ) do |test|
|
EventedMysqlTest.new( 10 ) do |test|
|
||||||
test.setup{ Mysql.real_connect('localhost','root') }
|
test.setup{ Mysql.real_connect('localhost','root') }
|
||||||
test.log_blocking_status = true
|
|
||||||
test.run!
|
|
||||||
end
|
|
||||||
|
|
||||||
EventedMysqlTest.new( 10 ) do |test|
|
|
||||||
test.setup{ Mysql.real_connect('localhost','root') }
|
|
||||||
test.c_async_query = true
|
|
||||||
test.run!
|
test.run!
|
||||||
end
|
end
|
@ -28,10 +28,8 @@ class MysqlTest
|
|||||||
|
|
||||||
def run!
|
def run!
|
||||||
c_or_native_ruby_async_query do
|
c_or_native_ruby_async_query do
|
||||||
with_blocking_status do
|
prepare
|
||||||
prepare
|
yield
|
||||||
yield
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -61,22 +59,16 @@ class MysqlTest
|
|||||||
|
|
||||||
def c_or_native_ruby_async_query
|
def c_or_native_ruby_async_query
|
||||||
if @c_async_query
|
if @c_async_query
|
||||||
ENV['MYSQL_C_ASYNC_QUERY'] = '1'
|
|
||||||
log "** using C based async_query"
|
log "** using C based async_query"
|
||||||
else
|
else
|
||||||
ENV['MYSQL_C_ASYNC_QUERY'] = '0'
|
|
||||||
log "** using native Ruby async_query"
|
log "** using native Ruby async_query"
|
||||||
end
|
end
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_blocking_status
|
def c_or_native_async_query( connection, sql, timeout = nil )
|
||||||
if @log_blocking_status
|
method = @c_async_query ? :c_async_query : :async_query
|
||||||
ENV['MYSQL_BLOCKING_STATUS'] = '1'
|
connection.send( method, sql, timeout )
|
||||||
else
|
|
||||||
ENV['MYSQL_BLOCKING_STATUS'] = '0'
|
|
||||||
end
|
|
||||||
yield
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -174,7 +166,7 @@ class ThreadedMysqlTest < MysqlTest
|
|||||||
|
|
||||||
log "sending query on connection #{conn}"
|
log "sending query on connection #{conn}"
|
||||||
|
|
||||||
@connections[conn].async_query( "select sleep(3)" ).each do |result|
|
c_or_native_async_query( @connections[conn], "select sleep(3)" ).each do |result|
|
||||||
log "connection #{conn} done"
|
log "connection #{conn} done"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ require File.dirname(__FILE__) + '/test_helper'
|
|||||||
|
|
||||||
ThreadedMysqlTest.new( 10 ) do |test|
|
ThreadedMysqlTest.new( 10 ) do |test|
|
||||||
test.setup{ Mysql.real_connect('localhost','root') }
|
test.setup{ Mysql.real_connect('localhost','root') }
|
||||||
test.log_blocking_status = true
|
|
||||||
test.run!
|
test.run!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user