comparison stream_upstream_hash.t @ 1481:06fbf6269f38

Tests: upstream hash tests for round-robin fallback on empty key.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 28 May 2019 16:25:34 +0300
parents 882267679006
children f3ba4c74de31
comparison
equal deleted inserted replaced
1480:d23d959713b5 1481:06fbf6269f38
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 stream_upstream_hash/)->plan(2); 28 my $t = Test::Nginx->new()->has(qw/stream stream_upstream_hash/)->plan(4);
29 29
30 $t->write_file_expand('nginx.conf', <<'EOF'); 30 $t->write_file_expand('nginx.conf', <<'EOF');
31 31
32 %%TEST_GLOBALS%% 32 %%TEST_GLOBALS%%
33 33
47 hash $remote_addr consistent; 47 hash $remote_addr consistent;
48 server 127.0.0.1:8082; 48 server 127.0.0.1:8082;
49 server 127.0.0.1:8083; 49 server 127.0.0.1:8083;
50 } 50 }
51 51
52 upstream empty {
53 hash $proxy_protocol_addr;
54 server 127.0.0.1:8082;
55 server 127.0.0.1:8083;
56 }
57
58 upstream cempty {
59 hash $proxy_protocol_addr consistent;
60 server 127.0.0.1:8082;
61 server 127.0.0.1:8083;
62 }
63
52 server { 64 server {
53 listen 127.0.0.1:8080; 65 listen 127.0.0.1:8080;
54 proxy_pass hash; 66 proxy_pass hash;
55 } 67 }
56 68
57 server { 69 server {
58 listen 127.0.0.1:8081; 70 listen 127.0.0.1:8081;
59 proxy_pass cons; 71 proxy_pass cons;
72 }
73
74 server {
75 listen 127.0.0.1:8084;
76 proxy_pass empty;
77 }
78
79 server {
80 listen 127.0.0.1:8085;
81 proxy_pass cempty;
60 } 82 }
61 } 83 }
62 84
63 EOF 85 EOF
64 86
73 95
74 my @ports = my ($port2, $port3) = (port(8082), port(8083)); 96 my @ports = my ($port2, $port3) = (port(8082), port(8083));
75 97
76 is(many(10, port(8080)), "$port3: 10", 'hash'); 98 is(many(10, port(8080)), "$port3: 10", 'hash');
77 like(many(10, port(8081)), qr/($port2|$port3): 10/, 'hash consistent'); 99 like(many(10, port(8081)), qr/($port2|$port3): 10/, 'hash consistent');
100
101 # fallback to round-robin
102
103 TODO: {
104 local $TODO = 'not yet' unless $t->has_version('1.17.1');
105
106 like(many(4, port(8084)), qr/$port2: 2, $port3: 2/, 'empty key');
107 like(many(4, port(8085)), qr/$port2: 2, $port3: 2/, 'empty key - consistent');
108
109 }
78 110
79 ############################################################################### 111 ###############################################################################
80 112
81 sub many { 113 sub many {
82 my ($count, $port) = @_; 114 my ($count, $port) = @_;