Mercurial > hg > nginx-tests
annotate stream_upstream_zone.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 |
---|---|
1203
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Stream tests for upstream zone. |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx::Stream qw/ stream /; |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/stream stream_return stream_upstream_zone/) |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 ->plan(2)->write_file_expand('nginx.conf', <<'EOF'); |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 events { |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 } |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
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:
1454
diff
changeset
|
37 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1454
diff
changeset
|
38 |
1203
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 log_format test $upstream_addr; |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 upstream u { |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 zone u 1m; |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 server 127.0.0.1:8081; |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 } |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 upstream u2 { |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 zone u; |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 server 127.0.0.1:8081 down; |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 server 127.0.0.1:8081 backup down; |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 } |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 server { |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 listen 127.0.0.1:8081; |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 return OK; |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 } |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 server { |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 listen 127.0.0.1:8091; |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 proxy_pass u; |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 access_log %%TESTDIR%%/access1.log test; |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 } |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 server { |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 listen 127.0.0.1:8092; |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 proxy_pass u2; |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 access_log %%TESTDIR%%/access2.log test; |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 } |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 } |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 EOF |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 $t->write_file('index.html', ''); |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 $t->run(); |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 ############################################################################### |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 my $p = port(8081); |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
1454
3008cc57b5c9
Tests: shutdown in stream_upstream_zone.t with closed connections.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1381
diff
changeset
|
81 stream('127.0.0.1:' . port(8091))->read(); |
3008cc57b5c9
Tests: shutdown in stream_upstream_zone.t with closed connections.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1381
diff
changeset
|
82 stream("127.0.0.1:" . port(8092))->read(); |
1203
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 $t->stop(); |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 is($t->read_file('access1.log'), "127.0.0.1:$p\n", 'upstream name'); |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 is($t->read_file('access2.log'), "u2\n", 'no live upstreams'); |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 |
6f17d67abeb8
Tests: basic stream upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 ############################################################################### |