@@ -19,7 +19,7 @@ run_tests();
19
19
20
20
__DATA__
21
21
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
23
23
--- stream_server_config
24
24
content_by_lua_block {
25
25
local loaded_resty_core = package.loaded["resty.core"]
@@ -32,36 +32,37 @@ resty.core loaded: true
32
32
33
33
34
34
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
36
36
--- stream_config
37
- lua_load_resty_core off ;
37
+ lua_shared_dict dogs 128k ;
38
38
--- stream_server_config
39
39
content_by_lua_block {
40
40
local loaded_resty_core = package.loaded["resty.core"]
41
+ local resty_core = require "resty.core"
41
42
42
- ngx.say("resty.core loaded: ", loaded_resty_core ~= nil )
43
+ ngx.say("resty.core loaded: ", loaded_resty_core == resty_core )
43
44
}
44
45
--- stream_response
45
- resty.core loaded: false
46
+ resty.core loaded: true
46
47
47
48
48
49
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'
50
51
--- stream_config
51
- lua_shared_dict dogs 128k ;
52
+ lua_code_cache off ;
52
53
--- stream_server_config
53
54
content_by_lua_block {
54
55
local loaded_resty_core = package.loaded["resty.core"]
55
56
local resty_core = require "resty.core"
56
57
57
- ngx.say("resty.core loaded: ", loaded_resty_core == resty_core )
58
+ ngx.say("resty.core loaded: ", loaded_resty_core ~= nil )
58
59
}
59
60
--- stream_response
60
61
resty.core loaded: true
61
62
62
63
63
64
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
65
66
--- stream_config eval
66
67
"lua_package_path '$::HtmlDir/?.lua;;';"
67
68
--- stream_server_config
@@ -86,208 +87,63 @@ return {
86
87
87
88
88
89
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;';"
102
93
--- stream_server_config
103
94
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")
151
96
}
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:/
155
100
156
101
157
102
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;
164
106
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 = ""
169
109
}
170
- --- stream_config
171
- lua_load_resty_core off;
172
110
--- stream_server_config
173
111
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")
220
113
}
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/
224
118
225
119
226
120
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")
239
127
}
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)
240
138
--- stream_config
241
139
lua_load_resty_core off;
242
140
--- stream_server_config
243
141
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")
290
143
}
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