1
# vim:set ft= ts=4 sw=4 et fdm=marker:
4
use Test::Nginx::Socket;
7
our $GCScript = <<_EOC_;
8
$t::StapThread::GCScript
10
F(ngx_http_lua_check_broken_connection) {
11
println("lua check broken conn")
14
F(ngx_http_lua_request_cleanup) {
15
println("lua req cleanup")
19
our $StapScript = $t::StapThread::StapScript;
23
plan tests => repeat_each() * (blocks() * 3 - 1);
25
$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
26
$ENV{TEST_NGINX_MEMCACHED_PORT} ||= '11211';
27
$ENV{TEST_NGINX_REDIS_PORT} ||= '6379';
35
=== TEST 1: sleep + stop
38
lua_check_client_abort on;
46
--- stap2 eval: $::StapScript
47
--- stap eval: $::GCScript
60
client prematurely closed connection
64
=== TEST 2: sleep + stop (log handler still gets called)
67
lua_check_client_abort on;
72
ngx.log(ngx.NOTICE, "here in log by lua")
78
--- stap2 eval: $::StapScript
79
--- stap eval: $::GCScript
91
client prematurely closed connection
96
=== TEST 3: sleep + ignore
99
lua_check_client_abort off;
103
content_by_lua return;
108
--- stap2 eval: $::StapScript
109
--- stap eval: $::GCScript
126
=== TEST 4: subrequest + stop
129
lua_check_client_abort on;
131
ngx.location.capture("/sub")
132
error("bad things happen")
142
--- stap2 eval: $::StapScript
143
--- stap eval: $::GCScript
145
lua check broken conn
155
client prematurely closed connection
159
=== TEST 5: subrequest + ignore
162
lua_check_client_abort off;
164
ngx.location.capture("/sub")
165
error("bad things happen")
175
--- stap2 eval: $::StapScript
176
--- stap eval: $::GCScript
191
=== TEST 6: subrequest + stop (proxy, ignore client abort)
194
lua_check_client_abort on;
196
ngx.location.capture("/sub")
197
error("bad things happen")
202
proxy_ignore_client_abort on;
203
proxy_pass http://www.google.com:1234/;
207
lua_check_client_abort on;
215
--- stap2 eval: $::StapScript
216
--- stap eval: $::GCScript
218
lua check broken conn
228
client prematurely closed connection
232
=== TEST 7: subrequest + stop (proxy, check client abort)
235
lua_check_client_abort on;
237
ngx.location.capture("/sub")
238
error("bad things happen")
243
proxy_ignore_client_abort off;
244
proxy_pass http://www.google.com:1234/;
249
--- stap2 eval: $::StapScript
250
--- stap eval: $::GCScript
252
lua check broken conn
262
client prematurely closed connection
266
=== TEST 8: need body on + sleep + stop (log handler still gets called)
269
lua_check_client_abort on;
270
lua_need_request_body on;
275
ngx.log(ngx.NOTICE, "here in log by lua")
282
--- stap2 eval: $::StapScript
283
--- stap eval: $::GCScript
285
lua check broken conn
295
client prematurely closed connection
300
=== TEST 9: ngx.req.read_body + sleep + stop (log handler still gets called)
303
lua_check_client_abort on;
309
ngx.log(ngx.NOTICE, "here in log by lua")
316
--- stap2 eval: $::StapScript
317
--- stap eval: $::GCScript
319
lua check broken conn
329
client prematurely closed connection
334
=== TEST 10: ngx.req.socket + receive() + sleep + stop
337
lua_check_client_abort on;
339
local sock = ngx.req.socket()
348
--- stap2 eval: $::StapScript
349
--- stap eval: $::GCScript
351
lua check broken conn
361
client prematurely closed connection
365
=== TEST 11: ngx.req.socket + receive(N) + sleep + stop
368
lua_check_client_abort on;
370
local sock = ngx.req.socket()
379
--- stap2 eval: $::StapScript
380
--- stap eval: $::GCScript
382
lua check broken conn
383
lua check broken conn
393
client prematurely closed connection
397
=== TEST 12: ngx.req.socket + receive(n) + sleep + stop
400
lua_check_client_abort on;
402
local sock = ngx.req.socket()
406
content_by_lua return;
412
--- stap2 eval: $::StapScript
413
--- stap eval: $::GCScript
415
^(?:lua check broken conn
420
lua req cleanup|lua check broken conn
433
=== TEST 13: ngx.req.socket + m * receive(n) + sleep + stop
436
lua_check_client_abort on;
438
local sock = ngx.req.socket()
449
--- stap2 eval: $::StapScript
450
--- stap eval: $::GCScript
452
lua check broken conn
453
lua check broken conn
464
client prematurely closed connection
468
=== TEST 14: ngx.req.socket + receiveuntil + sleep + stop
471
lua_check_client_abort on;
473
local sock = ngx.req.socket()
474
local it = sock:receiveuntil("\\n")
483
--- stap2 eval: $::StapScript
484
--- stap eval: $::GCScript
486
lua check broken conn
497
client prematurely closed connection
501
=== TEST 15: ngx.req.socket + receiveuntil + it(n) + sleep + stop
504
lua_check_client_abort on;
506
local sock = ngx.req.socket()
507
local it = sock:receiveuntil("\\n")
517
--- stap2 eval: $::StapScript
518
--- stap eval: $::GCScript
520
lua check broken conn
521
lua check broken conn
531
client prematurely closed connection
535
=== TEST 16: cosocket + stop
538
lua_check_client_abort on;
540
ngx.req.discard_body()
542
local sock, err = ngx.socket.tcp()
544
ngx.log(ngx.ERR, "failed to get socket: ", err)
548
ok, err = sock:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
550
ngx.log(ngx.ERR, "failed to connect: ", err)
554
local bytes, err = sock:send("blpop nonexist 2\\r\\n")
556
ngx.log(ngx.ERR, "failed to send query: ", err)
560
-- ngx.log(ngx.ERR, "about to receive")
562
local res, err = sock:receive()
564
ngx.log(ngx.ERR, "failed to receive query: ", err)
568
ngx.log(ngx.ERR, "res: ", res)
574
--- stap2 eval: $::StapScript
575
--- stap eval: $::GCScript
577
lua check broken conn
588
client prematurely closed connection
592
=== TEST 17: ngx.req.socket + receive n < content-length + stop
595
lua_check_client_abort on;
597
local sock = ngx.req.socket()
598
local res, err = sock:receive("*a")
600
ngx.log(ngx.NOTICE, "failed to receive: ", err)
605
content_by_lua return;
611
Content-Length: 100\r
614
--- stap2 eval: $::StapScript
615
--- stap eval: $::GCScript
629
failed to receive: client aborted
633
=== TEST 18: ngx.req.socket + receive n == content-length + stop
636
lua_check_client_abort on;
638
local sock = ngx.req.socket()
639
local res, err = sock:receive("*a")
641
ngx.log(ngx.NOTICE, "failed to receive: ", err)
648
content_by_lua return;
657
--- stap2 eval: $::StapScript
658
--- stap eval: $::GCScript
660
lua check broken conn
661
lua check broken conn
671
client prematurely closed connection
675
=== TEST 19: ngx.req.socket + receive n == content-length + ignore
679
local sock = ngx.req.socket()
680
local res, err = sock:receive("*a")
682
ngx.log(ngx.NOTICE, "failed to receive: ", err)
687
content_by_lua return;
696
--- stap2 eval: $::StapScript
697
--- stap eval: $::GCScript
713
=== TEST 20: ngx.req.read_body + sleep + stop (log handler still gets called)
716
lua_check_client_abort on;
720
content_by_lua return;
726
--- stap2 eval: $::StapScript
727
--- stap eval: $::GCScript
742
=== TEST 21: exec to lua + ignore
745
lua_check_client_abort on;
752
lua_check_client_abort off;
760
--- stap2 eval: $::StapScript
761
--- stap eval: $::GCScript
780
=== TEST 22: exec to proxy + ignore
783
lua_check_client_abort on;
790
proxy_ignore_client_abort on;
791
proxy_pass http://127.0.0.1:$server_port/sleep;
800
--- stap2 eval: $::StapScript
801
--- stap eval: $::GCScript
817
=== TEST 23: exec (named location) to proxy + ignore
820
lua_check_client_abort on;
827
proxy_ignore_client_abort on;
828
proxy_pass http://127.0.0.1:$server_port/sleep;
837
--- stap2 eval: $::StapScript
838
--- stap eval: $::GCScript