annotate proxy_method.t @ 1427:eb1d883305ea

Tests: avoid edge cases in upstream random two test. Unavailable servers contribute to the number of attempts, if selected, before the balancer would fall back to the default round-robin method. This means that it's quite possible to get server with more connections. To facilitate with selecting two alive servers, down server was removed from the upstream configuration at the cost of slightly worse coverage.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 10 Jan 2019 17:42:34 +0300
parents 766bcbb632ee
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1071
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
1 #!/usr/bin/perl
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
2
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
3 # (C) Dmitry Lazurkin
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
4
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
5 # Tests for proxy_method.
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
6
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
7 ###############################################################################
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
8
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
9 use warnings;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
10 use strict;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
11
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
12 use Test::More;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
13
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
15
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
16 use lib 'lib';
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
17 use Test::Nginx;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
18
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
19 ###############################################################################
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
20
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
21 select STDERR; $| = 1;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
22 select STDOUT; $| = 1;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
23
1075
5513b68493e7 Tests: added rewrite prerequisite in proxy_method.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1071
diff changeset
24 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(4)
1076
4240cca68d1d Tests: whitespace fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1075
diff changeset
25 ->write_file_expand('nginx.conf', <<'EOF');
1071
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
26
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
27 %%TEST_GLOBALS%%
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
28
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
29 daemon off;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
30
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
31 events {
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
32 }
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
33
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
34 http {
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
35 %%TEST_GLOBALS_HTTP%%
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
36
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
37 server {
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
38 listen 127.0.0.1:8080;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
39 server_name localhost;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
40
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
41 location /preserve {
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
42 proxy_pass http://127.0.0.1:8080/get-method;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
43 }
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
44
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
45 location /const {
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
46 proxy_pass http://127.0.0.1:8080/get-method;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
47 proxy_method POST;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
48 }
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
49
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
50 location /var {
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
51 proxy_pass http://127.0.0.1:8080/get-method;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
52 proxy_method $arg_method;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
53 }
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
54
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
55 location /parent {
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
56 proxy_method POST;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
57 location /parent/child {
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
58 proxy_pass http://127.0.0.1:8080/get-method;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
59 }
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
60 }
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
61
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
62 location /get-method {
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
63 return 200 "request_method=$request_method";
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
64 }
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
65 }
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
66 }
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
67
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
68 EOF
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
69
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
70 $t->run();
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
71
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
72 ###############################################################################
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
73
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
74 like(http_get('/preserve'), qr/request_method=GET/,
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
75 'proxy_method from request');
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
76
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
77 like(http_get('/const'), qr/request_method=POST/,
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
78 'proxy_method from constant');
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
79
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
80 like(http_get('/var?method=POST'), qr/request_method=POST/,
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
81 'proxy_method from variable');
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
82
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
83 like(http_get('/parent/child'), qr/request_method=POST/,
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
84 'proxy_method from parent');
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
85
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
86 ###############################################################################