Permalink
Browse files

Decouple native Ruby Mysql#async_query from the C extension as per Ro…

…ger's suggestion.Remove no-op c_mysql_query flag for evented tests.
  • Loading branch information...
methodmissing committed Sep 8, 2008
1 parent f6f460a commit ea2965270c89b30b00831673e4c09cdd9fc8ce67
Showing with 11 additions and 27 deletions.
  1. +4 −0 ext/extconf.rb
  2. +1 −1 ext/mysql.c
  3. +0 −4 lib/mysqlplus.rb
  4. +0 −7 test/evented_test.rb
  5. +6 −14 test/test_helper.rb
  6. +0 −1 test/threaded_test.rb
View
@@ -31,6 +31,10 @@
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
@@ -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
@@ -2,11 +2,7 @@
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
@@ -2,12 +2,5 @@
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
@@ -28,10 +28,8 @@ def setup( &block )
def run!
c_or_native_ruby_async_query do
- with_blocking_status do
- prepare
- yield
- end
+ prepare
+ yield
end
end
@@ -61,22 +59,16 @@ def timestamp
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 @@ def prepare
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
@@ -2,7 +2,6 @@
ThreadedMysqlTest.new( 10 ) do |test|
test.setup{ Mysql.real_connect('localhost','root') }
- test.log_blocking_status = true
test.run!
end

0 comments on commit ea29652

Please sign in to comment.