Skip to content

Commit cedb080

Browse files
committed
test: make sure that underlying connection is closed
1 parent 6f785f7 commit cedb080

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

test/mysql.test.lua

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ local mysql = require('mysql')
77
local json = require('json')
88
local tap = require('tap')
99
local fiber = require('fiber')
10+
local fio = require('fio')
11+
local ffi = require('ffi')
1012

1113
local 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')
482484
end
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+
484503
local test = tap.test('mysql connector')
485-
test:plan(7)
504+
test:plan(8)
486505

487506
test:test('connection old api', test_old_api, conn)
488507
local pool_conn = p:get()
@@ -492,6 +511,7 @@ test:test('concurrent connections', test_conn_concurrent, p)
492511
test:test('int64', test_mysql_int64, p)
493512
test:test('connection pool', test_connection_pool, p)
494513
test:test('connection reset', test_connection_reset, p)
514+
test:test('test_underlying_conn_closed', test_underlying_conn_closed, p)
495515
p:close()
496516

497517
os.exit(test:check() and 0 or 1)

0 commit comments

Comments
 (0)