comparison stream_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 882267679006
children a073a545413d
comparison
equal deleted inserted replaced
1025:94f8cd9b41dc 1026:e74a9342eb96
23 ############################################################################### 23 ###############################################################################
24 24
25 select STDERR; $| = 1; 25 select STDERR; $| = 1;
26 select STDOUT; $| = 1; 26 select STDOUT; $| = 1;
27 27
28 my $t = Test::Nginx->new()->has(qw/stream/)->plan(4) 28 my $t = Test::Nginx->new()->has(qw/stream/)
29 ->write_file_expand('nginx.conf', <<'EOF'); 29 ->write_file_expand('nginx.conf', <<'EOF');
30 30
31 %%TEST_GLOBALS%% 31 %%TEST_GLOBALS%%
32 32
33 daemon off; 33 daemon off;
34 34
35 events { 35 events {
36 } 36 }
37 37
38 stream { 38 stream {
39 log_format bytes $upstream_addr!
40 $upstream_bytes_sent!$upstream_bytes_received;
41
39 upstream u { 42 upstream u {
40 server 127.0.0.1:8084; 43 server 127.0.0.1:8084;
41 server 127.0.0.1:8085; 44 server 127.0.0.1:8085;
42 } 45 }
43 46
76 } 79 }
77 80
78 server { 81 server {
79 listen 127.0.0.1:8083; 82 listen 127.0.0.1:8083;
80 proxy_pass u4; 83 proxy_pass u4;
84 access_log %%TESTDIR%%/u.log bytes;
81 } 85 }
82 } 86 }
83 87
84 EOF 88 EOF
85 89
86 $t->run_daemon(\&stream_daemon, port(8084)); 90 $t->run_daemon(\&stream_daemon, port(8084));
87 $t->run_daemon(\&stream_daemon, port(8085)); 91 $t->run_daemon(\&stream_daemon, port(8085));
88 $t->run(); 92 $t->try_run('no stream access_log')->plan(5);
89 93
90 $t->waitforsocket('127.0.0.1:' . port(8084)); 94 $t->waitforsocket('127.0.0.1:' . port(8084));
91 $t->waitforsocket('127.0.0.1:' . port(8085)); 95 $t->waitforsocket('127.0.0.1:' . port(8085));
92 96
93 ############################################################################### 97 ###############################################################################
94 98
95 my @ports = my ($port4, $port5) = (port(8084), port(8085)); 99 my @ports = my ($port4, $port5, $port6) = (port(8084), port(8085), port(8086));
96 100
97 is(many(30, port(8080)), "$port4: 15, $port5: 15", 'balanced'); 101 is(many(30, port(8080)), "$port4: 15, $port5: 15", 'balanced');
98 is(many(30, port(8081)), "$port4: 15, $port5: 15", 'failures'); 102 is(many(30, port(8081)), "$port4: 15, $port5: 15", 'failures');
99 is(many(30, port(8082)), "$port4: 10, $port5: 20", 'weight'); 103 is(many(30, port(8082)), "$port4: 10, $port5: 20", 'weight');
100 is(many(30, port(8083)), "$port4: 30", 'backup'); 104 is(many(30, port(8083)), "$port4: 30", 'backup');
105
106 $t->stop();
107
108 like($t->read_file('u.log'), qr/127.0.0.1:$port6, 127.0.0.1:$port4!0, 1!0, 4/,
109 'per-upstream variables');
101 110
102 ############################################################################### 111 ###############################################################################
103 112
104 sub many { 113 sub many {
105 my ($count, $port) = @_; 114 my ($count, $port) = @_;