Skip to content

Commit

Permalink
feat(*) remove the _G write guard log in CLI and rbusted
Browse files Browse the repository at this point in the history
The newly introduced _G write guard alert log in OpenResty 1.15.8.1 will
be triggered when setting globals in resty-cli, since the wrapping
context is `ngx.timer`. At runtime, Kong should only set the _G.kong
variable during in the `init_by_lua` context, in which the warning would
not show. By disabling the log, this patch makes rbusted behave more
like runtime Kong, and reduces `stderr` output when running tests.
  • Loading branch information
thibaultcha committed Jul 2, 2019
1 parent cda9558 commit f8c6f26
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions bin/busted
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ if not os.getenv("KONG_BUSTED_RESPAWNED") then
os.exit(rc)
end

setmetatable(_G, nil)

pcall(require, "luarocks.loader")

require("kong.globalpatches")({
Expand Down
2 changes: 2 additions & 0 deletions bin/kong
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env resty

setmetatable(_G, nil)

pcall(require, "luarocks.loader")

package.path = (os.getenv("KONG_LUA_PATH_OVERRIDE") or "") .. "./?.lua;./?/init.lua;" .. package.path
Expand Down
10 changes: 9 additions & 1 deletion kong/globalpatches.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@ return function(options)
ran_before = true



options = options or {}
local meta = require "kong.meta"


if options.cli then
-- disable the _G write guard alert log introduced in OpenResty 1.15.8.1
-- when in CLI or when running tests in resty-cli
--local _G_mt = getmetatable(_G)
setmetatable(_G, nil)
end


_G._KONG = {
_NAME = meta._NAME,
_VERSION = meta._VERSION
Expand Down

0 comments on commit f8c6f26

Please sign in to comment.