Skip to content

Commit

Permalink
bugfix: missing clear table before to reuse table. (apache#1134)
Browse files Browse the repository at this point in the history
* test: avoid to use regex for matching output.
  • Loading branch information
membphis authored and qiujiayu committed Feb 21, 2020
1 parent 31fef2b commit 471c4a1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
10 changes: 6 additions & 4 deletions lua/apisix/core/response.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ local error = error
local select = select
local type = type
local ngx_exit = ngx.exit
local insert_tab = table.insert
local concat_tab = table.concat
local str_sub = string.sub
local tonumber = tonumber
local clear_tab = require("table.clear")
local pairs = pairs

local _M = {version = 0.1}
Expand All @@ -37,10 +37,12 @@ do
local idx = 1

function resp_exit(code, ...)
clear_tab(t)
idx = 0

if code and type(code) ~= "number" then
insert_tab(t, code)
idx = idx + 1
t[idx] = code
code = nil
end

Expand All @@ -56,12 +58,12 @@ function resp_exit(code, ...)
error("failed to encode data: " .. err, -2)
else
idx = idx + 1
insert_tab(t, idx, body .. "\n")
t[idx] = body .. "\n"
end

elseif v ~= nil then
idx = idx + 1
insert_tab(t, idx, v)
t[idx] = v
end
end

Expand Down
31 changes: 19 additions & 12 deletions t/admin/routes.t
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,7 @@ passed
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local core = require("apisix.core")
-- set
local code, body, res = t('/apisix/admin/routes/1?ttl=1',
ngx.HTTP_PUT,
Expand All @@ -1383,7 +1384,7 @@ location /t {
}]]
)

if code >= 300 then ngx.print("code: ", code, " ") end
ngx.say("code: ", code)
ngx.say(body)

-- get
Expand All @@ -1400,24 +1401,27 @@ location /t {
}]]
)

if code >= 300 then ngx.print("code: ", code, " ") end
ngx.say("code: ", code)
ngx.say(body)

ngx.sleep(2)

-- get again
code, body, res = t('/apisix/admin/routes/1', ngx.HTTP_GET)

if code >= 300 then ngx.print("code: ", code, " ") end
ngx.print(body)
ngx.say("code: ", code)
ngx.say("message: ", core.json.decode(body).message)
}
}
--- request
GET /t
--- response_body_like eval
qr$passed
--- response_body
code: 200
passed
code: 200
passed
code: 404 {"cause":"\\/apisix\\/routes\\/1","index":\d+,"errorCode":100,"message":"Key not found"}$
code: 404
message: Key not found
--- no_error_log
[error]
--- timeout: 5
Expand All @@ -1429,6 +1433,8 @@ code: 404 {"cause":"\\/apisix\\/routes\\/1","index":\d+,"errorCode":100,"message
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local core = require("apisix.core")

local code, body, res = t('/apisix/admin/routes?ttl=1',
ngx.HTTP_POST,
[[{
Expand Down Expand Up @@ -1456,15 +1462,16 @@ location /t {
local id = string.sub(res.node.key, #"/apisix/routes/" + 1)
code, body = t('/apisix/admin/routes/' .. id, ngx.HTTP_GET)

if code >= 300 then ngx.print("code: ", code, " ") end
ngx.print(body)
ngx.say("code: ", code)
ngx.say("message: ", core.json.decode(body).message)
}
}
--- request
GET /t
--- response_body_like eval
qr$succ: passed
code: 404 {"cause":"\\/apisix\\/routes\\/\d+","index":\d+,"errorCode":100,"message":"Key not found"}$
--- response_body
[push] succ: passed
code: 404
message: Key not found
--- no_error_log
[error]
--- timeout: 5
Expand Down
1 change: 0 additions & 1 deletion utils/check-lua-code-style.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ luacheck -q lua
lua/apisix/plugins/limit-count/*.lua > \
/tmp/check.log 2>&1 || (cat /tmp/check.log && exit 1)

sed -i 's/.*newproxy.*//g' /tmp/check.log
count=`grep -E ".lua:[0-9]+:" /tmp/check.log -c || true`

if [ $count -ne 0 ]
Expand Down

0 comments on commit 471c4a1

Please sign in to comment.