comparison stream_udp_upstream.t @ 1026:e74a9342eb96

Tests: stream tests for per-upstream variables.
author Sergey Kandaurov <pluknet@nginx.com>
date Mon, 05 Sep 2016 22:57:44 +0300
parents 196d33c2bb45
children ba26845f53ff
comparison
equal deleted inserted replaced
1025:94f8cd9b41dc 1026:e74a9342eb96
21 ############################################################################### 21 ###############################################################################
22 22
23 select STDERR; $| = 1; 23 select STDERR; $| = 1;
24 select STDOUT; $| = 1; 24 select STDOUT; $| = 1;
25 25
26 my $t = Test::Nginx->new()->has(qw/stream udp/)->plan(4) 26 my $t = Test::Nginx->new()->has(qw/stream udp/)
27 ->write_file_expand('nginx.conf', <<'EOF'); 27 ->write_file_expand('nginx.conf', <<'EOF');
28 28
29 %%TEST_GLOBALS%% 29 %%TEST_GLOBALS%%
30 30
31 daemon off; 31 daemon off;
34 } 34 }
35 35
36 stream { 36 stream {
37 proxy_responses 1; 37 proxy_responses 1;
38 proxy_timeout 1s; 38 proxy_timeout 1s;
39
40 log_format bytes $upstream_addr!
41 $upstream_bytes_sent!$upstream_bytes_received;
39 42
40 upstream u { 43 upstream u {
41 server 127.0.0.1:%%PORT_8084_UDP%%; 44 server 127.0.0.1:%%PORT_8084_UDP%%;
42 server 127.0.0.1:%%PORT_8085_UDP%%; 45 server 127.0.0.1:%%PORT_8085_UDP%%;
43 } 46 }
75 } 78 }
76 79
77 server { 80 server {
78 listen 127.0.0.1:%%PORT_8083_UDP%% udp; 81 listen 127.0.0.1:%%PORT_8083_UDP%% udp;
79 proxy_pass u4; 82 proxy_pass u4;
83 access_log %%TESTDIR%%/u.log bytes;
80 } 84 }
81 } 85 }
82 86
83 EOF 87 EOF
84 88
85 $t->run_daemon(\&udp_daemon, port(8084), $t); 89 $t->run_daemon(\&udp_daemon, port(8084), $t);
86 $t->run_daemon(\&udp_daemon, port(8085), $t); 90 $t->run_daemon(\&udp_daemon, port(8085), $t);
87 $t->run(); 91 $t->try_run('no stream access_log')->plan(5);
88 92
89 $t->waitforfile($t->testdir . '/' . port(8084)); 93 $t->waitforfile($t->testdir . '/' . port(8084));
90 $t->waitforfile($t->testdir . '/' . port(8085)); 94 $t->waitforfile($t->testdir . '/' . port(8085));
91 95
92 ############################################################################### 96 ###############################################################################
93 97
94 my @ports = my ($port4, $port5) = (port(8084), port(8085)); 98 my @ports = my ($port4, $port5, $port6) = (port(8084), port(8085), port(8086));
95 99
96 is(many(30, port(8080)), "$port4: 15, $port5: 15", 'balanced'); 100 is(many(30, port(8080)), "$port4: 15, $port5: 15", 'balanced');
97 is(many(30, port(8081)), "$port4: 15, $port5: 15", 'failures'); 101 is(many(30, port(8081)), "$port4: 15, $port5: 15", 'failures');
98 is(many(30, port(8082)), "$port4: 10, $port5: 20", 'weight'); 102 is(many(30, port(8082)), "$port4: 10, $port5: 20", 'weight');
99 is(many(30, port(8083)), "$port4: 30", 'backup'); 103 is(many(30, port(8083)), "$port4: 30", 'backup');
104
105 $t->stop();
106
107 like($t->read_file('u.log'), qr/127.0.0.1:$port6, 127.0.0.1:$port4!1, 1!0, 4/,
108 'per-upstream variables');
100 109
101 ############################################################################### 110 ###############################################################################
102 111
103 sub many { 112 sub many {
104 my ($count, $port) = @_; 113 my ($count, $port) = @_;