Mercurial > hg > nginx-tests
annotate upstream_zone.t @ 1236:93f749c1d5c5
Tests: fixed parallel tests execution with UDP.
Previously, when checking ports availability, a UDP socket was always created
first, then a TCP socket was created. On success, one of UDP and TCP sockets
was closed (depending on the "udp" option) and the second one was used to busy
this port in other scripts. This lead to the following problem: in an attempt
to reopen a UDP socket used in a given testing script it could be stolen by
another script as part of checking ports availability.
To solve this problem, UDP and TCP ports were split into two non-overlapping
ranges: TCP ports are only used in the range 8000-8499, and UDP ports - in
the range 8500-8999. In addition, the order of creating sockets in UDP tests
has been reversed: now a TCP socket used as a lock precedes a UDP socket.
author | Andrey Zelenkov <zelenkov@nginx.com> |
---|---|
date | Thu, 26 Oct 2017 18:00:21 +0300 |
parents | 76640144791b |
children | 97c8280de681 |
rev | line source |
---|---|
1201
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for upstream zone. |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http proxy upstream_zone/)->plan(2) |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 ->write_file_expand('nginx.conf', <<'EOF'); |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 %%TEST_GLOBALS%% |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 daemon off; |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 events { |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 } |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 http { |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 upstream u { |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 zone u 1m; |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 server 127.0.0.1:8081; |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 } |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 upstream u2 { |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 zone u; |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 server 127.0.0.1:8081 down; |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 server 127.0.0.1:8081 backup down; |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 } |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 server { |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 listen 127.0.0.1:8081; |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 server_name localhost; |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 location / {} |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 } |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 server { |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 listen 127.0.0.1:8080; |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 server_name localhost; |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 add_header X-Name $upstream_addr always; |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 location / { |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 proxy_pass http://u/; |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 } |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 location /down { |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 proxy_pass http://u2/; |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 } |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 } |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 } |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 EOF |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 $t->write_file('index.html', ''); |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 $t->run(); |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 ############################################################################### |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 my $p = port(8081); |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 TODO: { |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 todo_skip 'leaves coredump', 2 unless $^O ne 'MSWin32' |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 or $ENV{TEST_NGINX_UNSAFE} or $t->has_version('1.13.4'); |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 like(http_get('/'), qr/X-Name: 127.0.0.1:$p/, 'upstream name'); |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 like(http_get('/down'), qr/X-Name: u2/, 'no live upstreams'); |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 } |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 |
76640144791b
Tests: basic upstream zone tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 ############################################################################### |