Mercurial > hg > nginx-tests
annotate proxy_cache_variables.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 | 196d33c2bb45 |
children |
rev | line source |
---|---|
517
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for http proxy cache, proxy_cache directive with variables. |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
1020
196d33c2bb45
Tests: removed TODO and try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(8) |
517
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 ->write_file_expand('nginx.conf', <<'EOF'); |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 %%TEST_GLOBALS%% |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 daemon off; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 events { |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 } |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 http { |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 proxy_cache_path %%TESTDIR%%/cache1 levels=1:2 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 keys_zone=NAME1:1m; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 proxy_cache_path %%TESTDIR%%/cache2 levels=1:2 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 keys_zone=NAME2:1m; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
44 listen 127.0.0.1:8080; |
517
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 server_name localhost; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 location / { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
48 proxy_pass http://127.0.0.1:8081; |
517
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 proxy_cache $arg_c; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 proxy_cache_valid any 1m; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 add_header X-Cache-Status $upstream_cache_status; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 } |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 } |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
59 listen 127.0.0.1:8081; |
517
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 server_name localhost; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 location / { |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 } |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 } |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 } |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 EOF |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 $t->write_file('index.html', 'SEE-THIS'); |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
568
907e89fba9c3
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
517
diff
changeset
|
71 $t->run(); |
517
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 ############################################################################### |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 like(http_get('/?c=NAME1'), qr/MISS.*SEE-THIS/ms, 'proxy request'); |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 like(http_get('/?c=NAME1'), qr/HIT.*SEE-THIS/ms, 'proxy request cached'); |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 unlike(http_head('/?c=NAME1'), qr/SEE-THIS/, 'head request'); |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 $t->write_file('index.html', 'SEE-THAT'); |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 like(http_get('/?c=NAME2'), qr/MISS.*SEE-THAT/ms, 'proxy request 2'); |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 like(http_get('/?c=NAME2'), qr/HIT.*SEE-THAT/ms, 'proxy request 2 cached'); |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 # some invalid cases |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 like(http_get('/?c=NAME'), qr/ 500 /, 'proxy_cache unknown'); |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 like(http_get('/'), qr/(?<!X-Cache).*SEE-THAT/ms, 'proxy_cache empty'); |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 $t->write_file('index.html', 'SEE-THOSE'); |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 like(http_get('/'), qr/SEE-THOSE/, 'proxy_cache empty - not cached'); |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 ############################################################################### |