Mercurial > hg > nginx-tests
annotate stream_proxy_bind.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 | 882267679006 |
children | f3ba4c74de31 |
rev | line source |
---|---|
622
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
2 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
3 # (C) Andrey Zelenkov |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
5 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
6 # Test for stream proxy_bind directive. |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
7 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
9 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
11 use strict; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
12 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
14 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
16 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
19 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
21 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
24 |
626
5f9dfe85a1f2
Tests: skipped proxy_bind tests on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents:
622
diff
changeset
|
25 plan(skip_all => 'win32') if $^O eq 'MSWin32'; |
622
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
26 plan(skip_all => '127.0.0.2 local address required') |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
27 unless defined IO::Socket::INET->new( LocalAddr => '127.0.0.2' ); |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
28 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
29 my $t = Test::Nginx->new()->has(qw/http proxy stream/)->plan(1) |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
30 ->write_file_expand('nginx.conf', <<'EOF'); |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
31 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
32 %%TEST_GLOBALS%% |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
33 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
34 daemon off; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
35 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
36 events { |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
37 } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
38 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
39 stream { |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
40 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
41 listen 127.0.0.1:8081; |
622
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
42 proxy_bind 127.0.0.2; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
43 proxy_pass 127.0.0.1:8082; |
622
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
44 } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
45 } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
46 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
47 http { |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
48 %%TEST_GLOBALS_HTTP%% |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
49 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
50 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
51 listen 127.0.0.1:8080; |
622
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
52 server_name localhost; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
53 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
54 location / { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
55 proxy_pass http://127.0.0.1:8081; |
622
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
56 } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
57 } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
58 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
59 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
60 listen 127.0.0.1:8082; |
622
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
61 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
62 location / { |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
63 add_header X-IP $remote_addr; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
64 } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
65 } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
66 } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
67 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
68 EOF |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
69 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
70 $t->write_file('index.html', ''); |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
71 $t->run(); |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
72 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
73 ############################################################################### |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
74 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
75 like(http_get('/'), qr/X-IP: 127.0.0.2/, 'bind'); |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
76 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
77 ############################################################################### |