You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
test:test('get, broke and put a connection', function(test)
test:plan(2)
assert(pool.size>=1, 'test case precondition fails')
-- Get a connection and make a bad query.
localconn=pool:get()
localok=pcall(conn.execute, conn, 'bad query')
test:ok(notok, 'a query actually fails')
-- Put the connection back and verify that the pool is full.
pool:put(conn)
test:ok(pool.queue:is_full(), 'a broken connection was given back')
end)
-- Case: the same, but loss and collect a connection after
-- put.
test:test('get, broke, put and loss a connection', function(test)
test:plan(3)
assert(pool.size>=1, 'test case precondition fails')
-- Get a connection and make a bad query.
localconn=pool:get()
localok=pcall(conn.execute, conn, 'bad query')
test:ok(notok, 'a query actually fails')
-- Put the connection back, loss it and trigger GC.
pool:put(conn)
conn=nil-- luacheck: no unused
collectgarbage('collect')
-- Verify that the pool is full
test:ok(pool.queue:is_full(), 'a broken connection was given back')
-- Verify the pool will not be populated by a connection's
-- GC callback. Otherwise :put() will hang.
localitem=pool.queue:get()
pool.queue:put(item)
test:ok(true, 'GC callback does not put back a connection that was ' ..
'put manually')
end)
My initial assumption was that any SQL error (including syntax error) will lead to marking the connection as broken, however it is not so. Only CR_SERVER_LOST or CR_SERVER_GONE_ERROR errors matter here:
Just observed that my test cases for broken connections actually act on healthy connections. I mean the following cases:
mysql/test/mysql.test.lua
Lines 96 to 114 in 2d22046
mysql/test/mysql.test.lua
Lines 312 to 354 in 2d22046
My initial assumption was that any SQL error (including syntax error) will lead to marking the connection as broken, however it is not so. Only CR_SERVER_LOST or CR_SERVER_GONE_ERROR errors matter here:
mysql/mysql/driver.c
Lines 149 to 157 in 2d22046
mysql/mysql/init.lua
Lines 71 to 74 in 2d22046
It seems we should find a way to broke a connection from a test. It seems that support of an error injection is needed for Debug build.
The text was updated successfully, but these errors were encountered: