Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit ea2965270c89b30b00831673e4c09cdd9fc8ce67 1 parent f6f460a
Lourens Naudé authored September 08, 2008
4  ext/extconf.rb
@@ -31,6 +31,10 @@
31 31
   exit 1
32 32
 end
33 33
 
  34
+if have_func('rb_thread_blocking_region') and have_macro('RB_UBF_DFL', 'ruby.h')
  35
+  flags << "-DHAVE_TBR"
  36
+end
  37
+
34 38
 # make mysql constant
35 39
 File.open("conftest.c", "w") do |f|
36 40
   f.puts src
2  ext/mysql.c
@@ -2143,7 +2143,7 @@ void Init_mysql(void)
2143 2143
 #endif
2144 2144
     rb_define_method(cMysql, "query", query, 1);
2145 2145
     rb_define_method(cMysql, "real_query", query, 1);
2146  
-    rb_define_method(cMysql, "async_query", async_query, -1);
  2146
+    rb_define_method(cMysql, "c_async_query", async_query, -1);
2147 2147
     rb_define_method(cMysql, "send_query", send_query, 1);
2148 2148
     rb_define_method(cMysql, "get_result", get_result, 0);
2149 2149
     rb_define_method(cMysql, "readable?", readable, -1);
4  lib/mysqlplus.rb
@@ -2,11 +2,7 @@
2 2
 
3 3
 class Mysql
4 4
   
5  
-  alias_method :c_async_query, :async_query
6  
-
7 5
   def async_query(sql, timeout = nil)
8  
-    puts "** Blocking ? #{blocking?().inspect}" if ENV['MYSQL_BLOCKING_STATUS'] == '1'
9  
-    return c_async_query(sql, timeout) if ENV['MYSQL_C_ASYNC_QUERY'] == '1'
10 6
     send_query(sql)
11 7
     select [ (@sockets ||= {})[socket] ||= IO.new(socket) ], nil, nil, nil
12 8
     get_result
7  test/evented_test.rb
@@ -2,12 +2,5 @@
2 2
 
3 3
 EventedMysqlTest.new( 10 ) do |test|
4 4
   test.setup{ Mysql.real_connect('localhost','root') }
5  
-  test.log_blocking_status = true
6  
-  test.run!
7  
-end
8  
-
9  
-EventedMysqlTest.new( 10 ) do |test|
10  
-  test.setup{ Mysql.real_connect('localhost','root') }
11  
-  test.c_async_query = true
12 5
   test.run!
13 6
 end
20  test/test_helper.rb
@@ -28,10 +28,8 @@ def setup( &block )
28 28
   
29 29
   def run!
30 30
     c_or_native_ruby_async_query do
31  
-      with_blocking_status do
32  
-        prepare
33  
-        yield
34  
-      end  
  31
+      prepare
  32
+      yield
35 33
     end  
36 34
   end
37 35
   
@@ -61,22 +59,16 @@ def timestamp
61 59
   
62 60
   def c_or_native_ruby_async_query
63 61
     if @c_async_query
64  
-      ENV['MYSQL_C_ASYNC_QUERY'] = '1'
65 62
       log "** using C based async_query"
66 63
     else
67  
-      ENV['MYSQL_C_ASYNC_QUERY'] = '0'
68 64
       log "** using native Ruby async_query"
69 65
     end
70 66
     yield
71 67
   end
72 68
   
73  
-  def with_blocking_status
74  
-    if @log_blocking_status
75  
-      ENV['MYSQL_BLOCKING_STATUS'] = '1'
76  
-    else
77  
-      ENV['MYSQL_BLOCKING_STATUS'] = '0'
78  
-    end
79  
-    yield
  69
+  def c_or_native_async_query( connection, sql, timeout = nil )
  70
+    method = @c_async_query ? :c_async_query : :async_query
  71
+    connection.send( method, sql, timeout )
80 72
   end
81 73
   
82 74
 end
@@ -174,7 +166,7 @@ def prepare
174 166
 
175 167
           log "sending query on connection #{conn}"
176 168
 
177  
-          @connections[conn].async_query( "select sleep(3)" ).each do |result|
  169
+          c_or_native_async_query( @connections[conn], "select sleep(3)" ).each do |result|
178 170
             log "connection #{conn} done"
179 171
           end 
180 172
         
1  test/threaded_test.rb
@@ -2,7 +2,6 @@
2 2
 
3 3
 ThreadedMysqlTest.new( 10 ) do |test|
4 4
   test.setup{ Mysql.real_connect('localhost','root') }
5  
-  test.log_blocking_status = true
6 5
   test.run!
7 6
 end
8 7
 

0 notes on commit ea29652

Please sign in to comment.
Something went wrong with that request. Please try again.