Skip to content

Commit cf0623c

Browse files
doujiang24agentzh
authored andcommitted
tests: 147-tcp-socket-timeouts.t was failing in mockeagain read/write test modes.
now we use MOCKEAGAIN_WRITE_TIMEOUT_PATTERN feature instead of sending mega bytes of data. Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
1 parent 521d802 commit cf0623c

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed

t/147-tcp-socket-timeouts.t

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
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+
323
use Test::Nginx::Socket::Lua;
424

525
repeat_each(2);
@@ -145,8 +165,8 @@ lua tcp socket read timed out
145165
return
146166
end
147167

148-
local data = string.rep("a", 8096) -- 8k
149-
local num = 1024 -- total: 8M
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\nHost: localhost\r\nContent-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
206226
GET /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) -- 8k
231-
local num = 1024 -- total: 8M
250+
local data = "slowdata" -- slow data
251+
local num = 10
232252

233253
local req = "POST /foo HTTP/1.0\r\nHost: localhost\r\nContent-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) -- 100ms timeout
361+
sock:settimeouts(200, 200, 200) -- 200ms 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) -- 4k
370+
local data = string.rep("a", 4) -- 4 bytes
353371
local num = 3
354372

355373
local req = "POST /foo HTTP/1.0\r\nHost: localhost\r\nContent-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) -- 20ms
388+
ngx.sleep(0.12) -- 120ms
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: 10ms
426+
sock:settimeout(100) -- send: 100ms
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) -- 100ms timeout
454+
sock:settimeouts(200, 200, 200) -- 200ms 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) -- 4k
463+
local data = string.rep("a", 4) -- 4 bytes
446464
local num = 3
447465

448466
local req = "POST /foo HTTP/1.0\r\nHost: localhost\r\nContent-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) -- 20ms
481+
ngx.sleep(0.12) -- 120ms
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: 10ms, read: 200ms
505+
sock:settimeouts(0, 100, 200) -- send: 100ms, read: 200ms
488506

489-
local chunk = 4048
507+
local chunk = 4
490508

491509
function read()
492510
local data, err = sock:receive(content_length)

0 commit comments

Comments
 (0)