Mercurial > hg > nginx-tests
comparison upstream.t @ 952:e9064d691790
Tests: converted tests to run in parallel.
author | Andrey Zelenkov <zelenkov@nginx.com> |
---|---|
date | Tue, 21 Jun 2016 16:39:13 +0300 |
parents | e7dc8f4d0a4b |
children | 882267679006 |
comparison
equal
deleted
inserted
replaced
951:9361c7eddfc1 | 952:e9064d691790 |
---|---|
34 | 34 |
35 http { | 35 http { |
36 %%TEST_GLOBALS_HTTP%% | 36 %%TEST_GLOBALS_HTTP%% |
37 | 37 |
38 upstream u { | 38 upstream u { |
39 server 127.0.0.1:8081 max_fails=3 fail_timeout=10s; | 39 server 127.0.0.1:%%PORT_1%% max_fails=3 fail_timeout=10s; |
40 server 127.0.0.1:8082 max_fails=3 fail_timeout=10s; | 40 server 127.0.0.1:%%PORT_2%% max_fails=3 fail_timeout=10s; |
41 } | 41 } |
42 | 42 |
43 upstream u2 { | 43 upstream u2 { |
44 server 127.0.0.1:8081 max_fails=3 fail_timeout=10s; | 44 server 127.0.0.1:%%PORT_1%% max_fails=3 fail_timeout=10s; |
45 server 127.0.0.1:8082 max_fails=3 fail_timeout=10s; | 45 server 127.0.0.1:%%PORT_2%% max_fails=3 fail_timeout=10s; |
46 } | 46 } |
47 | 47 |
48 server { | 48 server { |
49 listen 127.0.0.1:8080; | 49 listen 127.0.0.1:%%PORT_0%%; |
50 server_name localhost; | 50 server_name localhost; |
51 | 51 |
52 location / { | 52 location / { |
53 proxy_pass http://u; | 53 proxy_pass http://u; |
54 } | 54 } |
58 } | 58 } |
59 } | 59 } |
60 | 60 |
61 EOF | 61 EOF |
62 | 62 |
63 $t->run_daemon(\&http_daemon, 8081); | 63 $t->run_daemon(\&http_daemon, port(1)); |
64 $t->run_daemon(\&http_daemon, 8082); | 64 $t->run_daemon(\&http_daemon, port(2)); |
65 $t->run(); | 65 $t->run(); |
66 | 66 |
67 $t->waitforsocket('127.0.0.1:8081'); | 67 $t->waitforsocket('127.0.0.1:' . port(1)); |
68 $t->waitforsocket('127.0.0.1:8082'); | 68 $t->waitforsocket('127.0.0.1:' . port(2)); |
69 | 69 |
70 ############################################################################### | 70 ############################################################################### |
71 | 71 |
72 is(many('/', 30), '8081: 15, 8082: 15', 'balanced'); | 72 my @ports = my ($p1, $p2) = (port(1), port(2)); |
73 | 73 |
74 # from 9 first requests to 8081, only 6 will be successful, | 74 is(many('/', 30), "$p1: 15, $p2: 15", 'balanced'); |
75 | |
76 # from 9 first requests to the first port, only 6 will be successful, | |
75 # 3rd, 6th, and 9th requests will fail; after this the backend | 77 # 3rd, 6th, and 9th requests will fail; after this the backend |
76 # will be considered down and won't be used till fail_timeout passes | 78 # will be considered down and won't be used till fail_timeout passes |
77 | 79 |
78 is(many('/close', 30), '8081: 6, 8082: 24', 'failures'); | 80 is(many('/close', 30), "$p1: 6, $p2: 24", 'failures'); |
79 | 81 |
80 SKIP: { | 82 SKIP: { |
81 skip 'long test', 1 unless $ENV{TEST_NGINX_UNSAFE}; | 83 skip 'long test', 1 unless $ENV{TEST_NGINX_UNSAFE}; |
82 | 84 |
83 # bug: failures counter is reset if first request in a second succeeds | 85 # bug: failures counter is reset if first request in a second succeeds |
84 # | 86 # |
85 # delay added to make sure first 9 requests will take more than 1s; | 87 # delay added to make sure first 9 requests will take more than 1s; |
86 # note that the test is racy and may unexpectedly succeed | 88 # note that the test is racy and may unexpectedly succeed |
87 | 89 |
88 is(many('/close2', 30, delay => 0.2), '8081: 6, 8082: 24', 'failures delay'); | 90 is(many('/close2', 30, delay => 0.2), "$p1: 6, $p2: 24", 'failures delay'); |
89 | 91 |
90 } | 92 } |
91 | 93 |
92 ############################################################################### | 94 ############################################################################### |
93 | 95 |
102 } | 104 } |
103 | 105 |
104 select undef, undef, undef, $opts{delay} if $opts{delay}; | 106 select undef, undef, undef, $opts{delay} if $opts{delay}; |
105 } | 107 } |
106 | 108 |
107 return join ', ', map { $_ . ": " . $ports{$_} } sort keys %ports; | 109 my @keys = map { my $p = $_; grep { $p == $_ } keys %ports } @ports; |
110 return join ', ', map { $_ . ": " . $ports{$_} } @keys; | |
108 } | 111 } |
109 | 112 |
110 ############################################################################### | 113 ############################################################################### |
111 | 114 |
112 sub http_daemon { | 115 sub http_daemon { |
135 last if (/^\x0d?\x0a?$/); | 138 last if (/^\x0d?\x0a?$/); |
136 } | 139 } |
137 | 140 |
138 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i; | 141 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i; |
139 | 142 |
140 if ($uri =~ 'close' && $port == 8081 && $count++ % 3 == 0) { | 143 if ($uri =~ 'close' && $port == port(1) && $count++ % 3 == 0) { |
141 next; | 144 next; |
142 } | 145 } |
143 | 146 |
144 print $client <<EOF; | 147 print $client <<EOF; |
145 HTTP/1.1 200 OK | 148 HTTP/1.1 200 OK |