~spuul/nginx/trunk

« back to all changes in this revision

Viewing changes to debian/modules/nginx-lua/t/065-tcp-socket-timeout.t

  • Committer: Package Import Robot
  • Author(s): Christos Trochalakis, Christos Trochalakis
  • Date: 2014-02-13 11:41:49 UTC
  • mfrom: (1.3.32)
  • mto: This revision was merged to the branch mainline in revision 72.
  • Revision ID: package-import@ubuntu.com-20140213114149-tkp78c45rzu3wr6y
Tags: 1.4.5-1
[ Christos Trochalakis ]
* New upstream release.
* debian/modules/nginx-lua:
  + Update nginx-lua to v0.9.4
* debian/nginx-naxsi-ui.preinst:
  + Fix exit status issue (Closes: #735152)
* debian/control:
  + Fix arch:all to arch:any dependencies
  + Make nginx depend on specific flavor version
* debian/nginx-*.postinst:
  + Make nginx start by default (Closes: #735551)
* debian/nginx-*.prerm:
  + No need to check for invoke-rc.d,
    correctly set the exit code on error
* debian/nginx-common.nginx.init:
  + Rewrite some parts of the initscript
  + Introduce rotate command
  + Introduce upgrade command

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
        $ENV{LD_PRELOAD} = "mockeagain.so $ENV{LD_PRELOAD}";
10
10
    }
11
11
 
12
 
    $ENV{MOCKEAGAIN} = 'w';
 
12
    if ($ENV{MOCKEAGAIN} eq 'r') {
 
13
        $ENV{MOCKEAGAIN} = 'rw';
 
14
 
 
15
    } else {
 
16
        $ENV{MOCKEAGAIN} = 'w';
 
17
    }
13
18
 
14
19
    $ENV{TEST_NGINX_EVENT_TYPE} = 'poll';
15
20
    $ENV{MOCKEAGAIN_WRITE_TIMEOUT_PATTERN} = 'get helloworld';
16
21
}
17
22
 
18
23
use lib 'lib';
19
 
use Test::Nginx::Socket;
 
24
use Test::Nginx::Socket::Lua;
20
25
use t::StapThread;
21
26
 
22
27
our $GCScript = $t::StapThread::GCScript;
24
29
 
25
30
repeat_each(2);
26
31
 
27
 
plan tests => repeat_each() * (blocks() * 4 + 10);
 
32
plan tests => repeat_each() * (blocks() * 4 + 12);
28
33
 
29
34
our $HtmlDir = html_dir;
30
35
 
127
132
    server_tokens off;
128
133
    lua_socket_connect_timeout 102ms;
129
134
    resolver $TEST_NGINX_RESOLVER;
 
135
    resolver_timeout 3s;
130
136
    location /t {
131
137
        content_by_lua '
132
138
            local sock = ngx.socket.tcp()
647
653
    }
648
654
}
649
655
 
650
 
F(ngx_http_lua_tcp_socket_cleanup) {
 
656
F(ngx_http_lua_coctx_cleanup) {
651
657
    println("lua tcp socket cleanup")
652
658
}
653
659
_EOC_
672
678
--- no_error_log
673
679
[error]
674
680
 
 
681
 
 
682
 
 
683
=== TEST 17: re-connect after timed out
 
684
--- config
 
685
    server_tokens off;
 
686
    lua_socket_connect_timeout 100ms;
 
687
    resolver $TEST_NGINX_RESOLVER;
 
688
    resolver_timeout 1s;
 
689
    location /t {
 
690
        content_by_lua '
 
691
            local sock = ngx.socket.tcp()
 
692
            local ok, err = sock:connect("agentzh.org", 12345)
 
693
            if not ok then
 
694
                ngx.say("1: failed to connect: ", err)
 
695
 
 
696
                local ok, err = sock:connect("127.0.0.1", ngx.var.server_port)
 
697
                if not ok then
 
698
                    ngx.say("2: failed to connect: ", err)
 
699
                    return
 
700
                end
 
701
 
 
702
                ngx.say("2: connected: ", ok)
 
703
                return
 
704
            end
 
705
 
 
706
            ngx.say("1: connected: ", ok)
 
707
        ';
 
708
    }
 
709
--- request
 
710
GET /t
 
711
--- response_body
 
712
1: failed to connect: timeout
 
713
2: connected: 1
 
714
--- error_log
 
715
lua tcp socket connect timeout: 100
 
716
lua tcp socket connect timed out
 
717
 
 
718
 
 
719
 
 
720
=== TEST 18: re-send on the same object after a send timeout happens
 
721
--- config
 
722
    server_tokens off;
 
723
    lua_socket_send_timeout 100ms;
 
724
    resolver $TEST_NGINX_RESOLVER;
 
725
    location /t {
 
726
        content_by_lua '
 
727
            local sock = ngx.socket.tcp()
 
728
            local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
 
729
            if not ok then
 
730
                ngx.say("failed to connect: ", err)
 
731
                return
 
732
            end
 
733
 
 
734
            ngx.say("connected: ", ok)
 
735
 
 
736
            local bytes
 
737
            bytes, err = sock:send("get helloworld!")
 
738
            if bytes then
 
739
                ngx.say("sent: ", bytes)
 
740
            else
 
741
                ngx.say("failed to send: ", err)
 
742
                bytes, err = sock:send("blah")
 
743
                if not bytes then
 
744
                    ngx.say("failed to send again: ", err)
 
745
                end
 
746
            end
 
747
        ';
 
748
    }
 
749
--- request
 
750
GET /t
 
751
--- stap2
 
752
global active = 0
 
753
F(ngx_http_lua_socket_send) {
 
754
    active = 1
 
755
    println(probefunc())
 
756
}
 
757
probe syscall.send,
 
758
    syscall.sendto,
 
759
    syscall.writev
 
760
{
 
761
    if (active && pid() == target()) {
 
762
        println(probefunc())
 
763
    }
 
764
}
 
765
--- response_body
 
766
connected: 1
 
767
failed to send: timeout
 
768
failed to send again: closed
 
769
--- error_log
 
770
lua tcp socket send timeout: 100
 
771
lua tcp socket connect timeout: 60000
 
772
lua tcp socket write timed out
 
773
 
 
774
 
 
775
 
 
776
=== TEST 19: abort when upstream sockets pending on writes
 
777
--- config
 
778
    server_tokens off;
 
779
    resolver $TEST_NGINX_RESOLVER;
 
780
    location /t {
 
781
        content_by_lua '
 
782
            local sock = ngx.socket.tcp()
 
783
            local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
 
784
            if not ok then
 
785
                ngx.say("failed to connect: ", err)
 
786
                return
 
787
            end
 
788
 
 
789
            ngx.say("connected: ", ok)
 
790
 
 
791
            sock:settimeout(100)
 
792
            ngx.thread.spawn(function () ngx.sleep(0.001) ngx.say("done") ngx.exit(200) end)
 
793
            local bytes
 
794
            bytes, err = sock:send("get helloworld!")
 
795
            if bytes then
 
796
                ngx.say("sent: ", bytes)
 
797
            else
 
798
                ngx.say("failed to send: ", err)
 
799
            end
 
800
        ';
 
801
    }
 
802
--- request
 
803
GET /t
 
804
--- stap2
 
805
global active = 0
 
806
F(ngx_http_lua_socket_send) {
 
807
    active = 1
 
808
    println(probefunc())
 
809
}
 
810
probe syscall.send,
 
811
    syscall.sendto,
 
812
    syscall.writev
 
813
{
 
814
    if (active && pid() == target()) {
 
815
        println(probefunc())
 
816
    }
 
817
}
 
818
--- response_body
 
819
connected: 1
 
820
done
 
821
--- error_log
 
822
lua tcp socket send timeout: 100
 
823
lua tcp socket connect timeout: 60000
 
824
--- no_error_log
 
825
lua tcp socket write timed out
 
826
 
 
827
 
 
828
 
 
829
=== TEST 20: abort when downstream socket pending on writes
 
830
--- config
 
831
    server_tokens off;
 
832
    resolver $TEST_NGINX_RESOLVER;
 
833
    location /t {
 
834
        content_by_lua '
 
835
            ngx.send_headers()
 
836
            ngx.flush(true)
 
837
            local sock, err = ngx.req.socket(true)
 
838
            if not sock then
 
839
                ngx.say("failed to acquire the req socket: ", err)
 
840
                return
 
841
            end
 
842
 
 
843
            sock:settimeout(100)
 
844
            ngx.thread.spawn(function ()
 
845
                ngx.sleep(0.001)
 
846
                ngx.log(ngx.WARN, "quitting request now")
 
847
                ngx.exit(200)
 
848
            end)
 
849
            local bytes
 
850
            bytes, err = sock:send("e\\r\\nget helloworld!")
 
851
            if bytes then
 
852
                ngx.say("sent: ", bytes)
 
853
            else
 
854
                ngx.say("failed to send: ", err)
 
855
            end
 
856
        ';
 
857
    }
 
858
--- request
 
859
GET /t
 
860
--- stap2
 
861
global active = 0
 
862
F(ngx_http_lua_socket_send) {
 
863
    active = 1
 
864
    println(probefunc())
 
865
}
 
866
probe syscall.send,
 
867
    syscall.sendto,
 
868
    syscall.writev
 
869
{
 
870
    if (active && pid() == target()) {
 
871
        println(probefunc())
 
872
    }
 
873
}
 
874
--- ignore_response
 
875
--- error_log
 
876
lua tcp socket send timeout: 100
 
877
quitting request now
 
878
--- no_error_log
 
879
lua tcp socket write timed out
 
880
[alert]
 
881