11# vim:set ft= ts=4 sw=4 et fdm=marker:
22
3+ BEGIN {
4+ if (! defined $ ENV {LD_PRELOAD}) {
5+ $ ENV {LD_PRELOAD} = ' ' ;
6+ }
7+
8+ if ($ ENV {LD_PRELOAD} !~ / \bmockeagain\. so \b/ ) {
9+ $ ENV {LD_PRELOAD} = " mockeagain.so $ ENV{ LD_PRELOAD} " ;
10+ }
11+
12+ if ($ ENV {MOCKEAGAIN} eq ' r' ) {
13+ $ ENV {MOCKEAGAIN} = ' rw' ;
14+
15+ } else {
16+ $ ENV {MOCKEAGAIN} = ' w' ;
17+ }
18+
19+ $ ENV {TEST_NGINX_EVENT_TYPE} = ' poll' ;
20+ $ ENV {MOCKEAGAIN_WRITE_TIMEOUT_PATTERN} = ' slowdata' ;
21+ }
22+
323use Test ::Nginx::Socket::Lua;
424
525repeat_each(2 );
@@ -145,8 +165,8 @@ lua tcp socket read timed out
145165 return
146166 end
147167
148- local data = string. rep(" a" , 8096 ) -- 8 k
149- local num = 1024 -- total: 8 M
168+ local data = string. rep(" a" , 8 ) -- 8 bytes
169+ local num = 10 -- total: 80 bytes
150170
151171 local req = " POST /foo HTTP/1.0\r\n Host: localhost\r\n Content-Length: "
152172 .. # data * num .. "\r\nConnection: close\r\n\r\n"
@@ -188,7 +208,7 @@ lua tcp socket read timed out
188208
189209 sock: settimeouts(500 , 500 , 500 )
190210
191- local chunk = 8096
211+ local chunk = 8
192212
193213 for i = 1 , content_length, chunk do
194214 local data, err = sock: receive(chunk)
@@ -205,7 +225,7 @@ lua tcp socket read timed out
205225-- - request
206226GET / t
207227-- - response_body_like
208- received: got len: 8290304
228+ received: got len: 80
209229-- - no_error_log
210230[error]
211231
@@ -227,8 +247,8 @@ received: got len: 8290304
227247 return
228248 end
229249
230- local data = string . rep( " a " , 8096 ) -- 8 k
231- local num = 1024 -- total : 8 M
250+ local data = " slowdata " -- slow data
251+ local num = 10
232252
233253 local req = " POST /foo HTTP/1.0\r\n Host: localhost\r\n Content-Length: "
234254 .. # data * num .. "\r\nConnection: close\r\n\r\n"
@@ -268,11 +288,9 @@ received: got len: 8290304
268288
269289 local sock = ngx. req. socket()
270290
271- ngx. sleep (1 )
272-
273291 sock: settimeouts(500 , 500 , 500 )
274292
275- local chunk = 8096
293+ local chunk = 8
276294
277295 for i = 1 , content_length, chunk do
278296 local data, err = sock: receive(chunk)
@@ -340,7 +358,7 @@ lua tcp socket connect timed out
340358 content_by_lua_block {
341359 local sock = ngx. socket. tcp()
342360
343- sock: settimeouts(100 , 100 , 100 ) -- 100 ms timeout
361+ sock: settimeouts(200 , 200 , 200 ) -- 200 ms timeout
344362
345363 local port = ngx. var. server_port
346364 local ok , err = sock: connect(" 127.0.0.1" , port)
@@ -349,7 +367,7 @@ lua tcp socket connect timed out
349367 return
350368 end
351369
352- local data = string. rep(" a" , 4048 ) -- 4 k
370+ local data = string. rep(" a" , 4 ) -- 4 bytes
353371 local num = 3
354372
355373 local req = " POST /foo HTTP/1.0\r\n Host: localhost\r\n Content-Length: "
@@ -367,7 +385,7 @@ lua tcp socket connect timed out
367385 ngx. log (ngx. ERR, " failed to send body: " , err)
368386 return
369387 end
370- ngx. sleep (0.08 ) -- 20 ms
388+ ngx. sleep (0.12 ) -- 120 ms
371389 end
372390
373391 while true do
@@ -391,7 +409,7 @@ lua tcp socket connect timed out
391409
392410 local sock = ngx. req. socket(true)
393411
394- local chunk = 4048
412+ local chunk = 4
395413
396414 function read ()
397415 sock: settimeout(200 ) -- read : 200 ms
@@ -405,7 +423,7 @@ lua tcp socket connect timed out
405423
406424 local co = ngx. thread. spawn(read )
407425
408- sock: settimeout(10 ) -- send: 10 ms
426+ sock: settimeout(100 ) -- send: 100 ms
409427 sock: send(" ok\n " )
410428
411429 local ok , err = ngx. thread. wait (co)
@@ -433,7 +451,7 @@ failed to receive data: timeout
433451 content_by_lua_block {
434452 local sock = ngx. socket. tcp()
435453
436- sock: settimeouts(100 , 100 , 100 ) -- 100 ms timeout
454+ sock: settimeouts(200 , 200 , 200 ) -- 200 ms timeout
437455
438456 local port = ngx. var. server_port
439457 local ok , err = sock: connect(" 127.0.0.1" , port)
@@ -442,7 +460,7 @@ failed to receive data: timeout
442460 return
443461 end
444462
445- local data = string. rep(" a" , 4048 ) -- 4 k
463+ local data = string. rep(" a" , 4 ) -- 4 bytes
446464 local num = 3
447465
448466 local req = " POST /foo HTTP/1.0\r\n Host: localhost\r\n Content-Length: "
@@ -460,7 +478,7 @@ failed to receive data: timeout
460478 ngx. log (ngx. ERR, " failed to send body: " , err)
461479 return
462480 end
463- ngx. sleep (0.08 ) -- 20 ms
481+ ngx. sleep (0.12 ) -- 120 ms
464482 end
465483
466484 while true do
@@ -484,9 +502,9 @@ failed to receive data: timeout
484502
485503 local sock = ngx. req. socket(true)
486504
487- sock: settimeouts(0 , 10 , 200 ) -- send: 10 ms , read : 200 ms
505+ sock: settimeouts(0 , 100 , 200 ) -- send: 100 ms , read : 200 ms
488506
489- local chunk = 4048
507+ local chunk = 4
490508
491509 function read ()
492510 local data, err = sock: receive(content_length)
0 commit comments