@@ -7,6 +7,8 @@ local mysql = require('mysql')
77local json = require (' json' )
88local tap = require (' tap' )
99local fiber = require (' fiber' )
10+ local fio = require (' fio' )
11+ local ffi = require (' ffi' )
1012
1113local host , port , user , password , db = string.match (os.getenv (' MYSQL' ) or ' ' ,
1214 " ([^:]*):([^:]*):([^:]*):([^:]*):([^:]*)" )
@@ -481,8 +483,25 @@ local function test_connection_reset(test, pool)
481483 assert (pool .queue :is_full (), ' test case postcondition fails' )
482484end
483485
486+ local function test_underlying_conn_closed (test )
487+ test :plan (1 )
488+ local fh = fio .open (' /dev/zero' , {' O_RDONLY' })
489+ if fh == nil then error (err ) end
490+ local handle = fh .fh
491+ fh :close ()
492+ local conn , err = mysql .connect ({ host = host , port = port , user = user ,
493+ password = password , db = db })
494+ if conn == nil then error (err ) end
495+
496+ -- Somehow we lost the connection handle.
497+ conn = nil
498+ collectgarbage ()
499+ ffi .cdef ([[ int fcntl(int fd, int cmd, ...); ]] )
500+ test :ok (ffi .C .fcntl (handle , 1 ) == - 1 , ' descriptor is closed' )
501+ end
502+
484503local test = tap .test (' mysql connector' )
485- test :plan (7 )
504+ test :plan (8 )
486505
487506test :test (' connection old api' , test_old_api , conn )
488507local pool_conn = p :get ()
@@ -492,6 +511,7 @@ test:test('concurrent connections', test_conn_concurrent, p)
492511test :test (' int64' , test_mysql_int64 , p )
493512test :test (' connection pool' , test_connection_pool , p )
494513test :test (' connection reset' , test_connection_reset , p )
514+ test :test (' test_underlying_conn_closed' , test_underlying_conn_closed , p )
495515p :close ()
496516
497517os.exit (test :check () and 0 or 1 )
0 commit comments