@@ -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,42 @@ 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 is_linux ()
487
+ local os_name
488
+ if jit and jit .os then
489
+ os_name = jit .os
490
+ end
491
+ os_name = (os_name ):lower ()
492
+ if os_name :match (' linux' ) then
493
+ return true
494
+ end
495
+ return false
496
+ end
497
+
498
+ local function test_underlying_conn_closed_during_gc (test )
499
+ test :plan (1 )
500
+ if jit .os == ' Linux' then
501
+ local fh = fio .open (' /dev/zero' , {' O_RDONLY' })
502
+ if fh == nil then error (err ) end
503
+ local handle = fh .fh
504
+ fh :close ()
505
+ local conn , err = mysql .connect ({ host = host , port = port , user = user ,
506
+ password = password , db = db })
507
+ if conn == nil then error (err ) end
508
+
509
+ -- Somehow we lost the connection handle.
510
+ conn = nil
511
+ collectgarbage ()
512
+ ffi .cdef ([[ int fcntl(int fd, int cmd, ...); ]] )
513
+ local F_GETFD = 1
514
+ test :ok (ffi .C .fcntl (handle , F_GETFD ) == - 1 , ' descriptor is closed' )
515
+ else
516
+ test :skip (1 , ' wrong OS' )
517
+ end
518
+ end
519
+
484
520
local test = tap .test (' mysql connector' )
485
- test :plan (7 )
521
+ test :plan (8 )
486
522
487
523
test :test (' connection old api' , test_old_api , conn )
488
524
local pool_conn = p :get ()
@@ -492,6 +528,8 @@ test:test('concurrent connections', test_conn_concurrent, p)
492
528
test :test (' int64' , test_mysql_int64 , p )
493
529
test :test (' connection pool' , test_connection_pool , p )
494
530
test :test (' connection reset' , test_connection_reset , p )
531
+ test :test (' test_underlying_conn_closed_during_gc' ,
532
+ test_underlying_conn_closed_during_gc , p )
495
533
p :close ()
496
534
497
535
os.exit (test :check () and 0 or 1 )
0 commit comments