Skip to content

Commit b404b07

Browse files
committed
tests: 161-load-resty-core.t: updated the test cases to reflect the deprecation of the 'lua_load_resty_core' directive.
1 parent e425e2c commit b404b07

File tree

1 file changed

+50
-194
lines changed

1 file changed

+50
-194
lines changed

t/161-load-resty-core.t

Lines changed: 50 additions & 194 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ run_tests();
1919

2020
__DATA__
2121
22-
=== TEST 1: lua_load_resty_core is enabled by default
22+
=== TEST 1: lua_load_resty_core is automatically loaded in the Lua VM
2323
--- stream_server_config
2424
content_by_lua_block {
2525
local loaded_resty_core = package.loaded["resty.core"]
@@ -32,36 +32,37 @@ resty.core loaded: true
3232
3333
3434
35-
=== TEST 2: lua_load_resty_core can be disabled
35+
=== TEST 2: resty.core is automatically loaded in the Lua VM when 'lua_shared_dict' is used
3636
--- stream_config
37-
lua_load_resty_core off;
37+
lua_shared_dict dogs 128k;
3838
--- stream_server_config
3939
content_by_lua_block {
4040
local loaded_resty_core = package.loaded["resty.core"]
41+
local resty_core = require "resty.core"
4142
42-
ngx.say("resty.core loaded: ", loaded_resty_core ~= nil)
43+
ngx.say("resty.core loaded: ", loaded_resty_core == resty_core)
4344
}
4445
--- stream_response
45-
resty.core loaded: false
46+
resty.core loaded: true
4647
4748
4849
49-
=== TEST 3: lua_load_resty_core is effective when using lua_shared_dict
50+
=== TEST 3: resty.core is automatically loaded in the Lua VM with 'lua_code_cache off'
5051
--- stream_config
51-
lua_shared_dict dogs 128k;
52+
lua_code_cache off;
5253
--- stream_server_config
5354
content_by_lua_block {
5455
local loaded_resty_core = package.loaded["resty.core"]
5556
local resty_core = require "resty.core"
5657
57-
ngx.say("resty.core loaded: ", loaded_resty_core == resty_core)
58+
ngx.say("resty.core loaded: ", loaded_resty_core ~= nil)
5859
}
5960
--- stream_response
6061
resty.core loaded: true
6162
6263
6364
64-
=== TEST 4: lua_load_resty_core honors the lua_package_path directive
65+
=== TEST 4: resty.core loading honors the lua_package_path directive
6566
--- stream_config eval
6667
"lua_package_path '$::HtmlDir/?.lua;;';"
6768
--- stream_server_config
@@ -86,208 +87,63 @@ return {
8687
8788
8889
89-
=== TEST 5: lua_load_resty_core 'on' in stream block and 'off' in http block
90-
--- http_config
91-
lua_load_resty_core off;
92-
--- config
93-
location = /t2 {
94-
content_by_lua_block {
95-
local loaded_resty_core = package.loaded["resty.core"]
96-
97-
local msg = "resty.core loaded in http: " .. tostring(loaded_resty_core ~= nil)
98-
ngx.header["Content-Length"] = #msg
99-
ngx.say(msg)
100-
}
101-
}
90+
=== TEST 5: resty.core not loading aborts the initialization
91+
--- stream_config eval
92+
"lua_package_path '$::HtmlDir/?.lua;';"
10293
--- stream_server_config
10394
content_by_lua_block {
104-
local loaded_resty_core = package.loaded["resty.core"]
105-
local resty_core = require "resty.core"
106-
107-
ngx.say("resty.core loaded in stream: ", loaded_resty_core == resty_core)
108-
109-
local sock = ngx.socket.tcp()
110-
local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_SERVER_PORT)
111-
if not ok then
112-
ngx.say("failed to connect: ", err)
113-
return
114-
end
115-
116-
local req = "GET /t2 HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"
117-
118-
local bytes, err = sock:send(req)
119-
if not bytes then
120-
ngx.say("failed to send request: ", err)
121-
return
122-
end
123-
124-
local cl
125-
126-
while true do
127-
local line, err, part = sock:receive("*l")
128-
if err then
129-
ngx.say("failed to receive headers: ", err, " [", part, "]")
130-
break
131-
end
132-
133-
local k, v = line:match("([^:]*):%s*(.*)")
134-
if k == "Content-Length" then
135-
cl = v
136-
end
137-
138-
if line == "" then
139-
local body, err = sock:receive(cl)
140-
if err then
141-
ngx.say("failed to receive body: ", err)
142-
break
143-
end
144-
145-
ngx.say(body)
146-
break
147-
end
148-
end
149-
150-
ok, err = sock:close()
95+
ngx.say("ok")
15196
}
152-
--- stream_response
153-
resty.core loaded in stream: true
154-
resty.core loaded in http: false
97+
--- must_die
98+
--- error_log eval
99+
qr/\[alert\] .*? failed to load the 'resty\.core' module .*? \(reason: module 'resty\.core' not found:/
155100
156101
157102
158-
=== TEST 6: lua_load_resty_core 'off' in stream block and 'on' in http block
159-
--- config
160-
location = /t2 {
161-
content_by_lua_block {
162-
local loaded_resty_core = package.loaded["resty.core"]
163-
local resty_core = require "resty.core"
103+
=== TEST 6: resty.core not loading produces an error with 'lua_code_cache off'
104+
--- stream_config
105+
lua_code_cache off;
164106
165-
local msg = "resty.core loaded in http: " .. tostring(loaded_resty_core == resty_core)
166-
ngx.header["Content-Length"] = #msg
167-
ngx.say(msg)
168-
}
107+
init_by_lua_block {
108+
package.path = ""
169109
}
170-
--- stream_config
171-
lua_load_resty_core off;
172110
--- stream_server_config
173111
content_by_lua_block {
174-
local loaded_resty_core = package.loaded["resty.core"]
175-
176-
ngx.say("resty.core loaded in stream: ", loaded_resty_core ~= nil)
177-
178-
local sock = ngx.socket.tcp()
179-
local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_SERVER_PORT)
180-
if not ok then
181-
ngx.say("failed to connect: ", err)
182-
return
183-
end
184-
185-
local req = "GET /t2 HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"
186-
187-
local bytes, err = sock:send(req)
188-
if not bytes then
189-
ngx.say("failed to send request: ", err)
190-
return
191-
end
192-
193-
local cl
194-
195-
while true do
196-
local line, err, part = sock:receive("*l")
197-
if err then
198-
ngx.say("failed to receive headers: ", err, " [", part, "]")
199-
break
200-
end
201-
202-
local k, v = line:match("([^:]*):%s*(.*)")
203-
if k == "Content-Length" then
204-
cl = v
205-
end
206-
207-
if line == "" then
208-
local body, err = sock:receive(cl)
209-
if err then
210-
ngx.say("failed to receive body: ", err)
211-
break
212-
end
213-
214-
ngx.say(body)
215-
break
216-
end
217-
end
218-
219-
ok, err = sock:close()
112+
ngx.say("ok")
220113
}
221-
--- stream_response
222-
resty.core loaded in stream: false
223-
resty.core loaded in http: true
114+
--- error_log eval
115+
qr/\[error\] .*? failed to load the 'resty\.core' module .*? \(reason: module 'resty\.core' not found:/
116+
--- no_error_log eval
117+
qr/\[alert\] .*? failed to load the 'resty\.core' module/
224118
225119
226120
227-
=== TEST 7: lua_load_resty_core 'off' in stream block and 'off' in http block
228-
--- http_config
229-
lua_load_resty_core off;
230-
--- config
231-
location = /t2 {
232-
content_by_lua_block {
233-
local loaded_resty_core = package.loaded["resty.core"]
234-
235-
local msg = "resty.core loaded in http: " .. tostring(loaded_resty_core ~= nil)
236-
ngx.header["Content-Length"] = #msg
237-
ngx.say(msg)
238-
}
121+
=== TEST 7: lua_load_resty_core logs a deprecation warning when specified (on)
122+
--- stream_config
123+
lua_load_resty_core on;
124+
--- stream_server_config
125+
content_by_lua_block {
126+
ngx.say("ok")
239127
}
128+
--- grep_error_log eval: qr/\[warn\] .*? lua_load_resty_core is deprecated.*/
129+
--- grep_error_log_out eval
130+
[
131+
qr/\[warn\] .*? lua_load_resty_core is deprecated \(the lua-resty-core library is required since ngx_stream_lua v0\.0\.8\) in .*?nginx\.conf:\d+/,
132+
""
133+
]
134+
135+
136+
137+
=== TEST 8: lua_load_resty_core logs a deprecation warning when specified (off)
240138
--- stream_config
241139
lua_load_resty_core off;
242140
--- stream_server_config
243141
content_by_lua_block {
244-
local loaded_resty_core = package.loaded["resty.core"]
245-
246-
ngx.say("resty.core loaded in stream: ", loaded_resty_core ~= nil)
247-
248-
local sock = ngx.socket.tcp()
249-
local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_SERVER_PORT)
250-
if not ok then
251-
ngx.say("failed to connect: ", err)
252-
return
253-
end
254-
255-
local req = "GET /t2 HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"
256-
257-
local bytes, err = sock:send(req)
258-
if not bytes then
259-
ngx.say("failed to send request: ", err)
260-
return
261-
end
262-
263-
local cl
264-
265-
while true do
266-
local line, err, part = sock:receive("*l")
267-
if err then
268-
ngx.say("failed to receive headers: ", err, " [", part, "]")
269-
break
270-
end
271-
272-
local k, v = line:match("([^:]*):%s*(.*)")
273-
if k == "Content-Length" then
274-
cl = v
275-
end
276-
277-
if line == "" then
278-
local body, err = sock:receive(cl)
279-
if err then
280-
ngx.say("failed to receive body: ", err)
281-
break
282-
end
283-
284-
ngx.say(body)
285-
break
286-
end
287-
end
288-
289-
ok, err = sock:close()
142+
ngx.say("ok")
290143
}
291-
--- stream_response
292-
resty.core loaded in stream: false
293-
resty.core loaded in http: false
144+
--- grep_error_log eval: qr/\[warn\] .*? lua_load_resty_core is deprecated.*/
145+
--- grep_error_log_out eval
146+
[
147+
qr/\[warn\] .*? lua_load_resty_core is deprecated \(the lua-resty-core library is required since ngx_stream_lua v0\.0\.8\) in .*?nginx\.conf:\d+/,
148+
""
149+
]

0 commit comments

Comments
 (0)