From d1433a549e4dd0fa1bbfe0e43f696a04928da3e2 Mon Sep 17 00:00:00 2001 From: Roger Pack Date: Tue, 21 Apr 2009 02:13:24 +0000 Subject: [PATCH] attempt to not blow up on ctrl+c during connect--that might have been a problem --- ext/mysql.c | 2 +- test/connect_failure2_test.rb | 16 ++++++++++++++++ .../{test_failure.rb => connect_failure_test.rb} | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/connect_failure2_test.rb rename test/{test_failure.rb => connect_failure_test.rb} (99%) diff --git a/ext/mysql.c b/ext/mysql.c index 297c4d6..1c61640 100644 --- a/ext/mysql.c +++ b/ext/mysql.c @@ -389,7 +389,7 @@ static VALUE real_connect(int argc, VALUE* argv, VALUE klass) /* actually gets r #if MYSQL_VERSION_ID >= 32200 mysql_init(&myp->handler); /* we get here */ # ifdef HAVE_TBR - if( (int) rb_thread_blocking_region_variable_params(10, &mysql_real_connect, 8, &myp->handler, h, u, p, d, pp, s, f) == NULL) + if( (int) rb_thread_blocking_region_variable_params(10, &mysql_real_connect, RUBY_UBF_IO, &myp->handler, h, u, p, d, pp, s, f) == NULL) # else if(mysql_real_connect(&myp->handler, h, u, p, d, pp, s, f) == NULL) # endif diff --git a/test/connect_failure2_test.rb b/test/connect_failure2_test.rb new file mode 100644 index 0000000..c792bdc --- /dev/null +++ b/test/connect_failure2_test.rb @@ -0,0 +1,16 @@ +if RUBY_VERSION >= "1.9.1" + require 'mysqlplus' + require 'socket' + TCPServer.new '0.0.0.0', 8001 + require 'timeout' + Timeout::timeout(1) { + # uncomment this line to do the 'real' test + # which hangs otherwise (blows up if code is bad, otherwise hangs) + # Mysql.real_connect '127.0.0.1', 'root', 'pass', 'db', 8000 + } + Thread.new { Mysql.real_connect '127.0.0.1', 'root', 'pass', 'db', 8001 } + sleep 1 + print "pass" + system("kill -9 #{Process.pid}") +end + diff --git a/test/test_failure.rb b/test/connect_failure_test.rb similarity index 99% rename from test/test_failure.rb rename to test/connect_failure_test.rb index 48fcf39..102f12b 100644 --- a/test/test_failure.rb +++ b/test/connect_failure_test.rb @@ -11,6 +11,7 @@ begin Mysql.real_connect('localhost', 'root', 'pass', 'db', 3307)# bad port rescue Mysql::Error end + print "pass"