Mercurial > hg > nginx-tests
annotate stream_udp_proxy_requests.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | f3ba4c74de31 |
children |
rev | line source |
---|---|
1396
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for stream proxy module, the proxy_requests directive. |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx::Stream qw/ dgram /; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 |
1535
144c6ce732e4
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1398
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/stream udp/)->plan(26) |
1396
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 ->write_file_expand('nginx.conf', <<'EOF'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 events { |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 } |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 stream { |
1609
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1535
diff
changeset
|
37 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1535
diff
changeset
|
38 |
1396
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 proxy_timeout 2100ms; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 log_format status $status; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 server { |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 listen 127.0.0.1:%%PORT_8980_UDP%% udp; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 proxy_pass 127.0.0.1:%%PORT_8990_UDP%%; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 proxy_requests 0; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 } |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 server { |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 listen 127.0.0.1:%%PORT_8981_UDP%% udp; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 proxy_pass 127.0.0.1:%%PORT_8990_UDP%%; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 proxy_requests 1; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 } |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 server { |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 listen 127.0.0.1:%%PORT_8982_UDP%% udp; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 proxy_pass 127.0.0.1:%%PORT_8990_UDP%%; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 proxy_requests 2; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 } |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 server { |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 listen 127.0.0.1:%%PORT_8983_UDP%% udp; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 proxy_pass 127.0.0.1:%%PORT_8990_UDP%%; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 } |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 server { |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 listen 127.0.0.1:%%PORT_8984_UDP%% udp; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 proxy_pass 127.0.0.1:%%PORT_8991_UDP%%; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 proxy_requests 2; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 access_log %%TESTDIR%%/s.log status; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 } |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 server { |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 listen 127.0.0.1:%%PORT_8985_UDP%% udp; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 proxy_pass 127.0.0.1:%%PORT_8990_UDP%%; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 proxy_requests 2; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 proxy_responses 2; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 access_log %%TESTDIR%%/s2.log status; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 } |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 } |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 EOF |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 $t->run_daemon(\&udp_daemon, $t, port(8990)); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 $t->run_daemon(\&udp_daemon, $t, port(8991)); |
1535
144c6ce732e4
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1398
diff
changeset
|
92 $t->run(); |
1396
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 $t->waitforfile($t->testdir . '/' . port(8990)); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 $t->waitforfile($t->testdir . '/' . port(8991)); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 ############################################################################### |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 # proxy_requests 0, binding is not dropped across streams |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 my $s = dgram('127.0.0.1:' . port(8980)); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 my $n = $s->io('1', read => 1); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 ok($n, 'requests 0 create'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 is($s->read(), '1', 'requests 0 create - response'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 is($s->io('1', read => 1), $n, 'requests 0 second - binding saved'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 is($s->read(), '1', 'requests 0 second - response'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 is($s->io('1', read => 1), $n, 'requests 0 follow - binding saved'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 is($s->read(), '1', 'requests 0 follow - response'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 # proxy_requests 1, binding is dropped on every next stream |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 $s = dgram('127.0.0.1:' . port(8981)); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 $n = $s->io('1', read => 1); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 ok($n, 'requests 1 create'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 is($s->read(), '1', 'requests 1 create - response'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 isnt($s->io('1', read => 1), $n, 'requests 1 second - binding lost'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 is($s->read(), '1', 'requests 1 second - response'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 # proxy_requests 2, binding is dropped on every second stream |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 $s = dgram('127.0.0.1:' . port(8982)); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 $n = $s->io('1', read => 1); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 ok($n, 'requests 2 create'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 is($s->read(), '1', 'requests 2 create - response'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 is($s->io('1', read => 1), $n, 'requests 2 second - binding saved'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 is($s->read(), '1', 'requests 2 second - response'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 isnt($s->io('1', read => 1), $n, 'requests 2 follow - binding lost'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 is($s->read(), '1', 'requests 2 follow - response'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 # proxy_requests unset, binding is not dropped across streams |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 $s = dgram('127.0.0.1:' . port(8983)); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 $n = $s->io('1', read => 1); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 ok($n, 'requests unset create'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 is($s->read(), '1', 'requests unset create - response'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 is($s->io('1', read => 1), $n, 'requests unset second - binding saved'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 is($s->read(), '1', 'requests unset second - response'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 is($s->io('1', read => 1), $n, 'requests unset follow - binding saved'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 is($s->read(), '1', 'requests unset follow - response'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 # proxy_requests 2, with slow backend |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 # client sends 5 packets, each responded with 3 packets |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 # expects all packets proxied from backend, the last (uneven) session succeed |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 $s = dgram('127.0.0.1:' . port(8984)); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
153 $s->write('2') for 1 .. 5; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 my $b = join ' ', map { $s->read() } (1 .. 15); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
155 like($b, qr/^(\d+ 1 2) \1 (?!\1)(\d+ 1 2) \2 (?!\2)\d+ 1 2$/, 'slow backend'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 # proxy_requests 2, proxy_responses 2 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 # client sends 5 packets, each responded with 2 packets |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 # expects all packets proxied from backend, the last (uneven) session succeed |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 $s = dgram('127.0.0.1:' . port(8985)); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 $s->write('1') for 1 .. 5; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 $b = join ' ', map { $s->read() } (1 .. 10); |
1398
9242811bf22b
Tests: marked "requests - responses" proxy_requests test as unsafe.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1396
diff
changeset
|
164 |
9242811bf22b
Tests: marked "requests - responses" proxy_requests test as unsafe.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1396
diff
changeset
|
165 SKIP: { |
9242811bf22b
Tests: marked "requests - responses" proxy_requests test as unsafe.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1396
diff
changeset
|
166 skip 'session could early terminate', 1 unless $ENV{TEST_NGINX_UNSAFE}; |
9242811bf22b
Tests: marked "requests - responses" proxy_requests test as unsafe.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1396
diff
changeset
|
167 |
1396
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 like($b, qr/^(\d+ 1) \1 (?!\1)(\d+ 1) \2 (?!\2)\d+ 1$/, 'requests - responses'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
169 |
1398
9242811bf22b
Tests: marked "requests - responses" proxy_requests test as unsafe.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1396
diff
changeset
|
170 } |
9242811bf22b
Tests: marked "requests - responses" proxy_requests test as unsafe.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1396
diff
changeset
|
171 |
1396
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 $t->stop(); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
174 is($t->read_file('s.log'), <<EOF, 'uneven session status - slow backend'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
175 200 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
176 200 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
177 200 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
178 EOF |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
179 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
180 is($t->read_file('s2.log'), <<EOF, 'uneven session status - responses'); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
181 200 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
182 200 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
183 200 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
184 EOF |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
185 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
186 ############################################################################### |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
187 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
188 sub udp_daemon { |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
189 my ($t, $port) = @_; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
190 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
191 my $server = IO::Socket::INET->new( |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
192 Proto => 'udp', |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
193 LocalAddr => "127.0.0.1:$port", |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
194 Reuse => 1 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
195 ) |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
196 or die "Can't create listening socket: $!\n"; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
197 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
198 # signal we are ready |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
199 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
200 open my $fh, '>', $t->testdir() . "/$port"; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
201 close $fh; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
202 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
203 my $slp = 1 if $port == port(8991); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
204 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
205 while (1) { |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
206 $server->recv(my $buffer, 65536); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
207 sleep 1, $slp = 0 if $slp; |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
208 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
209 $server->send($server->peerport()); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
210 $server->send($_) for (1 .. $buffer); |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
211 } |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
212 } |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
213 |
28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
214 ############################################################################### |