@@ -7,6 +7,8 @@ local mysql = require('mysql')
7
7
local json = require (' json' )
8
8
local tap = require (' tap' )
9
9
local fiber = require (' fiber' )
10
+ local fio = require (' fio' )
11
+ local ffi = require (' ffi' )
10
12
11
13
local host , port , user , password , db = string.match (os.getenv (' MYSQL' ) or ' ' ,
12
14
" ([^:]*):([^:]*):([^:]*):([^:]*):([^:]*)" )
@@ -481,8 +483,25 @@ local function test_connection_reset(test, pool)
481
483
assert (pool .queue :is_full (), ' test case postcondition fails' )
482
484
end
483
485
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
+
484
503
local test = tap .test (' mysql connector' )
485
- test :plan (7 )
504
+ test :plan (8 )
486
505
487
506
test :test (' connection old api' , test_old_api , conn )
488
507
local pool_conn = p :get ()
@@ -492,6 +511,7 @@ test:test('concurrent connections', test_conn_concurrent, p)
492
511
test :test (' int64' , test_mysql_int64 , p )
493
512
test :test (' connection pool' , test_connection_pool , p )
494
513
test :test (' connection reset' , test_connection_reset , p )
514
+ test :test (' test_underlying_conn_closed' , test_underlying_conn_closed , p )
495
515
p :close ()
496
516
497
517
os.exit (test :check () and 0 or 1 )
0 commit comments