Mercurial > hg > nginx-tests
annotate stream_proxy_half_close.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 2a0a6035a1af |
children |
rev | line source |
---|---|
1735
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for stream proxy_half_close directive. |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 use IO::Select; |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use lib 'lib'; |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 use Test::Nginx; |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 ############################################################################### |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDERR; $| = 1; |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 select STDOUT; $| = 1; |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 my $t = Test::Nginx->new()->has(qw/stream/); |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 $t->write_file_expand('nginx.conf', <<'EOF'); |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 %%TEST_GLOBALS%% |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 daemon off; |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 events { |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 } |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 stream { |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 %%TEST_GLOBALS_STREAM%% |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 server { |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 listen 127.0.0.1:8080; |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 proxy_pass 127.0.0.1:8081; |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 proxy_half_close on; |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 } |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 } |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 EOF |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 |
1937
2a0a6035a1af
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1735
diff
changeset
|
51 $t->run()->plan(2); |
1735
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 ############################################################################### |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 my ($s, $u) = pair(8080, 8081); |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 shutdown($u, 1); |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 is(proxy($s, $u, 'SEE'), 'SEE', 'half close upstream'); |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 ($s, $u) = pair(8080, 8081); |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 shutdown($s, 1); |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 is(proxy($u, $s, 'SEE'), 'SEE', 'half close client'); |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 ############################################################################### |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 sub pair { |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 my ($server, $backend) = @_; |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 my $listen = IO::Socket::INET->new( |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 LocalHost => '127.0.0.1:' . port($backend), |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 Listen => 5, |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 Reuse => 1, |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 ) |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 or die "Can't listen on $server: $!\n"; |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 my $connect = IO::Socket::INET->new( |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 Proto => 'tcp', |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 PeerHost => '127.0.0.1:' . port($server), |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 ) |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 or die "Can't connect to $server: $!\n"; |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 my $accept = $listen->accept() if IO::Select->new($listen)->can_read(3); |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 return $connect, $accept; |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 } |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 sub proxy { |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 my ($from, $to, $msg) = @_; |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 proxy_from($from, $msg); |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 return proxy_to($to); |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 } |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 sub proxy_from { |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 my ($s, $msg) = @_; |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 local $SIG{PIPE} = 'IGNORE'; |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 while (IO::Select->new($s)->can_write(5)) { |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 my $n = $s->syswrite($msg); |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 log_out(substr($msg, 0, $n)); |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 last unless $n; |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 $msg = substr($msg, $n); |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 last unless length $msg; |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 } |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 } |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 sub proxy_to { |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 my ($s) = @_; |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 my $buf; |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 $s->sysread($buf, 1024) if IO::Select->new($s)->can_read(5); |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 log_in($buf); |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 return $buf; |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 } |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 |
8bdf548487f6
Tests: proxy_half_close tests in the stream module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 ############################################################################### |