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:
Lourens Naude 2008-09-08 17:27:11 +01:00
parent f6f460a542
commit ea2965270c
6 changed files with 11 additions and 27 deletions

View File

@ -31,6 +31,10 @@ else
exit 1
end
if have_func('rb_thread_blocking_region') and have_macro('RB_UBF_DFL', 'ruby.h')
flags << "-DHAVE_TBR"
end
# make mysql constant
File.open("conftest.c", "w") do |f|
f.puts src

View File

@ -2143,7 +2143,7 @@ void Init_mysql(void)
#endif
rb_define_method(cMysql, "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, "get_result", get_result, 0);
rb_define_method(cMysql, "readable?", readable, -1);

View File

@ -2,11 +2,7 @@ require 'mysql'
class Mysql
alias_method :c_async_query, :async_query
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)
select [ (@sockets ||= {})[socket] ||= IO.new(socket) ], nil, nil, nil
get_result

View File

@ -2,12 +2,5 @@ require File.dirname(__FILE__) + '/test_helper'
EventedMysqlTest.new( 10 ) do |test|
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!
end

View File

@ -28,10 +28,8 @@ class MysqlTest
def run!
c_or_native_ruby_async_query do
with_blocking_status do
prepare
yield
end
prepare
yield
end
end
@ -61,22 +59,16 @@ class MysqlTest
def c_or_native_ruby_async_query
if @c_async_query
ENV['MYSQL_C_ASYNC_QUERY'] = '1'
log "** using C based async_query"
else
ENV['MYSQL_C_ASYNC_QUERY'] = '0'
log "** using native Ruby async_query"
end
yield
end
def with_blocking_status
if @log_blocking_status
ENV['MYSQL_BLOCKING_STATUS'] = '1'
else
ENV['MYSQL_BLOCKING_STATUS'] = '0'
end
yield
def c_or_native_async_query( connection, sql, timeout = nil )
method = @c_async_query ? :c_async_query : :async_query
connection.send( method, sql, timeout )
end
end
@ -174,7 +166,7 @@ class ThreadedMysqlTest < MysqlTest
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"
end

View File

@ -2,7 +2,6 @@ require File.dirname(__FILE__) + '/test_helper'
ThreadedMysqlTest.new( 10 ) do |test|
test.setup{ Mysql.real_connect('localhost','root') }
test.log_blocking_status = true
test.run!
end