[Tarantool-patches] [PATCH v6 11/25] Fix luacheck warnings in test/box-tap

sergeyb at tarantool.org sergeyb at tarantool.org
Fri May 29 18:09:14 MSK 2020


From: Sergey Bronnikov <sergeyb at tarantool.org>

Part of #4681

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                           |   9 ++
 test/box-tap/auth.test.lua            |  36 +++----
 test/box-tap/cfg.test.lua             |  34 +++----
 test/box-tap/cfgup.test.lua           |   2 +-
 test/box-tap/extended_error.test.lua  |  11 ++-
 test/box-tap/feedback_daemon.test.lua |   4 +-
 test/box-tap/gc.test.lua              |   6 +-
 test/box-tap/gh-4785-syslog.test.lua  |   4 +-
 test/box-tap/key_def.test.lua         | 132 +++++++++++++-------------
 test/box-tap/merger.test.lua          | 112 +++++++++++-----------
 test/box-tap/on_schema_init.test.lua  |   4 +-
 test/box-tap/schema_mt.test.lua       |  18 ++--
 test/box-tap/session.storage.test.lua |  10 +-
 test/box-tap/session.test.lua         |  59 ++++++------
 test/box-tap/trigger_atexit.test.lua  |  10 +-
 test/box-tap/trigger_yield.test.lua   |  10 +-
 16 files changed, 233 insertions(+), 228 deletions(-)

diff --git a/.luacheckrc b/.luacheckrc
index f99cc17eb..23b9f1b72 100644
--- a/.luacheckrc
+++ b/.luacheckrc
@@ -54,3 +54,12 @@ files["test/box/lua/bitset.lua"] = {
 files["test/box/lua/fifo.lua"] = {globals = {"fifomax", "find_or_create_fifo", "fifo_push", "fifo_top"}}
 files["test/box/lua/identifier.lua"] = {globals = {"run_test"}}
 files["test/box/lua/require_mod.lua"] = {globals = {"exports"}}
+files["test/box-tap/session.test.lua"] = {
+	globals = {"active_connections", "session", "space", "f1", "f2"},
+	ignore = {"211"}
+}
+files["test/box-tap/extended_error.test.lua"] = {
+	globals = {"error_new", "error_throw", "error_new_stacked", "error_throw_stacked",
+	"error_access_denied", "error_throw_access_denied", "forbidden_function"},
+	ignore = {"211"}
+}
diff --git a/test/box-tap/auth.test.lua b/test/box-tap/auth.test.lua
index 4e9879408..6c14d1981 100755
--- a/test/box-tap/auth.test.lua
+++ b/test/box-tap/auth.test.lua
@@ -18,22 +18,24 @@ 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)
     counter = counter + 1
+    msg = 'user ' .. user_name .. ' is there'
 end
 -- get user name as argument
-function auth_trigger2(user_name)
+local function auth_trigger2(user_name)
     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)
+    succeeded = success
+    msg = 'user ' .. user_name .. ' is there'
 end
 -- set trigger
 local handle = session.on_auth(auth_trigger)
@@ -57,68 +59,61 @@ 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
 succeeded = true
-local conn = netbox.connect('test:pas@' .. HOST .. ':' .. PORT)
+conn = netbox.connect('test:pas@' .. HOST .. ':' .. PORT)
 while counter < 1 do fiber.sleep(0.001) end
 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
-local conn = netbox.connect('test2:@' .. HOST .. ':' .. PORT)
+conn = netbox.connect('test2:@' .. HOST .. ':' .. PORT)
 while counter < 1 do fiber.sleep(0.001) end
 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
-local conn = netbox.connect('test2@' .. HOST .. ':' .. PORT)
+conn = netbox.connect('test2@' .. HOST .. ':' .. PORT)
 while counter < 1 do fiber.sleep(0.001) end
 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
-local conn = netbox.connect(HOST, PORT, {user='test2'})
+conn = netbox.connect(HOST, PORT, {user='test2'})
 while counter < 1 do fiber.sleep(0.001) end
 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
-local conn = netbox.connect('guest@' .. HOST .. ':' .. PORT)
+conn = netbox.connect('guest@' .. HOST .. ':' .. PORT)
 while counter < 1 do fiber.sleep(0.001) end
 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
-local conn = netbox.connect('guest:@' .. HOST .. ':' .. PORT)
+conn = netbox.connect('guest:@' .. HOST .. ':' .. PORT)
 while counter < 1 do fiber.sleep(0.001) end
 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,17 +123,15 @@ 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
-local conn = netbox.connect(HOST, PORT, {user='guest'})
+conn = netbox.connect(HOST, PORT, {user='guest'})
 while counter < 1 do fiber.sleep(0.001) end
 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 +141,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..85b18a37a 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()
+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()
+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..493a37ae0 100755
--- a/test/box-tap/cfgup.test.lua
+++ b/test/box-tap/cfgup.test.lua
@@ -6,7 +6,7 @@ local tap = require('tap')
 local test = tap.test('cfg')
 test:plan(3)
 
-config = {
+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 d4adb71f1..06d967588 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()
diff --git a/test/box-tap/gc.test.lua b/test/box-tap/gc.test.lua
index f88752e71..c3437507d 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,10 +19,10 @@ 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()
+    gc = box.info.gc()
     test:is(gc.checkpoint_is_in_progress, true, "checkpoint is in progress")
     box.error.injection.set("ERRINJ_SNAP_COMMIT_DELAY", false)
 end
diff --git a/test/box-tap/gh-4785-syslog.test.lua b/test/box-tap/gh-4785-syslog.test.lua
index 9bdc97175..c0520da21 100755
--- a/test/box-tap/gh-4785-syslog.test.lua
+++ b/test/box-tap/gh-4785-syslog.test.lua
@@ -52,12 +52,12 @@ test:like(entry, pattern, 'log.info() log entry is in syslog format',
           {logs = {entry}})
 
 -- log.log_format('plain') is silently ignored.
-local ok = pcall(log.log_format, 'plain')
+ok = pcall(log.log_format, 'plain')
 test:ok(ok, "log.log_format('plain') is ignored with syslog")
 
 -- Verify log format again after log.log_format().
 log.info('world')
-local entry = unix_socket:recv(100)
+entry = unix_socket:recv(100)
 test:like(entry, pattern, 'log.info() log entry after log_format',
           {logs = {entry}})
 
diff --git a/test/box-tap/key_def.test.lua b/test/box-tap/key_def.test.lua
index d7dbf5b88..3959b9406 100755
--- a/test/box-tap/key_def.test.lua
+++ b/test/box-tap/key_def.test.lua
@@ -206,8 +206,8 @@ end
 -- Prepare source data for test cases.
 
 -- Case: extract_key().
-test:test('extract_key()', function(test)
-    test:plan(13)
+test:test('extract_key()', function(testcase)
+    testcase:plan(13)
 
     local key_def_a = key_def_lib.new({
         {type = 'unsigned', fieldno = 1},
@@ -223,19 +223,19 @@ test:test('extract_key()', function(test)
     })
     local tuple_a = box.tuple.new({1, 1, 22})
 
-    test:is_deeply(key_def_a:extract_key(tuple_a):totable(), {1}, 'case 1')
-    test:is_deeply(key_def_b:extract_key(tuple_a):totable(), {1, 22}, 'case 2')
+    testcase:is_deeply(key_def_a:extract_key(tuple_a):totable(), {1}, 'case 1')
+    testcase:is_deeply(key_def_b:extract_key(tuple_a):totable(), {1, 22}, 'case 2')
 
     -- JSON path.
     local res = key_def_lib.new({
         {type = 'string', fieldno = 1, path = 'a.b'},
     }):extract_key(box.tuple.new({{a = {b = 'foo'}}})):totable()
-    test:is_deeply(res, {'foo'}, 'JSON path (tuple argument)')
+    testcase:is_deeply(res, {'foo'}, 'JSON path (tuple argument)')
 
-    local res = key_def_lib.new({
+    res = key_def_lib.new({
         {type = 'string', fieldno = 1, path = 'a.b'},
     }):extract_key({{a = {b = 'foo'}}}):totable()
-    test:is_deeply(res, {'foo'}, 'JSON path (table argument)')
+    testcase:is_deeply(res, {'foo'}, 'JSON path (table argument)')
 
     -- A key def has a **nullable** part with a field that is over
     -- a tuple size.
@@ -244,7 +244,7 @@ test:test('extract_key()', function(test)
     --
     -- * is_nullable = true;
     -- * has_optional_parts = true.
-    test:is_deeply(key_def_c:extract_key(tuple_a):totable(), {1, 1, box.NULL},
+    testcase:is_deeply(key_def_c:extract_key(tuple_a):totable(), {1, 1, box.NULL},
         'short tuple with a nullable part')
 
     -- A key def has a **non-nullable** part with a field that is
@@ -261,73 +261,73 @@ test:test('extract_key()', function(test)
     })
     local ok, err = pcall(key_def.extract_key, key_def,
         box.tuple.new({'foo'}))
-    test:is_deeply({ok, tostring(err)}, {false, exp_err},
+    testcase:is_deeply({ok, tostring(err)}, {false, exp_err},
         'short tuple with a non-nullable part (case 1)')
 
     -- Same as before, but a max fieldno is over tuple:len() + 1.
-    local exp_err = 'Tuple field [2] required by space format is missing'
-    local key_def = key_def_lib.new({
+    exp_err = 'Tuple field [2] required by space format is missing'
+    key_def = key_def_lib.new({
         {type = 'string', fieldno = 1},
         {type = 'string', fieldno = 2},
         {type = 'string', fieldno = 3},
     })
-    local ok, err = pcall(key_def.extract_key, key_def,
+    ok, err = pcall(key_def.extract_key, key_def,
         box.tuple.new({'foo'}))
-    test:is_deeply({ok, tostring(err)}, {false, exp_err},
+    testcase:is_deeply({ok, tostring(err)}, {false, exp_err},
         'short tuple with a non-nullable part (case 2)')
 
     -- Same as before, but with another key def options:
     --
     -- * is_nullable = true;
     -- * has_optional_parts = false.
-    local exp_err = 'Tuple field [2] required by space format is missing'
-    local key_def = key_def_lib.new({
+    exp_err = 'Tuple field [2] required by space format is missing'
+    key_def = key_def_lib.new({
         {type = 'string', fieldno = 1, is_nullable = true},
         {type = 'string', fieldno = 2},
     })
-    local ok, err = pcall(key_def.extract_key, key_def,
+    ok, err = pcall(key_def.extract_key, key_def,
         box.tuple.new({'foo'}))
-    test:is_deeply({ok, tostring(err)}, {false, exp_err},
+    testcase:is_deeply({ok, tostring(err)}, {false, exp_err},
         'short tuple with a non-nullable part (case 3)')
 
     -- A tuple has a field that does not match corresponding key
     -- part type.
-    local exp_err = 'Supplied key type of part 2 does not match index ' ..
+    exp_err = 'Supplied key type of part 2 does not match index ' ..
                     'part type: expected string'
-    local key_def = key_def_lib.new({
+    key_def = key_def_lib.new({
         {type = 'string', fieldno = 1},
         {type = 'string', fieldno = 2},
         {type = 'string', fieldno = 3},
     })
-    local ok, err = pcall(key_def.extract_key, key_def, {'one', 'two', 3})
-    test:is_deeply({ok, tostring(err)}, {false, exp_err},
+    ok, err = pcall(key_def.extract_key, key_def, {'one', 'two', 3})
+    testcase:is_deeply({ok, tostring(err)}, {false, exp_err},
         'wrong field type')
 
-    local key_def = key_def_lib.new({
+    key_def = key_def_lib.new({
         {type = 'number', fieldno = 1, path='a'},
         {type = 'number', fieldno = 1, path='b'},
         {type = 'number', fieldno = 1, path='c', is_nullable=true},
         {type = 'number', fieldno = 3, is_nullable=true},
     })
-    local ok, err = pcall(key_def.extract_key, key_def,
+    ok, err = pcall(key_def.extract_key, key_def,
                           box.tuple.new({1, 1, 22}))
-    test:is_deeply({ok, tostring(err)},
+    testcase:is_deeply({ok, tostring(err)},
                 {false, 'Tuple field [1]a required by space format is missing'},
                 'invalid JSON structure')
-    test:is_deeply(key_def:extract_key({{a=1, b=2}, 1}):totable(),
+    testcase:is_deeply(key_def:extract_key({{a=1, b=2}, 1}):totable(),
                    {1, 2, box.NULL, box.NULL},
                    'tuple with optional parts - case 1')
-    test:is_deeply(key_def:extract_key({{a=1, b=2, c=3}, 1}):totable(),
+    testcase:is_deeply(key_def:extract_key({{a=1, b=2, c=3}, 1}):totable(),
                    {1, 2, 3, box.NULL},
                    'tuple with optional parts - case 2')
-    test:is_deeply(key_def:extract_key({{a=1, b=2}, 1, 3}):totable(),
+    testcase:is_deeply(key_def:extract_key({{a=1, b=2}, 1, 3}):totable(),
                    {1, 2, box.NULL, 3},
                    'tuple with optional parts - case 3')
 end)
 
 -- Case: compare().
-test:test('compare()', function(test)
-    test:plan(8)
+test:test('compare()', function(testcase)
+    testcase:plan(8)
 
     local key_def_a = key_def_lib.new({
         {type = 'unsigned', fieldno = 1},
@@ -340,28 +340,28 @@ test:test('compare()', function(test)
     local tuple_b = box.tuple.new({2, 1, 11})
     local tuple_c = box.tuple.new({3, 1, 22})
 
-    test:is(key_def_a:compare(tuple_b, tuple_a), 1,
+    testcase:is(key_def_a:compare(tuple_b, tuple_a), 1,
             'case 1: great (tuple argument)')
-    test:is(key_def_a:compare(tuple_b, tuple_c), -1,
+    testcase:is(key_def_a:compare(tuple_b, tuple_c), -1,
             'case 2: less (tuple argument)')
-    test:is(key_def_b:compare(tuple_b, tuple_a), -1,
+    testcase:is(key_def_b:compare(tuple_b, tuple_a), -1,
             'case 3: less (tuple argument)')
-    test:is(key_def_b:compare(tuple_a, tuple_c), 0,
+    testcase:is(key_def_b:compare(tuple_a, tuple_c), 0,
             'case 4: equal (tuple argument)')
 
-    test:is(key_def_a:compare(tuple_b:totable(), tuple_a:totable()), 1,
+    testcase:is(key_def_a:compare(tuple_b:totable(), tuple_a:totable()), 1,
             'case 1: great (table argument)')
-    test:is(key_def_a:compare(tuple_b:totable(), tuple_c:totable()), -1,
+    testcase:is(key_def_a:compare(tuple_b:totable(), tuple_c:totable()), -1,
             'case 2: less (table argument)')
-    test:is(key_def_b:compare(tuple_b:totable(), tuple_a:totable()), -1,
+    testcase:is(key_def_b:compare(tuple_b:totable(), tuple_a:totable()), -1,
             'case 3: less (table argument)')
-    test:is(key_def_b:compare(tuple_a:totable(), tuple_c:totable()), 0,
+    testcase:is(key_def_b:compare(tuple_a:totable(), tuple_c:totable()), 0,
             'case 4: equal (table argument)')
 end)
 
 -- Case: compare_with_key().
-test:test('compare_with_key()', function(test)
-    test:plan(2)
+test:test('compare_with_key()', function(testcase)
+    testcase:plan(2)
 
     local key_def_b = key_def_lib.new({
         {type = 'number', fieldno = 2},
@@ -370,15 +370,15 @@ test:test('compare_with_key()', function(test)
     local tuple_a = box.tuple.new({1, 1, 22})
 
     local key = {1, 22}
-    test:is(key_def_b:compare_with_key(tuple_a:totable(), key), 0, 'table')
+    testcase:is(key_def_b:compare_with_key(tuple_a:totable(), key), 0, 'table')
 
-    local key = box.tuple.new({1, 22})
-    test:is(key_def_b:compare_with_key(tuple_a, key), 0, 'tuple')
+    key = box.tuple.new({1, 22})
+    testcase:is(key_def_b:compare_with_key(tuple_a, key), 0, 'tuple')
 end)
 
 -- Case: totable().
-test:test('totable()', function(test)
-    test:plan(2)
+test:test('totable()', function(testcase)
+    testcase:plan(2)
 
     local parts_a = {
         {type = 'unsigned', fieldno = 1}
@@ -391,15 +391,15 @@ test:test('totable()', function(test)
     local key_def_b = key_def_lib.new(parts_b)
 
     local exp = set_key_part_defaults(parts_a)
-    test:is_deeply(key_def_a:totable(), exp, 'case 1')
+    testcase:is_deeply(key_def_a:totable(), exp, 'case 1')
 
-    local exp = set_key_part_defaults(parts_b)
-    test:is_deeply(key_def_b:totable(), exp, 'case 2')
+    exp = set_key_part_defaults(parts_b)
+    testcase:is_deeply(key_def_b:totable(), exp, 'case 2')
 end)
 
 -- Case: __serialize().
-test:test('__serialize()', function(test)
-    test:plan(2)
+test:test('__serialize()', function(testcase)
+    testcase:plan(2)
 
     local parts_a = {
         {type = 'unsigned', fieldno = 1}
@@ -412,15 +412,15 @@ test:test('__serialize()', function(test)
     local key_def_b = key_def_lib.new(parts_b)
 
     local exp = set_key_part_defaults(parts_a)
-    test:is(json.encode(key_def_a), json.encode(exp), 'case 1')
+    testcase:is(json.encode(key_def_a), json.encode(exp), 'case 1')
 
-    local exp = set_key_part_defaults(parts_b)
-    test:is(json.encode(key_def_b), json.encode(exp), 'case 2')
+    exp = set_key_part_defaults(parts_b)
+    testcase:is(json.encode(key_def_b), json.encode(exp), 'case 2')
 end)
 
 -- Case: tostring().
-test:test('tostring()', function(test)
-    test:plan(2)
+test:test('tostring()', function(testcase)
+    testcase:plan(2)
 
     local parts_a = {
         {type = 'unsigned', fieldno = 1}
@@ -433,13 +433,13 @@ test:test('tostring()', function(test)
     local key_def_b = key_def_lib.new(parts_b)
 
     local exp = '<struct key_def &>'
-    test:is(tostring(key_def_a), exp, 'case 1')
-    test:is(tostring(key_def_b), exp, 'case 2')
+    testcase:is(tostring(key_def_a), exp, 'case 1')
+    testcase:is(tostring(key_def_b), exp, 'case 2')
 end)
 
 -- Case: merge().
-test:test('merge()', function(test)
-    test:plan(6)
+test:test('merge()', function(testcase)
+    testcase:plan(6)
 
     local key_def_a = key_def_lib.new({
         {type = 'unsigned', fieldno = 1},
@@ -458,27 +458,27 @@ test:test('merge()', function(test)
     local key_def_ab = key_def_a:merge(key_def_b)
     local exp_parts = fun.iter(key_def_a:totable())
         :chain(fun.iter(key_def_b:totable())):totable()
-    test:is_deeply(key_def_ab:totable(), exp_parts,
+    testcase:is_deeply(key_def_ab:totable(), exp_parts,
         'case 1: verify with :totable()')
-    test:is_deeply(key_def_ab:extract_key(tuple_a):totable(), {1, 1, 22},
+    testcase:is_deeply(key_def_ab:extract_key(tuple_a):totable(), {1, 1, 22},
         'case 1: verify with :extract_key()')
 
     local key_def_ba = key_def_b:merge(key_def_a)
-    local exp_parts = fun.iter(key_def_b:totable())
+    exp_parts = fun.iter(key_def_b:totable())
         :chain(fun.iter(key_def_a:totable())):totable()
-    test:is_deeply(key_def_ba:totable(), exp_parts,
+    testcase:is_deeply(key_def_ba:totable(), exp_parts,
         'case 2: verify with :totable()')
-    test:is_deeply(key_def_ba:extract_key(tuple_a):totable(), {1, 22, 1},
+    testcase:is_deeply(key_def_ba:extract_key(tuple_a):totable(), {1, 22, 1},
         'case 2: verify with :extract_key()')
 
     -- Intersecting parts + NULL parts.
     local key_def_cb = key_def_c:merge(key_def_b)
-    local exp_parts = key_def_c:totable()
+    exp_parts = key_def_c:totable()
     exp_parts[#exp_parts + 1] = {type = 'number', fieldno = 3,
         is_nullable = false}
-    test:is_deeply(key_def_cb:totable(), exp_parts,
+    testcase:is_deeply(key_def_cb:totable(), exp_parts,
         'case 3: verify with :totable()')
-    test:is_deeply(key_def_cb:extract_key(tuple_a):totable(),
+    testcase:is_deeply(key_def_cb:extract_key(tuple_a):totable(),
         {1, 1, box.NULL, 22}, 'case 3: verify with :extract_key()')
 end)
 
diff --git a/test/box-tap/merger.test.lua b/test/box-tap/merger.test.lua
index ee9eaeaed..768b42a41 100755
--- a/test/box-tap/merger.test.lua
+++ b/test/box-tap/merger.test.lua
@@ -39,7 +39,7 @@ end
 
 -- Get buffer with data encoded without last 'trunc' bytes.
 local function truncated_msgpack_buffer(data, trunc)
-    local data = msgpackffi.encode(data)
+    data = msgpackffi.encode(data)
     data = data:sub(1, data:len() - trunc)
     local len = data:len()
     local buf = buffer.ibuf()
@@ -370,7 +370,7 @@ local function fetch_source_iterator(input_type, tuples)
 end
 
 local function prepare_data(schema, tuple_count, source_count, opts)
-    local opts = opts or {}
+    opts = opts or {}
     local input_type = opts.input_type
     local use_table_as_tuple = opts.use_table_as_tuple
     local use_fetch_source = opts.use_fetch_source
@@ -471,7 +471,7 @@ end
 local function run_merger(test, schema, tuple_count, source_count, opts)
     fiber.yield()
 
-    local opts = opts or {}
+    opts = opts or {}
 
     -- Prepare data.
     local sources, exp_result = prepare_data(schema, tuple_count, source_count,
@@ -516,8 +516,8 @@ local function run_merger(test, schema, tuple_count, source_count, opts)
         :format(tuple_count, source_count, test_case_opts_str(opts)))
 end
 
-local function run_case(test, schema, opts)
-    local opts = opts or {}
+local function run_case(testcase, schema, opts)
+    opts = opts or {}
 
     local case_name = ('testing on schema %s%s'):format(
         schema.name, test_case_opts_str(opts))
@@ -535,7 +535,7 @@ local function run_case(test, schema, opts)
         return
     end
 
-    test:test(case_name, function(test)
+    testcase:test(case_name, function(test)
         test:plan(4)
 
         -- Check with small buffer count.
@@ -556,12 +556,12 @@ test:plan(#bad_source_new_calls + #bad_chunks + #bad_merger_new_calls +
 box.cfg{}
 
 for _, case in ipairs(bad_source_new_calls) do
-    test:test(case[1], function(test)
+    test:test(case[1], function(testcase)
         local funcs = case.funcs
-        test:plan(#funcs)
+        testcase:plan(#funcs)
         for _, func in ipairs(funcs) do
             local ok, err = pcall(merger[func], unpack(case.params))
-            test:ok(ok == false and err:match(case.exp_err), func)
+            testcase:ok(ok == false and err:match(case.exp_err), func)
         end
     end)
 end
@@ -602,8 +602,8 @@ for _, schema in ipairs(schemas) do
     schema.key_def = key_def_lib.new(schema.parts)
 end
 
-test:test('use a source in two mergers', function(test)
-    test:plan(5)
+test:test('use a source in two mergers', function(testcase)
+    testcase:plan(5)
 
     local data = {{'a'}, {'b'}, {'c'}}
     local source = merger.new_source_fromtable(data)
@@ -611,16 +611,16 @@ test:test('use a source in two mergers', function(test)
     local i2 = merger.new(key_def, {source}):pairs()
 
     local t1 = i1:head():totable()
-    test:is_deeply(t1, data[1], 'tuple 1 from merger 1')
+    testcase:is_deeply(t1, data[1], 'tuple 1 from merger 1')
 
     local t3 = i2:head():totable()
-    test:is_deeply(t3, data[3], 'tuple 3 from merger 2')
+    testcase:is_deeply(t3, data[3], 'tuple 3 from merger 2')
 
     local t2 = i1:head():totable()
-    test:is_deeply(t2, data[2], 'tuple 2 from merger 1')
+    testcase:is_deeply(t2, data[2], 'tuple 2 from merger 1')
 
-    test:ok(i1:is_null(), 'merger 1 ends')
-    test:ok(i2:is_null(), 'merger 2 ends')
+    testcase:ok(i1:is_null(), 'merger 1 ends')
+    testcase:ok(i2:is_null(), 'merger 2 ends')
 end)
 
 local function reusable_source_gen(param)
@@ -640,37 +640,37 @@ local function reusable_source_gen(param)
     return box.NULL, chunk
 end
 
-local function verify_reusable_source(test, source)
-    test:plan(3)
+local function verify_reusable_source(testcase, source)
+    testcase:plan(3)
 
     local exp = {{1}, {2}}
     local res = source:pairs():map(box.tuple.totable):totable()
-    test:is_deeply(res, exp, '1st use')
+    testcase:is_deeply(res, exp, '1st use')
 
-    local exp = {{3}, {4}, {5}}
-    local res = source:pairs():map(box.tuple.totable):totable()
-    test:is_deeply(res, exp, '2nd use')
+    exp = {{3}, {4}, {5}}
+    res = source:pairs():map(box.tuple.totable):totable()
+    testcase:is_deeply(res, exp, '2nd use')
 
-    local exp = {}
-    local res = source:pairs():map(box.tuple.totable):totable()
-    test:is_deeply(res, exp, 'end')
+    exp = {}
+    res = source:pairs():map(box.tuple.totable):totable()
+    testcase:is_deeply(res, exp, 'end')
 end
 
-test:test('reuse a tuple source', function(test)
+test:test('reuse a tuple source', function(testcase)
     local tuples = {{1}, {2}, nil, {3}, {4}, {5}}
     local source = merger.new_tuple_source(reusable_source_gen,
         {chunks = tuples})
-    verify_reusable_source(test, source)
+    verify_reusable_source(testcase, source)
 end)
 
-test:test('reuse a table source', function(test)
+test:test('reuse a table source', function(testcase)
     local chunks = {{{1}}, {{2}}, {}, nil, {{3}}, {{4}}, {}, {{5}}}
     local source = merger.new_table_source(reusable_source_gen,
         {chunks = chunks})
-    verify_reusable_source(test, source)
+    verify_reusable_source(testcase, source)
 end)
 
-test:test('reuse a buffer source', function(test)
+test:test('reuse a buffer source', function(testcase)
     local chunks_tbl = {{{1}}, {{2}}, {}, nil, {{3}}, {{4}}, {}, {{5}}}
     local chunks = {}
     for i = 1, table.maxn(chunks_tbl) do
@@ -683,43 +683,43 @@ test:test('reuse a buffer source', function(test)
     end
     local source = merger.new_buffer_source(reusable_source_gen,
         {chunks = chunks})
-    verify_reusable_source(test, source)
+    verify_reusable_source(testcase, source)
 end)
 
-test:test('use limit', function(test)
-    test:plan(6)
+test:test('use limit', function(testcase)
+    testcase:plan(6)
 
     local data = {{'a'}, {'b'}}
 
     local source = merger.new_source_fromtable(data)
     local m = merger.new(key_def, {source})
     local res = m:select({limit = 0})
-    test:is(#res, 0, 'table output with limit 0')
+    testcase:is(#res, 0, 'table output with limit 0')
 
-    local source = merger.new_source_fromtable(data)
-    local m = merger.new(key_def, {source})
-    local res = m:select({limit = 1})
-    test:is(#res, 1, 'table output with limit 1')
-    test:is_deeply(res[1]:totable(), data[1], 'tuple content')
+    source = merger.new_source_fromtable(data)
+    m = merger.new(key_def, {source})
+    res = m:select({limit = 1})
+    testcase:is(#res, 1, 'table output with limit 1')
+    testcase:is_deeply(res[1]:totable(), data[1], 'tuple content')
 
-    local source = merger.new_source_fromtable(data)
-    local m = merger.new(key_def, {source})
+    source = merger.new_source_fromtable(data)
+    m = merger.new(key_def, {source})
     local output_buffer = buffer.ibuf()
     m:select({buffer = output_buffer, limit = 0})
-    local res = msgpackffi.decode(output_buffer.rpos)
-    test:is(#res, 0, 'buffer output with limit 0')
+    res = msgpackffi.decode(output_buffer.rpos)
+    testcase:is(#res, 0, 'buffer output with limit 0')
 
-    local source = merger.new_source_fromtable(data)
-    local m = merger.new(key_def, {source})
+    source = merger.new_source_fromtable(data)
+    m = merger.new(key_def, {source})
     output_buffer:recycle()
     m:select({buffer = output_buffer, limit = 1})
-    local res = msgpackffi.decode(output_buffer.rpos)
-    test:is(#res, 1, 'buffer output with limit 1')
-    test:is_deeply(res[1], data[1], 'tuple content')
+    res = msgpackffi.decode(output_buffer.rpos)
+    testcase:is(#res, 1, 'buffer output with limit 1')
+    testcase:is_deeply(res[1], data[1], 'tuple content')
 end)
 
-test:test('cascade mergers', function(test)
-    test:plan(2)
+test:test('cascade mergers', function(testcase)
+    testcase:plan(2)
 
     local data = {{'a'}, {'b'}}
 
@@ -728,7 +728,7 @@ test:test('cascade mergers', function(test)
     local m2 = merger.new(key_def, {m1})
 
     local res = m2:pairs():map(box.tuple.totable):totable()
-    test:is_deeply(res, data, 'same key_def')
+    testcase:is_deeply(res, data, 'same key_def')
 
     local key_def_unicode = key_def_lib.new({{
         fieldno = 1,
@@ -736,12 +736,12 @@ test:test('cascade mergers', function(test)
         collation = 'unicode',
     }})
 
-    local source = merger.new_source_fromtable(data)
-    local m1 = merger.new(key_def, {source})
-    local m2 = merger.new(key_def_unicode, {m1})
+    source = merger.new_source_fromtable(data)
+    m1 = merger.new(key_def, {source})
+    m2 = merger.new(key_def_unicode, {m1})
 
-    local res = m2:pairs():map(box.tuple.totable):totable()
-    test:is_deeply(res, data, 'different key_defs')
+    res = m2:pairs():map(box.tuple.totable):totable()
+    testcase:is_deeply(res, data, 'different key_defs')
 end)
 
 -- Merging cases.
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..c098fcc3e 100755
--- a/test/box-tap/schema_mt.test.lua
+++ b/test/box-tap/schema_mt.test.lua
@@ -21,6 +21,7 @@ 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)
+  print(space)
   return args
 end
 test:is(sp1:myfunc(123), 123, 'space_mt can be extended')
@@ -42,12 +43,15 @@ test:isnt(getmetatable(sp1_pk).__index, getmetatable(sp2_pk).__index, 'engines d
 -- extend base index metatable, or extend engine specific.
 --
 function box.schema.index_mt.common_func(index, args)
+  print(index)
   return args
 end
 function box.schema.vinyl_index_mt.vinyl_func(index, args)
+  print(index)
   return args
 end
 function box.schema.memtx_index_mt.memtx_func(index, args)
+  print(index)
   return args
 end
 test:is(box.schema.index_mt.common_func, box.schema.vinyl_index_mt.common_func,
@@ -77,14 +81,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..09095f99f 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,26 @@ 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, _
+_, 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 +50,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 +71,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 +96,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 +123,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 +144,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')
 
@@ -163,7 +164,7 @@ test:is(
     inspector:cmd('start server session'),
     true, 'instance started'
 )
-local uri = inspector:eval('session', 'box.cfg.listen')[1]
+uri = inspector:eval('session', 'box.cfg.listen')[1]
 conn = net.box.connect(uri)
 test:ok(conn:eval("return box.session.exists(box.session.id())"), "remote session exist check")
 test:isnt(conn:eval("return box.session.peer(box.session.id())"), nil, "remote session peer check")
@@ -187,7 +188,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.23.0



More information about the Tarantool-patches mailing list