annotate proxy_set_body.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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
283
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
1 #!/usr/bin/perl
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
2
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
3 # (C) Maxim Dounin
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
4
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
5 # Tests for proxy_set_body.
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
6
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
7 ###############################################################################
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
8
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
9 use warnings;
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
10 use strict;
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
11
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
12 use Test::More;
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
13
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
15
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
16 use lib 'lib';
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
17 use Test::Nginx;
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
18
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
19 ###############################################################################
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
20
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
21 select STDERR; $| = 1;
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
22 select STDOUT; $| = 1;
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
23
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
24 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(2)
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
25 ->write_file_expand('nginx.conf', <<'EOF');
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
26
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
27 %%TEST_GLOBALS%%
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
28
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
29 daemon off;
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
30
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
31 events {
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
32 }
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
33
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
34 http {
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
35 %%TEST_GLOBALS_HTTP%%
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
36
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
37 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
38 listen 127.0.0.1:8080;
283
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
39 server_name localhost;
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
40
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
41 location / {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
42 proxy_pass http://127.0.0.1:8080/body;
283
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
43 proxy_set_body "body";
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
44 }
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
45
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
46 location /p1 {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
47 proxy_pass http://127.0.0.1:8080/x1;
283
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
48 proxy_set_body "body";
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
49 }
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
50
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
51 location /p2 {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
52 proxy_pass http://127.0.0.1:8080/body;
283
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
53 proxy_set_body "body two";
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
54 }
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
55
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
56 location /x1 {
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
57 add_header X-Accel-Redirect /p2;
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
58 return 204;
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
59 }
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
60
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
61 location /body {
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
62 add_header X-Body $request_body;
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
63 proxy_pass http://127.0.0.1:8080/empty;
283
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
64 }
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
65
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
66 location /empty {
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
67 return 204;
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
68 }
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
69 }
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
70 }
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
71
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
72 EOF
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
73
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
74 $t->run();
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
75
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
76 ###############################################################################
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
77
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
78 like(http_get('/'), qr/X-Body: body/, 'proxy_set_body');
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
79 like(http_get('/p1'), qr/X-Body: body two/, 'proxy_set_body twice');
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
80
36d24870ccb2 Tests: proxy_set_body tests added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
81 ###############################################################################