Skip to content

Commit

Permalink
luacheck: fix warnings in test/app-tap
Browse files Browse the repository at this point in the history
Closes #5453

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

Co-authored-by: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Co-authored-by: Igor Munkin <imun@tarantool.org>
  • Loading branch information
3 people authored and kyukhin committed Dec 25, 2020
1 parent 7cce4f1 commit eb2e18a
Show file tree
Hide file tree
Showing 27 changed files with 144 additions and 185 deletions.
5 changes: 3 additions & 2 deletions .luacheckrc
@@ -1,8 +1,10 @@
std = "luajit"
globals = {"box", "_TARANTOOL", "tonumber64"}
globals = {"box", "_TARANTOOL", "tonumber64", "utf8"}
ignore = {
-- Accessing an undefined field of a global variable <debug>.
"143/debug",
-- Accessing an undefined field of a global variable <os>.
"143/os",
-- Accessing an undefined field of a global variable <string>.
"143/string",
-- Accessing an undefined field of a global variable <table>.
Expand Down Expand Up @@ -32,7 +34,6 @@ exclude_files = {
"src/box/lua/serpent.lua",
"test-run/**/*.lua",
"test/app/**/*.lua",
"test/app-tap/**/*.lua",
"test/box/**/*.lua",
"test/box-py/**/*.lua",
"test/box-tap/**/*.lua",
Expand Down
2 changes: 1 addition & 1 deletion test/app-tap/cfg.test.lua
Expand Up @@ -12,7 +12,7 @@ test:plan(11)
local nil_uuid = '00000000-0000-0000-0000-000000000000'
local ok = pcall(box.cfg, {instance_uuid = nil_uuid})
test:ok(not ok, 'nil instance UUID is not allowed')
ok, err = pcall(box.cfg, {replicaset_uuid = nil_uuid})
ok = pcall(box.cfg, {replicaset_uuid = nil_uuid})
test:ok(not ok, 'nil replicaset UUID is not allowed')

test:is(type(box.ctl), "table", "box.ctl is available before box.cfg")
Expand Down
4 changes: 2 additions & 2 deletions test/app-tap/clock.test.lua
@@ -1,7 +1,7 @@
#!/usr/bin/env tarantool

clock = require("clock")
test = require("tap").test("csv")
local clock = require("clock")
local test = require("tap").test("csv")
test:plan(10)
test:ok(clock.realtime() > 0, "realtime")
test:ok(clock.thread() > 0, "thread")
Expand Down
12 changes: 5 additions & 7 deletions test/app-tap/console.test.lua
Expand Up @@ -5,9 +5,9 @@ local console = require('console')
local socket = require('socket')
local yaml = require('yaml')
local fiber = require('fiber')
local ffi = require('ffi')
local log = require('log')
local fio = require('fio')
local _

-- Suppress console log messages
log.level(4)
Expand All @@ -19,7 +19,7 @@ os.remove(IPROTO_SOCKET)
--
local EOL = "\n...\n"

test = tap.test("console")
local test = tap.test("console")

test:plan(78)

Expand Down Expand Up @@ -59,7 +59,8 @@ test:is(client:read(";"), 'true;', "pushed message")
client:write('\\set output lua\n')
client:read(";")

long_func_f = nil
local long_func_f = nil
-- luacheck: globals long_func (is called via client socket)
function long_func()
long_func_f = fiber.self()
box.session.push('push')
Expand Down Expand Up @@ -87,12 +88,9 @@ test:is(#client:read(EOL) > 0, true, "_G")
client:write("require('fiber').id()\n")
local fid1 = yaml.decode(client:read(EOL))[1]
local state = fiber.find(fid1).storage.console
local server_info = state.client:peer()
local client_info = state.client:name()
test:is(client_info.host, client_info.host, "state.socker:peer().host")
test:is(client_info.port, client_info.port, "state.socker:peer().port")
server_info = nil
client_info = nil

-- Check console.delimiter()
client:write("require('console').delimiter(';')\n")
Expand Down Expand Up @@ -225,7 +223,7 @@ box.cfg{listen = ''}
os.remove(IPROTO_SOCKET)

local s = console.listen('127.0.0.1:0')
addr = s:name()
local addr = s:name()
test:is(addr.family, 'AF_INET', 'console.listen uri support')
test:is(addr.host, '127.0.0.1', 'console.listen uri support')
test:isnt(addr.port, 0, 'console.listen uri support')
Expand Down
56 changes: 28 additions & 28 deletions test/app-tap/csv.test.lua
Expand Up @@ -2,19 +2,19 @@

local function table2str(t)
local res = ""
for k, line in pairs(t) do
for _, line in pairs(t) do
local s = ""
for k2, field in pairs(line) do
for _, field in pairs(line) do
s = s .. '|' .. field .. '|\t'
end
res = res .. s .. '\n'
end
return res
end

local function myread(self, bytes)
local function myread(self, bytes)
self.i = self.i + bytes
return self.v:sub(self.i - bytes + 1, self.i)
return self.v:sub(self.i - bytes + 1, self.i)
end
local csv = require('csv')
local fio = require('fio')
Expand All @@ -27,18 +27,18 @@ local test4_ans = '|123|\t|5|\t|92|\t|0|\t|0|\t\n|1|\t|12 34|\t|56|\t' ..
local test5_ans = "|1|\t\n|23|\t|456|\t|abcac|\t|'multiword field 4'|\t\n" ..
"|none|\t|none|\t|0|\t\n||\t||\t||\t\n|aba|\t|adda|\t|f" ..
"3|\t|0|\t\n|local res = internal.pwrite(self.fh|\t|dat" ..
"a|\t|len|\t|offset)|\t\n|iflag = bit.bor(iflag|\t|fio." ..
"a|\t|len|\t|offset)|\t\n|iflag = bit.bor(iflag|\t|fio." ..
"c.flag[ flag ])|\t\n||\t||\t||\t\n"
local test6_ans = "|23|\t|456|\t|abcac|\t|'multiword field 4'|\t\n|none|" ..
"\t|none|\t|0|\t\n||\t||\t||\t\n|aba|\t|adda|\t|f3|\t|" ..
"\t|none|\t|0|\t\n||\t||\t||\t\n|aba|\t|adda|\t|f3|\t|" ..
"0|\t\n|local res = internal.pwrite(self.fh|\t|data|\t" ..
"|len|\t|offset)|\t\n|iflag = bit.bor(iflag|\t|fio.c.f" ..
"lag[ flag ])|\t\n||\t||\t||\t\n"

test = tap.test("csv")
local test = tap.test("csv")
test:plan(12)

readable = {}
local readable = {}
readable.read = myread
readable.v = "a,b\n1,\"ha\n\"\"ha\"\"\nha\"\n3,4\n"
readable.i = 0
Expand All @@ -52,17 +52,17 @@ readable.v = ", \r\nkp\"\"v"
readable.i = 0
test:is(table2str(csv.load(readable, {chunk_size = 3})), test3_ans, "obj test3")

tmpdir = fio.tempdir()
file1 = fio.pathjoin(tmpdir, 'file.1')
file2 = fio.pathjoin(tmpdir, 'file.2')
file3 = fio.pathjoin(tmpdir, 'file.3')
file4 = fio.pathjoin(tmpdir, 'file.4')
local tmpdir = fio.tempdir()
local file1 = fio.pathjoin(tmpdir, 'file.1')
local file2 = fio.pathjoin(tmpdir, 'file.2')
local file3 = fio.pathjoin(tmpdir, 'file.3')
local file4 = fio.pathjoin(tmpdir, 'file.4')

local f = fio.open(file1, { 'O_WRONLY', 'O_TRUNC', 'O_CREAT' }, tonumber('0777', 8))
f:write("123 , 5 , 92 , 0, 0\n" ..
"1, 12 34, 56, \"quote , \", 66\nok")
f:close()
f = fio.open(file1, {'O_RDONLY'})
f = fio.open(file1, {'O_RDONLY'})
test:is(table2str(csv.load(f, {chunk_size = 10})), test4_ans, "fio test1")
f:close()

Expand All @@ -77,31 +77,31 @@ f:write("1\n23,456,abcac,\'multiword field 4\'\n" ..
",,"
)
f:close()
f = fio.open(file2, {'O_RDONLY'})
f = fio.open(file2, {'O_RDONLY'})
--symbol by symbol reading
test:is(table2str(csv.load(f, {chunk_size = 1})), test5_ans, "fio test2")
test:is(table2str(csv.load(f, {chunk_size = 1})), test5_ans, "fio test2")
f:close()

f = fio.open(file2, {'O_RDONLY'})
opts = {chunk_size = 7, skip_head_lines = 1}
f = fio.open(file2, {'O_RDONLY'})
local opts = {chunk_size = 7, skip_head_lines = 1}
--7 symbols per chunk
test:is(table2str(csv.load(f, opts)), test6_ans, "fio test3")
test:is(table2str(csv.load(f, opts)), test6_ans, "fio test3")
f:close()

t = {
{'quote" d', ',and, comma', 'both " of " t,h,e,m'},
{'"""', ',","'},
{'mul\nti\nli\r\nne\n\n', 'field'},
{""},
{'"'},
{"\n"}
local t = {
{'quote" d', ',and, comma', 'both " of " t,h,e,m'},
{'"""', ',","'},
{'mul\nti\nli\r\nne\n\n', 'field'},
{""},
{'"'},
{"\n"}
}

f = require("fio").open(file3, { "O_WRONLY", "O_TRUNC" , "O_CREAT"}, 0x1FF)
csv.dump(t, {}, f)
f:close()
f = fio.open(file3, {'O_RDONLY'})
t2 = csv.load(f, {chunk_size = 5})
f = fio.open(file3, {'O_RDONLY'})
local t2 = csv.load(f, {chunk_size = 5})
f:close()

test:is(table2str(t), table2str(t2), "test roundtrip")
Expand Down
4 changes: 2 additions & 2 deletions test/app-tap/fail_main.test.lua
Expand Up @@ -7,7 +7,7 @@ local tarantool_bin = arg[-1]

test:plan(1)

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'},
Expand All @@ -30,7 +30,7 @@ end
-- gh-4382: an error in main script should be handled gracefully,
-- with proper logging.
--
local code, output = run_script("error('Error in the main script')")
local _, output = run_script("error('Error in the main script')")

test:ok(output:match("fatal error, exiting the event loop"),
"main script error is handled gracefully")
Expand Down
8 changes: 4 additions & 4 deletions test/app-tap/gh-4761-json-per-call-options.test.lua
Expand Up @@ -13,8 +13,8 @@ local res = tap.test('gh-4761-json-per-call-options', function(test)
test:plan(2)

-- Preparation code: call :decode() with a custom option.
local ok, err = pcall(json.decode, '{"foo": {"bar": 1}}',
{decode_max_depth = 1})
local ok = pcall(json.decode, '{"foo": {"bar": 1}}',
{decode_max_depth = 1})
assert(not ok, 'expect "too many nested data structures" error')

-- Verify that the instance option remains unchanged.
Expand All @@ -25,8 +25,8 @@ local res = tap.test('gh-4761-json-per-call-options', function(test)

-- Same check for json.encode.
local nan = 1/0
local ok, err = pcall(json.encode, {a = nan},
{encode_invalid_numbers = false})
local ok = pcall(json.encode, {a = nan},
{encode_invalid_numbers = false})
assert(not ok, 'expected "number must not be NaN or Inf" error')
local exp_res = '{"a":inf}'
local ok, res = pcall(json.encode, {a = nan})
Expand Down
2 changes: 1 addition & 1 deletion test/app-tap/gh-5013-fiber-cancel.test.lua
Expand Up @@ -8,7 +8,7 @@ test:plan(2)

local result = {}

function test_f()
local function test_f()
local cond = fiber.cond()
local res, err = pcall(cond.wait, cond)
result.res = res
Expand Down
4 changes: 2 additions & 2 deletions test/app-tap/gh-5130-panic-on-invalid-log.test.lua
Expand Up @@ -9,11 +9,11 @@ test:plan(3)
--

-- Invalid log. No panic, just error
_, err = pcall(log.cfg, {log=' :invalid'})
local _, err = pcall(log.cfg, {log=' :invalid'})
test:like(err, "expecting a file name or a prefix")

-- Empty string - default log (to be compatible with box.cfg)
ok = pcall(log.cfg, {log=''})
local ok = pcall(log.cfg, {log=''})
test:ok(ok)

-- Dynamic reconfiguration - error, no info about invalid logger type
Expand Down
25 changes: 8 additions & 17 deletions test/app-tap/http_client.test.lua
Expand Up @@ -42,7 +42,7 @@ local function start_server(test, sock_family, sock_addr)
test:is(server:read("*l"), "heartbeat", "server started")
test:diag("trying to connect to %s", url)
local r
for i=1,10 do
for _=1,10 do
r = client.get(url, merge(opts, {timeout = 0.01}))
if r.status == 200 then
break
Expand Down Expand Up @@ -164,7 +164,7 @@ local function test_cancel_and_errinj(test, url, opts)
local errinj = box.error.injection
errinj.set('ERRINJ_HTTP_RESPONSE_ADD_WAIT', true)
local topts = merge(opts, {timeout = 1200})
f = fiber.create(func, topts)
fiber.create(func, topts)
r = ch:get()
test:is(r.status, 200, "No hangs in errinj")
errinj.set('ERRINJ_HTTP_RESPONSE_ADD_WAIT', false)
Expand All @@ -180,7 +180,6 @@ local function test_post_and_get(test, url, opts)
local my_body = { key = "value" }
local json_body = json.encode(my_body)
local responses = {}
local data = {a = 'b'}
headers['Content-Type'] = 'application/json'
local fibers = 7
local ch = fiber.channel(fibers)
Expand Down Expand Up @@ -213,7 +212,7 @@ local function test_post_and_get(test, url, opts)
responses.absent_get = http:get(url .. 'absent', opts)
ch:put(1)
end)
for i=1,fibers do
for _=1,fibers do
ch:get()
end
local r = responses.good_get
Expand Down Expand Up @@ -270,7 +269,6 @@ local function test_errors(test)
test:ok(not status and string.find(json.encode(err),
"Unsupported protocol"),
"POST: exception on bad protocol")
local r = http:get("http://do_not_exist_8ffad33e0cb01e6a01a03d00089e71e5b2b7e9930dfcba.ru")
end

-- gh-3679 Check that opts.headers values can be strings only.
Expand Down Expand Up @@ -355,7 +353,7 @@ local function test_request_headers(test, url, opts)
local http = client:new()

for _, case in ipairs(cases) do
local opts = merge(table.copy(opts), case.opts)
opts = merge(table.copy(opts), case.opts)
local ok, err = pcall(http.get, http, url, opts)
if case.postrequest_check ~= nil then
case.postrequest_check(opts)
Expand Down Expand Up @@ -425,7 +423,6 @@ local function test_special_methods(test, url, opts)
local responses = {}
local fibers = 7
local ch = fiber.channel(fibers)
local _
fiber.create(function()
responses.patch_data = http:patch(url, "{\"key\":\"val\"}", opts)
ch:put(1)
Expand Down Expand Up @@ -454,7 +451,7 @@ local function test_special_methods(test, url, opts)
responses.custom_data = http:request("CUSTOM", url, nil, opts)
ch:put(1)
end)
for i = 1, fibers do
for _ = 1, fibers do
ch:get()
end

Expand Down Expand Up @@ -483,10 +480,6 @@ end

local function test_concurrent(test, url, opts)
test:plan(3)
local http = client.new()
local headers = { my_header = "1", my_header2 = "2" }
local my_body = { key = "value" }
local json_body = json.encode(my_body)
local num_test = 10
local num_load = 10
local curls = { }
Expand All @@ -497,7 +490,7 @@ local function test_concurrent(test, url, opts)
headers["My-header" .. i] = "my-value"
end

for i = 1, num_test do
for _ = 1, num_test do
table.insert(curls, {
url = url,
http = client.new(),
Expand All @@ -515,7 +508,7 @@ local function test_concurrent(test, url, opts)
-- Creating concurrent clients
for i=1,num_test do
local obj = curls[i]
for j=1,num_load do
for _=1,num_load do
fiber.create(function()
local r = obj.http:post(obj.url, obj.body, merge(opts, {
headers = obj.headers,
Expand All @@ -540,13 +533,11 @@ local function test_concurrent(test, url, opts)
end
local ok_sockets_added = true
local ok_active = true
local ok_timeout = true
local ok_req = true

-- Join test
local rest = num_test
while true do
local ticks = 0
for i = 1, num_load do
local obj = curls[i]
-- checking that stats in concurrent are ok
Expand Down Expand Up @@ -582,7 +573,7 @@ local function test_concurrent(test, url, opts)
test:ok(ok_active, "no active requests")
end

function run_tests(test, sock_family, sock_addr)
local function run_tests(test, sock_family, sock_addr)
test:plan(11)
local server, url, opts = start_server(test, sock_family, sock_addr)
test:test("http.client", test_http_client, url, opts)
Expand Down

0 comments on commit eb2e18a

Please sign in to comment.