@@ -17,8 +17,9 @@ if conn == nil then error(err) end
17
17
18
18
local p , err = mysql .pool_create ({ host = host , port = port , user = user ,
19
19
password = password , db = db , size = 2 })
20
+ if p == nil then error (err ) end
20
21
21
- function test_old_api (t , conn )
22
+ local function test_old_api (t , conn )
22
23
t :plan (16 )
23
24
-- Add an extension to 'tap' module
24
25
getmetatable (t ).__index .q = function (test , stmt , result , ...)
@@ -63,12 +64,12 @@ function test_old_api(t, conn)
63
64
end )
64
65
65
66
t :q (' DROP TABLE IF EXISTS unknown_table' , nil )
66
- local status , reason = pcall (conn .execute , conn , ' DROP TABLE unknown_table' )
67
+ local _ , reason = pcall (conn .execute , conn , ' DROP TABLE unknown_table' )
67
68
t :like (reason , ' unknown_table' , ' error' )
68
69
t :ok (conn :close (), " close" )
69
70
end
70
71
71
- function test_gc (test , pool )
72
+ local function test_gc (test , pool )
72
73
test :plan (3 )
73
74
74
75
-- Case: verify that a pool tracks connections that are not
@@ -82,7 +83,7 @@ function test_gc(test, pool)
82
83
pool :get ()
83
84
84
85
-- Loss another one.
85
- local conn = pool :get ()
86
+ local conn = pool :get () -- luacheck: no unused
86
87
conn = nil
87
88
88
89
-- Collect lost connections.
@@ -103,7 +104,7 @@ function test_gc(test, pool)
103
104
local conn = pool :get ()
104
105
local ok = pcall (conn .execute , conn , ' bad query' )
105
106
test :ok (not ok , ' a query actually fails' )
106
- conn = nil
107
+ conn = nil -- luacheck: no unused
107
108
108
109
-- Collect the lost connection.
109
110
collectgarbage (' collect' )
@@ -121,7 +122,7 @@ function test_gc(test, pool)
121
122
-- Get a connection, close it and loss the connection.
122
123
local conn = pool :get ()
123
124
conn :close ()
124
- conn = nil
125
+ conn = nil -- luacheck: no unused
125
126
126
127
-- Collect the lost connection.
127
128
collectgarbage (' collect' )
@@ -131,21 +132,21 @@ function test_gc(test, pool)
131
132
end )
132
133
end
133
134
134
- function test_conn_fiber1 (c , q )
135
- for i = 1 , 10 do
135
+ local function test_conn_fiber1 (c , q )
136
+ for _ = 1 , 10 do
136
137
c :execute (' SELECT sleep(0.05)' )
137
138
end
138
139
q :put (true )
139
140
end
140
141
141
- function test_conn_fiber2 (c , q )
142
- for i = 1 , 25 do
142
+ local function test_conn_fiber2 (c , q )
143
+ for _ = 1 , 25 do
143
144
c :execute (' SELECT sleep(0.02)' )
144
145
end
145
146
q :put (true )
146
147
end
147
148
148
- function test_conn_concurrent (t , p )
149
+ local function test_conn_concurrent (t , p )
149
150
t :plan (1 )
150
151
local c = p :get ()
151
152
local q = fiber .channel (2 )
@@ -158,13 +159,12 @@ function test_conn_concurrent(t, p)
158
159
t :ok (fiber .time () - t1 >= 0.95 , ' concurrent connections' )
159
160
end
160
161
161
-
162
- function test_mysql_int64 (t , p )
162
+ local function test_mysql_int64 (t , p )
163
163
t :plan (1 )
164
- conn = p :get ()
164
+ local conn = p :get ()
165
165
conn :execute (' create table int64test (id bigint)' )
166
166
conn :execute (' insert into int64test values(1234567890123456789)' )
167
- local d , s = conn :execute (' select id from int64test' )
167
+ local d , _ = conn :execute (' select id from int64test' )
168
168
conn :execute (' drop table int64test' )
169
169
t :ok (d [1 ][1 ][' id' ] == 1234567890123456789 LL, ' int64 test' )
170
170
p :put (conn )
@@ -179,7 +179,7 @@ local function test_connection_pool(test, pool)
179
179
180
180
-- Grab all connections from a pool.
181
181
local connections = {}
182
- for i = 1 , pool .size do
182
+ for _ = 1 , pool .size do
183
183
table.insert (connections , pool :get ())
184
184
end
185
185
@@ -206,7 +206,7 @@ local function test_connection_pool(test, pool)
206
206
207
207
-- Restore everything as it was.
208
208
table.insert (connections , conn )
209
- conn = nil
209
+ conn = nil -- luacheck: no unused
210
210
211
211
assert (pool .queue :is_empty (), ' test case postcondition fails' )
212
212
end )
@@ -295,7 +295,7 @@ local function test_connection_pool(test, pool)
295
295
296
296
-- Put the connection back, loss it and trigger GC.
297
297
pool :put (conn )
298
- conn = nil
298
+ conn = nil -- luacheck: no unused
299
299
collectgarbage (' collect' )
300
300
301
301
-- Verify that the pool is full.
@@ -339,7 +339,7 @@ local function test_connection_pool(test, pool)
339
339
340
340
-- Put the connection back, loss it and trigger GC.
341
341
pool :put (conn )
342
- conn = nil
342
+ conn = nil -- luacheck: no unused
343
343
collectgarbage (' collect' )
344
344
345
345
-- Verify that the pool is full
0 commit comments