[Tarantool-patches] [PATCH v7 3/3] luacheck: fix warnings in test/box-tap

sergeyb at tarantool.org sergeyb at tarantool.org
Tue Dec 22 17:54:22 MSK 2020


From: Sergey Bronnikov <sergeyb at tarantool.org>

Closes #5457

Reviewed-by: Vladislav Shpilevoy <v.shpilevoy at tarantool.org>
Reviewed-by: Igor Munkin <imun at tarantool.org>

Co-authored-by: Vladislav Shpilevoy <v.shpilevoy at tarantool.org>
Co-authored-by: Igor Munkin <imun at tarantool.org>
---
 .luacheckrc                                   | 21 ++++++-
 test/box-tap/auth.test.lua                    | 20 ++-----
 test/box-tap/cfg.test.lua                     | 34 +++++------
 test/box-tap/cfgup.test.lua                   |  4 +-
 test/box-tap/extended_error.test.lua          | 11 ++--
 test/box-tap/feedback_daemon.test.lua         |  8 +--
 test/box-tap/gc.test.lua                      |  4 +-
 test/box-tap/gh-4688-box-info-memory.test.lua |  2 +-
 test/box-tap/on_schema_init.test.lua          |  4 +-
 test/box-tap/schema_mt.test.lua               | 22 ++++----
 test/box-tap/session.storage.test.lua         | 10 ++--
 test/box-tap/session.test.lua                 | 56 +++++++++----------
 test/box-tap/trigger_atexit.test.lua          | 10 ++--
 test/box-tap/trigger_yield.test.lua           | 10 ++--
 14 files changed, 112 insertions(+), 104 deletions(-)

diff --git a/.luacheckrc b/.luacheckrc
index 52625bb35..b7f9abb45 100644
--- a/.luacheckrc
+++ b/.luacheckrc
@@ -39,7 +39,6 @@ exclude_files = {
     "test/box/lua/require_mod.lua",
     -- Unused source file, to be dropped (gh-5169).
     "test/box/lua/test_init.lua",
-    "test/box-tap/**/*.lua",
     "test/engine/**/*.lua",
     "test/engine_long/**/*.lua",
     "test/long_run-py/**/*.lua",
@@ -157,3 +156,23 @@ files["test/box/lua/fifo.lua"] = {
 files["test/box/lua/identifier.lua"] = {
      globals = {"run_test"}
 }
+files["test/box-tap/session.test.lua"] = {
+    globals = {
+        "active_connections",
+        "session",
+        "space",
+        "f1",
+        "f2",
+    },
+}
+files["test/box-tap/extended_error.test.lua"] = {
+    globals = {
+        "error_access_denied",
+        "error_new",
+        "error_new_stacked",
+        "error_throw",
+        "error_throw_stacked",
+        "error_throw_access_denied",
+        "forbidden_function",
+    },
+}
diff --git a/test/box-tap/auth.test.lua b/test/box-tap/auth.test.lua
index 4e9879408..c6de6ff82 100755
--- a/test/box-tap/auth.test.lua
+++ b/test/box-tap/auth.test.lua
@@ -18,22 +18,22 @@ local test = tap.test("auth")
 test:plan(42)
 
 local space = box.schema.space.create('tweedledum')
-local index = space:create_index('primary', { type = 'hash' })
+space:create_index('primary', { type = 'hash' })
 box.schema.user.create('test', {password='pass'})
 box.schema.user.create('test2', {password=''})
 
 -- check how authentication trigger work
 local msg, counter, succeeded
-function auth_trigger(user_name)
+local function auth_trigger(user_name) -- luacheck: no unused args
     counter = counter + 1
 end
 -- get user name as argument
-function auth_trigger2(user_name)
+local function auth_trigger2(user_name) -- luacheck: no unused args
     msg = 'user ' .. user_name .. ' is there'
 end
 -- get user name and result of authentication as arguments
-function auth_trigger3(user_name, success)
-        succeeded = success
+local function auth_trigger3(user_name, success) -- luacheck: no unused args
+    succeeded = success
 end
 -- set trigger
 local handle = session.on_auth(auth_trigger)
@@ -57,7 +57,6 @@ test:is(counter, 1, "on_auth has been fired once")
 test:is(msg, "user test is there", "on_auth username param")
 test:ok(succeeded, "on_auth success param")
 conn:close()
-conn = nil
 
 -- check failing authentication
 counter = 0
@@ -68,7 +67,6 @@ test:is(counter, 1, "on_auth has been fired once")
 test:is(msg, "user test is there", "on_auth username param")
 test:ok(not succeeded, "on_auth success param")
 conn:close()
-conn = nil
 
 counter = 0
 succeeded = false
@@ -78,7 +76,6 @@ test:is(counter, 1, "on_auth has been fired once")
 test:is(msg, "user test2 is there", "on_auth username param")
 test:ok(succeeded, "on_auth success param")
 conn:close()
-conn = nil
 
 counter = 0
 succeeded = false
@@ -88,7 +85,6 @@ test:is(counter, 1, "on_auth has been fired once")
 test:is(msg, "user test2 is there", "on_auth username param")
 test:ok(succeeded, "on_auth success param")
 conn:close()
-conn = nil
 
 counter = 0
 succeeded = false
@@ -98,7 +94,6 @@ test:is(counter, 1, "on_auth has been fired once")
 test:is(msg, "user test2 is there", "on_auth username param")
 test:ok(succeeded, "on_auth success param")
 conn:close()
-conn = nil
 
 counter = 0
 succeeded = false
@@ -108,7 +103,6 @@ test:is(counter, 1, "on_auth has been fired once")
 test:is(msg, "user guest is there", "on_auth username param")
 test:ok(succeeded, "on_auth success param")
 conn:close()
-conn = nil
 
 counter = 0
 succeeded = false
@@ -118,7 +112,6 @@ test:is(counter, 1, "on_auth has been fired once")
 test:is(msg, "user guest is there", "on_auth username param")
 test:ok(succeeded, "on_auth success param")
 conn:close()
-conn = nil
 
 counter = 0
 succeeded = false
@@ -128,7 +121,6 @@ test:is(counter, 1, "on_auth has been fired once")
 test:is(msg, "user guest is there", "on_auth username param")
 test:ok(succeeded, "on_auth success param")
 conn:close()
-conn = nil
 
 counter = 0
 succeeded = false
@@ -138,7 +130,6 @@ test:is(counter, 1, "on_auth has been fired once")
 test:is(msg, "user guest is there", "on_auth username param")
 test:ok(succeeded, "on_auth success param")
 conn:close()
-conn = nil
 
 -- check guest connection without authentication(no increment)
 counter = 0
@@ -148,7 +139,6 @@ conn:ping()
 test:is(counter, 0, "on_auth hasn't been fired")
 test:ok(not succeeded, "on_auth not successed param")
 conn:close()
-conn = nil
 
 test:isnil(session.on_auth(nil, auth_trigger), "removal returns nil")
 test:isnil(session.on_auth(nil, auth_trigger2), "removal returns nil")
diff --git a/test/box-tap/cfg.test.lua b/test/box-tap/cfg.test.lua
index 569b5f463..a577f023d 100755
--- a/test/box-tap/cfg.test.lua
+++ b/test/box-tap/cfg.test.lua
@@ -76,14 +76,14 @@ test:ok(not status and result:match('Please call box.cfg{}'),
     'exception on unconfigured box')
 
 status, result = pcall(box.error, box.error.ILLEGAL_PARAMS, 'xx')
-test:ok(result.code == box.error.ILLEGAL_PARAMS, "box.error without box.cfg")
+test:ok(not status and result.code == box.error.ILLEGAL_PARAMS, "box.error without box.cfg")
 status, result = pcall(function() return box.runtime.info() end)
 test:ok(status and type(result) == 'table', "box.runtime without box.cfg")
 status, result = pcall(function() return box.index.EQ end)
 test:ok(status and type(result) == 'number', "box.index without box.cfg")
 status, result = pcall(function() return box.NULL end)
 test:ok(status and result == msgpack.NULL, "box.NULL without box.cfg")
-status, result = pcall(box.session.id)
+status = pcall(box.session.id)
 test:ok(status, "box.session without box.cfg")
 status, result = pcall(box.tuple.new, {1, 2, 3})
 test:ok(status and result[1] == 1, "box.tuple without box.cfg")
@@ -145,13 +145,13 @@ test:is(box.cfg.too_long_threshold , 0.1, "too_long_threshold new value")
 test:is(box.cfg.read_only, false, "read_only default value")
 box.cfg{read_only = true}
 test:is(box.cfg.read_only, true, "read_only new value")
-local status, reason = pcall(function()
+local status = pcall(function()
     box.space._schema:insert({'read_only', 'test'})
 end)
 test:ok(not status and box.error.last().code == box.error.READONLY,
     "read_only = true")
 box.cfg{read_only = false}
-local status, reason = pcall(function()
+local status = pcall(function()
     box.space._schema:insert({'read_only', 'test'})
 end)
 test:ok(status, "read_only = false")
@@ -163,7 +163,7 @@ test:is(box.cfg.worker_pool_threads, 1, 'worker_pool_threads')
 
 local tarantool_bin = arg[-1]
 local PANIC = 256
-function run_script(code)
+local function run_script(code)
     local dir = fio.tempdir()
     local script_path = fio.pathjoin(dir, 'script.lua')
     local script = fio.open(script_path, {'O_CREAT', 'O_WRONLY', 'O_APPEND'},
@@ -178,7 +178,7 @@ function run_script(code)
 end
 
 -- gh-3468: should allow box.cfg with vinyl_memory=0
-code =[[
+local code =[[
 box.cfg{vinyl_memory=0}
 os.exit(box.cfg.vinyl_memory == 0 and 0 or 1)
 ]]
@@ -198,7 +198,6 @@ code = [[ box.cfg{ wal_mode = 'write' }; box.cfg { wal_mode = 'fsync'} ]]
 test:is(run_script(code), PANIC, 'wal_mode write -> fsync is not supported')
 
 -- gh-684: Inconsistency with box.cfg and directories
-local code;
 code = [[ box.cfg{ work_dir='invalid' } ]]
 test:is(run_script(code), PANIC, 'work_dir is invalid')
 
@@ -238,7 +237,7 @@ os.remove(path)
 
 path = './tarantool.sock'
 local path2 = './tarantool2.sock'
-local s = socket.tcp_server('unix/', path, function () end)
+s = socket.tcp_server('unix/', path, function () end)
 os.execute('ln ' .. path .. ' ' .. path2)
 s:close()
 box.cfg{ listen = 'unix/:'.. path2}
@@ -270,6 +269,7 @@ test:is(run_script(code), 0, "wal_mode none and ER_LOADING")
 --
 -- gh-1962: incorrect replication source
 --
+local reason
 status, reason = pcall(box.cfg, {replication="3303,3304"})
 test:ok(not status and reason:match("Incorrect"), "invalid replication")
 
@@ -298,7 +298,7 @@ test:is(run_script(code), 0, "page size equal with range")
 code = [[
 box.cfg{slab_alloc_arena = 0.2, slab_alloc_minimal = 16,
     slab_alloc_maximal = 64 * 1024}
-os.exit(box.cfg.memtx_memory == 214748364 
+os.exit(box.cfg.memtx_memory == 214748364
     and box.cfg.memtx_min_tuple_size == 16
     and box.cfg.memtx_max_tuple_size == 64 * 1024
 and 0 or 1)
@@ -384,7 +384,7 @@ test:is(run_script(code), 0, "wal_max_size xlog rotation")
 -- gh-2872 bootstrap is aborted if vinyl_dir contains vylog files
 -- left from previous runs
 --
-vinyl_dir = fio.tempdir()
+local vinyl_dir = fio.tempdir()
 run_script(string.format([[
 box.cfg{vinyl_dir = '%s'}
 s = box.schema.space.create('test', {engine = 'vinyl'})
@@ -401,8 +401,8 @@ fio.rmtree(vinyl_dir)
 --
 -- gh-2278 vinyl does not support DDL/DML if wal_mode = 'none'
 --
-dir = fio.tempdir()
-cfg = string.format("wal_dir = '%s', memtx_dir = '%s', vinyl_dir = '%s'", dir, dir, dir)
+local dir = fio.tempdir()
+local cfg = string.format("wal_dir = '%s', memtx_dir = '%s', vinyl_dir = '%s'", dir, dir, dir)
 run_script(string.format([[
 box.cfg{%s}
 s = box.schema.space.create('test', {engine = 'vinyl'})
@@ -453,9 +453,9 @@ test:is(run_script(code), 0, "check replicaset_uuid")
 -- Configuration fails on instance or replica set UUID mismatch.
 --
 dir = fio.tempdir()
-instance_uuid = uuid.new()
-replicaset_uuid = uuid.new()
-code_fmt = [[
+local instance_uuid = uuid.new()
+local replicaset_uuid = uuid.new()
+local code_fmt = [[
 box.cfg{memtx_dir = '%s', instance_uuid = '%s', replicaset_uuid = '%s'}
 os.exit(0)
 ]]
@@ -569,14 +569,14 @@ test:is(run_script(code), 0, "log_nonblock")
 -- Crash (instead of panic) when trying to recover a huge tuple.
 --
 dir = fio.tempdir()
-code1 = string.format([[
+local code1 = string.format([[
 box.cfg{wal_dir = '%s', memtx_dir = '%s', memtx_max_tuple_size = 10 * 1024 * 1024}
 box.schema.space.create('test')
 box.space.test:create_index('primary')
 box.space.test:insert{1, string.rep('x', 1024 * 1024)}
 os.exit(0)
 ]], dir, dir)
-code2 = string.format([[
+local code2 = string.format([[
 box.cfg{wal_dir = '%s', memtx_dir = '%s', memtx_max_tuple_size = 10 * 1024}
 os.exit(0)
 ]], dir, dir)
diff --git a/test/box-tap/cfgup.test.lua b/test/box-tap/cfgup.test.lua
index 45fc12316..e699e304f 100755
--- a/test/box-tap/cfgup.test.lua
+++ b/test/box-tap/cfgup.test.lua
@@ -6,8 +6,8 @@ local tap = require('tap')
 local test = tap.test('cfg')
 test:plan(3)
 
-config = {
-	pid_file = '1.pid',
+local config = {
+    pid_file = '1.pid',
     log="tarantool.log"
 }
 
diff --git a/test/box-tap/extended_error.test.lua b/test/box-tap/extended_error.test.lua
index 884387be8..7a6152d22 100755
--- a/test/box-tap/extended_error.test.lua
+++ b/test/box-tap/extended_error.test.lua
@@ -24,7 +24,8 @@ box.schema.func.create('forbidden_function')
 box.session.su('guest')
 local tmp = box.func.forbidden_function
 local access_denied_error
-tmp, access_denied_error = pcall(tmp.call, tmp)
+local _
+_, access_denied_error = pcall(tmp.call, tmp)
 box.session.su('admin')
 box.schema.func.drop('forbidden_function')
 box.session.su(user)
@@ -85,7 +86,7 @@ local checks = {
     type = 'ClientError',
 }
 test:ok(check_error(err, checks), "ClientError marshaling")
-tmp, err = pcall(c.call, c, 'error_throw', args)
+_, err = pcall(c.call, c, 'error_throw', args)
 test:ok(check_error(err, checks), "ClientError marshaling in iproto fields")
 
 args = {{code = 1001, reason = 'Reason2', type = 'MyError'}}
@@ -97,7 +98,7 @@ checks = {
     type = 'MyError',
 }
 test:ok(check_error(err, checks), "CustomError marshaling")
-tmp, err = pcall(c.call, c, 'error_throw', args)
+_, err = pcall(c.call, c, 'error_throw', args)
 test:ok(check_error(err, checks), "CustomError marshaling in iproto fields")
 
 err = c:call('error_access_denied')
@@ -111,7 +112,7 @@ checks = {
     access_type = 'Execute',
 }
 test:ok(check_error(err, checks), "AccessDeniedError marshaling")
-tmp, err = pcall(c.call, c, 'error_throw_access_denied')
+_, err = pcall(c.call, c, 'error_throw_access_denied')
 test:ok(check_error(err, checks), "AccessDeniedError marshaling in iproto fields")
 
 args = {
@@ -137,7 +138,7 @@ local checks2 = {
 }
 test:ok(check_error(err2, checks2), "Second error in the stack")
 
-tmp, err = pcall(c.call, c, 'error_throw_stacked', args)
+_, err = pcall(c.call, c, 'error_throw_stacked', args)
 err1 = err
 err2 = err.prev
 test:isnt(err2, nil, 'Stack is received via iproto fields')
diff --git a/test/box-tap/feedback_daemon.test.lua b/test/box-tap/feedback_daemon.test.lua
index 7ebc97587..3c929132d 100755
--- a/test/box-tap/feedback_daemon.test.lua
+++ b/test/box-tap/feedback_daemon.test.lua
@@ -36,7 +36,7 @@ local function http_handle(s)
         buf = s:read('\n')
     end
     buf = s:read(length)
-    local ok, data = pcall(json.decode, buf)
+    local ok = pcall(json.decode, buf)
     if ok then
         feedback = buf
         feedback_count = feedback_count + 1
@@ -126,7 +126,7 @@ fio.unlink("feedback.json")
 
 server:close()
 -- check it does not fail without server
-local daemon = box.internal.feedback_daemon
+daemon = box.internal.feedback_daemon
 daemon.start()
 daemon.send_test()
 daemon.stop()
@@ -225,8 +225,8 @@ test:is(actual.features.schema.hash_indices, 2,
 -- collect box.cfg options: election mode, synchronous replication and tx
 -- manager.
 --
-em = box.cfg.election_mode
-quorum = box.cfg.replication_synchro_quorum
+local em = box.cfg.election_mode
+local quorum = box.cfg.replication_synchro_quorum
 box.cfg{election_mode='candidate', replication_synchro_quorum=2}
 box.on_reload_configuration = function() end
 actual = daemon.generate_feedback()
diff --git a/test/box-tap/gc.test.lua b/test/box-tap/gc.test.lua
index f88752e71..f0155779c 100755
--- a/test/box-tap/gc.test.lua
+++ b/test/box-tap/gc.test.lua
@@ -4,7 +4,7 @@ local fiber = require('fiber')
 
 box.cfg{}
 
-local debug = type(box.error.injection) == "table" 
+local debug = type(box.error.injection) == "table"
 
 -- check box.info.gc() is false if snapshot is not in progress
 local test = tap.test('box.info.gc')
@@ -19,7 +19,7 @@ test:is(gc.checkpoint_is_in_progress, false, "checkpoint is not in progress")
 if debug then
     box.error.injection.set("ERRINJ_SNAP_COMMIT_DELAY", true)
     local snapshot_f  = function()
-       box.snapshot() 
+       box.snapshot()
     end
     fiber.create(snapshot_f)
     local gc = box.info.gc()
diff --git a/test/box-tap/gh-4688-box-info-memory.test.lua b/test/box-tap/gh-4688-box-info-memory.test.lua
index 0a27741d3..991ea4177 100755
--- a/test/box-tap/gh-4688-box-info-memory.test.lua
+++ b/test/box-tap/gh-4688-box-info-memory.test.lua
@@ -12,7 +12,7 @@ test:plan(1)
 
 local function get_keys(t)
     local keys = {}
-    for k, v in pairs(t) do
+    for k, _ in pairs(t) do
         table.insert(keys, k)
     end
     return keys
diff --git a/test/box-tap/on_schema_init.test.lua b/test/box-tap/on_schema_init.test.lua
index 51b28ea08..db9ae6f27 100755
--- a/test/box-tap/on_schema_init.test.lua
+++ b/test/box-tap/on_schema_init.test.lua
@@ -8,7 +8,7 @@ local test = tap.test('on_schema_init')
 local str = ''
 test:plan(7)
 
-function testing_trig()
+local function testing_trig()
     test:istable(box.space._space, 'system spaces are accessible')
     test:is(type(box.space._space.before_replace), 'function', 'before_replace triggers')
     test:is(type(box.space._space.on_replace), 'function', 'on_replace triggers')
@@ -17,7 +17,7 @@ function testing_trig()
     str = str..'on_schema_init'
 end
 
-trig = box.ctl.on_schema_init(testing_trig)
+local trig = box.ctl.on_schema_init(testing_trig)
 test:is(type(trig), 'function', 'on_schema_init trigger set')
 
 box.cfg{log = 'tarantool.log'}
diff --git a/test/box-tap/schema_mt.test.lua b/test/box-tap/schema_mt.test.lua
index 5a635262f..c0fe5f10b 100755
--- a/test/box-tap/schema_mt.test.lua
+++ b/test/box-tap/schema_mt.test.lua
@@ -20,7 +20,7 @@ local sp1 = box.schema.create_space('test1', {engine = 'memtx'})
 local sp2 = box.schema.create_space('test2', {engine = 'vinyl'})
 test:is(getmetatable(sp1).__index, getmetatable(sp2).__index, 'spaces share metatables __index')
 
-function box.schema.space_mt.myfunc(space, args)
+function box.schema.space_mt.myfunc(space, args) -- luacheck: no unused args
   return args
 end
 test:is(sp1:myfunc(123), 123, 'space_mt can be extended')
@@ -41,13 +41,13 @@ test:isnt(getmetatable(sp1_pk).__index, getmetatable(sp2_pk).__index, 'engines d
 -- Check that there are two ways to extend index metatable:
 -- extend base index metatable, or extend engine specific.
 --
-function box.schema.index_mt.common_func(index, args)
+function box.schema.index_mt.common_func(index, args) -- luacheck: no unused args
   return args
 end
-function box.schema.vinyl_index_mt.vinyl_func(index, args)
+function box.schema.vinyl_index_mt.vinyl_func(index, args) -- luacheck: no unused args
   return args
 end
-function box.schema.memtx_index_mt.memtx_func(index, args)
+function box.schema.memtx_index_mt.memtx_func(index, args) -- luacheck: no unused args
   return args
 end
 test:is(box.schema.index_mt.common_func, box.schema.vinyl_index_mt.common_func,
@@ -77,14 +77,14 @@ test:is(sp2_sk:common_func(400), 400, 'vinyl common methods work')
 -- A space local metatable can extended so it does not affect
 -- other spaces. Same about index.
 --
-sp3 = box.schema.create_space('test3', {engine = 'memtx'})
-sp3_pk = sp3:create_index('pk')
-sp3_sk = sp3:create_index('sk')
-mt1 = getmetatable(sp1)
-mt2 = getmetatable(sp2)
+local sp3 = box.schema.create_space('test3', {engine = 'memtx'})
+local sp3_pk = sp3:create_index('pk')
+local sp3_sk = sp3:create_index('sk')
+local mt1 = getmetatable(sp1)
+local mt2 = getmetatable(sp2)
 test:isnt(mt1, mt2, 'spaces do not share metatables')
-index_mt1 = getmetatable(sp3_pk)
-index_mt2 = getmetatable(sp3_sk)
+local index_mt1 = getmetatable(sp3_pk)
+local index_mt2 = getmetatable(sp3_sk)
 test:isnt(index_mt1, index_mt2, 'indexes do not share metatables')
 
 mt1.my_func = function(a) return a end
diff --git a/test/box-tap/session.storage.test.lua b/test/box-tap/session.storage.test.lua
index 40ca9c230..d17d3efce 100755
--- a/test/box-tap/session.storage.test.lua
+++ b/test/box-tap/session.storage.test.lua
@@ -19,7 +19,7 @@ test:is(
 )
 
 local uri = inspector:eval('session_storage', 'box.cfg.listen')[1]
-conn1 = net_box.connect(uri)
+local conn1 = net_box.connect(uri)
 
 conn1:eval("session = box.session")
 test:is(conn1:eval("return type(session.id())"), "number", "session.id()")
@@ -34,7 +34,7 @@ conn1:eval("all = getmetatable(session).aggregate_storage")
 test:ok(conn1:eval("return all[session.id()].abc == 'cde'"), "check meta table")
 
 
-conn2 = net_box.connect(uri)
+local conn2 = net_box.connect(uri)
 
 test:is(conn2:eval("return type(session.storage)"), "table", "storage")
 test:isnil(conn2:eval("return type(session.storage.abc)"), "empty storage")
@@ -45,12 +45,12 @@ test:ok(conn1:eval("return session.storage.abc == 'cde'"), "first conn storage")
 test:ok(conn1:eval("return all[session.id()].abc == 'cde'"), "check first conn metatable")
 test:ok(conn2:eval("return all[session.id()].abc == 'def'"), "check second conn metatable")
 
-tres1 = conn1:eval("t1 = {} for k, v in pairs(all) do table.insert(t1, v.abc) end return t1")
+local tres1 = conn1:eval("t1 = {} for k, v in pairs(all) do table.insert(t1, v.abc) end return t1")
 
 conn1:close()
 conn2:close()
-conn3 = net_box.connect(uri)
-tres2 = conn3:eval("t2 = {} for k, v in pairs(all) do table.insert(t2, v.abc) end return t2")
+local conn3 = net_box.connect(uri)
+local tres2 = conn3:eval("t2 = {} for k, v in pairs(all) do table.insert(t2, v.abc) end return t2")
 table.sort(tres1)
 table.sort(tres2)
 test:is(tres1[1], "cde", "check after closing")
diff --git a/test/box-tap/session.test.lua b/test/box-tap/session.test.lua
index 5d4965533..160f047bc 100755
--- a/test/box-tap/session.test.lua
+++ b/test/box-tap/session.test.lua
@@ -13,7 +13,7 @@ local uri = require('uri').parse(box.cfg.listen)
 local HOST, PORT = uri.host or 'localhost', uri.service
 session = box.session
 space = box.schema.space.create('tweedledum')
-index = space:create_index('primary', { type = 'hash' })
+space:create_index('primary', { type = 'hash' })
 
 test:plan(56)
 
@@ -23,25 +23,25 @@ test:plan(56)
 test:ok(session.exists(session.id()), "session is created")
 test:isnil(session.peer(session.id()), "session.peer")
 test:ok(session.exists(), "session.exists")
-ok, err = pcall(session.exists, 1, 2, 3)
+local _, err = pcall(session.exists, 1, 2, 3)
 test:is(err, "session.exists(sid): bad arguments", "exists bad args #2")
 test:ok(not session.exists(1234567890), "session doesn't exist")
 
 -- check session.id()
 test:ok(session.id() > 0, "id > 0")
-failed = false
+local failed = false
 local f = fiber.create(function() failed = session.id() == 0 end)
 while f:status() ~= 'dead' do fiber.sleep(0) end
 test:ok(not failed, "session not broken")
 test:is(session.peer(), session.peer(session.id()), "peer() == peer(id())")
 
 -- check on_connect/on_disconnect triggers
-function noop() end
+local function noop() end
 test:is(type(session.on_connect(noop)), "function", "type of trigger noop on_connect")
 test:is(type(session.on_disconnect(noop)), "function", "type of trigger noop on_disconnect")
 
 -- check it's possible to reset these triggers
-function fail() error('hear') end
+local function fail() error('hear') end
 test:is(type(session.on_connect(fail, noop)), "function", "type of trigger fail, noop on_connect")
 test:is(type(session.on_disconnect(fail, noop)), "function", "type of trigger fail, noop on_disconnect")
 
@@ -49,19 +49,19 @@ test:is(type(session.on_disconnect(fail, noop)), "function", "type of trigger fa
 test:is(type(session.on_connect()), "table", "type of trigger on_connect, no args")
 test:is(type(session.on_disconnect()), "table", "type of trigger on_disconnect, no args")
 
-ok, err = pcall(session.on_connect, function() end, function() end)
+_, err = pcall(session.on_connect, function() end, function() end)
 test:is(err,"trigger reset: Trigger is not found", "on_connect trigger not found")
-ok, err = pcall(session.on_disconnect, function() end, function() end)
+_, err = pcall(session.on_disconnect, function() end, function() end)
 test:is(err,"trigger reset: Trigger is not found", "on_disconnect trigger not found")
 
-ok, err = pcall(session.on_connect, 1, 2)
+_, err = pcall(session.on_connect, 1, 2)
 test:is(err, "trigger reset: incorrect arguments", "on_connect bad args #1")
-ok, err = pcall(session.on_disconnect, 1, 2)
+_, err = pcall(session.on_disconnect, 1, 2)
 test:is(err, "trigger reset: incorrect arguments", "on_disconnect bad args #1")
 
-ok, err = pcall(session.on_connect, 1)
+_, err = pcall(session.on_connect, 1)
 test:is(err, "trigger reset: incorrect arguments", "on_connect bad args #2")
-ok, err = pcall(session.on_disconnect, 1)
+_, err = pcall(session.on_disconnect, 1)
 test:is(err, "trigger reset: incorrect arguments", "on_disconnect bad args #2")
 
 -- use of nil to clear the trigger
@@ -70,18 +70,18 @@ session.on_disconnect(nil, fail)
 
 -- check how connect/disconnect triggers work
 local peer_name = "peer_name"
-function inc() active_connections = active_connections + 1 end
-function dec() active_connections = active_connections - 1 end
-function peer() peer_name = box.session.peer() end
-net = { box = require('net.box') }
+local function inc() active_connections = active_connections + 1 end
+local function dec() active_connections = active_connections - 1 end
+local function peer() peer_name = box.session.peer() end
+local net = { box = require('net.box') }
 test:is(type(session.on_connect(inc)), "function", "type of trigger inc on_connect")
 test:is(type(session.on_disconnect(dec)), "function", "type of trigger dec on_disconnect")
 test:is(type(session.on_disconnect(peer)), "function", "type of trigger peer on_disconnect")
 active_connections = 0
-c = net.box.connect(HOST, PORT)
+local c = net.box.connect(HOST, PORT)
 while active_connections < 1 do fiber.sleep(0.001) end
 test:is(active_connections, 1, "active_connections after 1 connection")
-c1 = net.box.connect(HOST, PORT)
+local c1 = net.box.connect(HOST, PORT)
 while active_connections < 2 do fiber.sleep(0.001) end
 test:is(active_connections, 2, "active_connections after 2 connection")
 c:close()
@@ -95,14 +95,14 @@ session.on_disconnect(nil, dec)
 session.on_disconnect(nil, peer)
 
 -- write audit trail of connect/disconnect into a space
-function audit_connect() box.space['tweedledum']:insert{session.id()} end
-function audit_disconnect() box.space['tweedledum']:delete{session.id()} end
+local function audit_connect() box.space['tweedledum']:insert{session.id()} end
+local function audit_disconnect() box.space['tweedledum']:delete{session.id()} end
 test:is(type(session.on_connect(audit_connect)), "function", "type of trigger audit_connect on_connect")
 test:is(type(session.on_disconnect(audit_disconnect)), "function", "type of trigger audit_connect on_disconnect")
 
 box.schema.user.grant('guest', 'read,write', 'space', 'tweedledum')
 box.schema.user.grant('guest', 'execute', 'universe')
-a = net.box.connect(HOST, PORT)
+local a = net.box.connect(HOST, PORT)
 test:ok(a:eval('return space:get{box.session.id()}[1] == session.id()'), "eval get_id")
 test:ok(a:eval('return session.sync() ~= 0'), "eval sync")
 a:close()
@@ -122,15 +122,15 @@ box.schema.user.revoke('guest', 'execute', 'universe')
 -- audit permission in on_connect/on_disconnect triggers
 box.schema.user.create('tester', { password = 'tester' })
 
-on_connect_user = nil
-on_disconnect_user = nil
-function on_connect() on_connect_user = box.session.effective_user() end
-function on_disconnect() on_disconnect_user = box.session.effective_user() end
+local on_connect_user = nil
+local on_disconnect_user = nil
+local function on_connect() on_connect_user = box.session.effective_user() end
+local function on_disconnect() on_disconnect_user = box.session.effective_user() end
 _ = box.session.on_connect(on_connect)
 _ = box.session.on_disconnect(on_disconnect)
 local conn = require('net.box').connect("tester:tester@" ..HOST..':'..PORT)
 -- Triggers must not lead to privilege escalation
-ok, err = pcall(function () conn:eval('box.space._user:select()') end)
+local ok = pcall(function () conn:eval('box.space._user:select()') end)
 test:ok(not ok, "check access")
 conn:close()
 conn = nil
@@ -143,13 +143,13 @@ box.session.on_connect(nil, on_connect)
 box.session.on_disconnect(nil, on_disconnect)
 
 -- check Session privilege
-ok, err = pcall(function() net.box.connect("tester:tester@" ..HOST..':'..PORT) end)
+ok = pcall(function() net.box.connect("tester:tester@" ..HOST..':'..PORT) end)
 test:ok(ok, "session privilege")
 box.schema.user.revoke('tester', 'session', 'universe')
 conn = net.box.connect("tester:tester@" ..HOST..':'..PORT)
 test:is(conn.state, "error", "session privilege state")
 test:ok(conn.error:match("Session"), "sesssion privilege errmsg")
-ok, err = pcall(box.session.su, "user1")
+ok = pcall(box.session.su, "user1")
 test:ok(not ok, "session.su on revoked")
 box.schema.user.drop('tester')
 
@@ -187,7 +187,7 @@ conn:close()
 --
 -- gh-3450: box.session.sync() becomes request local.
 --
-cond = fiber.cond()
+local cond = fiber.cond()
 local sync1, sync2
 local started = 0
 function f1()
diff --git a/test/box-tap/trigger_atexit.test.lua b/test/box-tap/trigger_atexit.test.lua
index 59b47aa6a..8baa868c4 100755
--- a/test/box-tap/trigger_atexit.test.lua
+++ b/test/box-tap/trigger_atexit.test.lua
@@ -3,11 +3,9 @@
 
 -- see https://github.com/tarantool/tarantool/issues/583
 
-tap = require 'tap'
-fio = require 'fio'
-log = require 'log'
+local fio = require 'fio'
 
-tempdir = fio.tempdir()
+local tempdir = fio.tempdir()
 
 box.cfg {
     wal_dir = tempdir,
@@ -17,7 +15,7 @@ box.cfg {
     memtx_memory = 104857600 -- for small systems
 }
 
-local function test_replace(old_tuple, new_tuple)
+local function test_replace()
 
 end
 
@@ -27,7 +25,7 @@ box.space.abc:create_index('pk', { type = 'tree' })
 box.space.abc:on_replace(test_replace)
 
 
-cleanup_list = fio.glob(fio.pathjoin(tempdir, '*'))
+local cleanup_list = fio.glob(fio.pathjoin(tempdir, '*'))
 for _, file in pairs(cleanup_list) do
     fio.unlink(file)
 end
diff --git a/test/box-tap/trigger_yield.test.lua b/test/box-tap/trigger_yield.test.lua
index 5d02fea3a..10fca632c 100755
--- a/test/box-tap/trigger_yield.test.lua
+++ b/test/box-tap/trigger_yield.test.lua
@@ -5,21 +5,21 @@ box.cfg{
     log = "tarantool.log"
 }
 
-fiber = require('fiber')
+local fiber = require('fiber')
 
 box.schema.space.create('test')
 box.space.test:create_index('pk')
 
 box.space.test:truncate()
 
-function fail() fiber.sleep(0.0001) error("fail") end
+local function fail() fiber.sleep(0.0001) error("fail") end
 
 box.space.test:on_replace(fail)
 
-function insert() box.space.test:auto_increment{fiber.id()} end
+local function insert() box.space.test:auto_increment{fiber.id()} end
 
-fibers = {}
-for i = 1, 100 do
+local fibers = {}
+for _ = 1, 100 do
     table.insert(fibers, fiber.create(insert))
 end
 
-- 
2.25.1



More information about the Tarantool-patches mailing list