Mercurial > hg > nginx-tests
annotate map_volatile.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 | b16d30a52753 |
children | 766bcbb632ee |
rev | line source |
---|---|
1095
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for map module with volatile. |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http map/); |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 $t->write_file_expand('nginx.conf', <<'EOF'); |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 events { |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 } |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 http { |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 map $uri $uri_cached { |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 /1/ /1/redirect; |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 /1/redirect uncached; |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 } |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 map $uri $uri_uncached { |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 volatile; |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 /2/ /2/redirect; |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 /2/redirect uncached; |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 } |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 server { |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 listen 127.0.0.1:8080; |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 server_name localhost; |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 location /1 { |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 index $uri_cached; |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 } |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 location /1/redirect { |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 add_header X-URI $uri_cached always; |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 } |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 location /2 { |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 index $uri_uncached; |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 } |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 location /2/redirect { |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 add_header X-URI $uri_uncached always; |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 } |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 } |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 } |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 EOF |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 mkdir($t->testdir() . '/1'); |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 mkdir($t->testdir() . '/2'); |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 $t->try_run('no map volatile')->plan(2); |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 ############################################################################### |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 like(http_get('/1/'), qr!X-URI: /1/redirect!, 'map'); |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 like(http_get('/2/'), qr/X-URI: uncached/, 'map volatile'); |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 |
b16d30a52753
Tests: map module basic tests with volatile.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 ############################################################################### |