Mercurial > hg > nginx-tests
annotate stream_variables.t @ 986:99f93be57416
Tests: various HTTP/2 tests with canceled stream.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 20 Jul 2016 11:07:22 +0300 |
parents | 882267679006 |
children | 4f90c1456ba6 |
rev | line source |
---|---|
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for stream variables. |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx::Stream qw/ stream dgram /; |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/stream stream_return ipv6/); |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 $t->write_file_expand('nginx.conf', <<'EOF'); |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 daemon off; |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 events { |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 } |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 stream { |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
39 listen 127.0.0.1:8080; |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 return $connection:$nginx_version:$hostname:$pid:$bytes_sent; |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 } |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
44 listen 127.0.0.1:8081; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
45 listen [::1]:%%PORT_8081%%; |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 return $remote_addr:$remote_port:$server_addr:$server_port; |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 } |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
50 listen 127.0.0.1:8082; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
51 proxy_pass [::1]:%%PORT_8081%%; |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 } |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
55 listen 127.0.0.1:8083; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
56 listen [::1]:%%PORT_8083%%; |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 return $binary_remote_addr; |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 } |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
61 listen 127.0.0.1:8084; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
62 proxy_pass [::1]:%%PORT_8083%%; |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 } |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
66 listen 127.0.0.1:8085; |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 return $msec!$time_local!$time_iso8601; |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 } |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 } |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 EOF |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 $t->try_run('no stream return')->plan(6); |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 ############################################################################### |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 chomp(my $hostname = lc `hostname`); |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 like(stream()->read(), qr/^\d+:[\d.]+:$hostname:\d+:0$/, 'vars'); |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
80 my $dport = port(8081); |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 my $s = stream("127.0.0.1:$dport"); |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 my $lport = $s->sockport(); |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 is($s->read(), "127.0.0.1:$lport:127.0.0.1:$dport", 'addr'); |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
85 my $data = stream('127.0.0.1:' . port(8082))->read(); |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 like($data, qr/^::1:\d+:::1:\d+$/, 'addr ipv6'); |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
88 $data = stream('127.0.0.1:' . port(8083))->read(); |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 is(unpack("H*", $data), '7f000001', 'binary addr'); |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
91 $data = stream('127.0.0.1:' . port(8084))->read(); |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 is(unpack("H*", $data), '0' x 31 . '1', 'binary addr ipv6'); |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
94 $data = stream('127.0.0.1:' . port(8085))->read(); |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 like($data, qr#^\d+.\d+![-+\w/: ]+![-+\dT:]+$#, 'time'); |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 ############################################################################### |