Mercurial > hg > nginx-tests
comparison grpc_next_upstream.t @ 1311:4979af9fd905
Tests: grpc request buffering and next upstream tests.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 29 Mar 2018 18:35:02 +0300 |
parents | proxy_next_upstream.t@882267679006 |
children | 97c8280de681 |
comparison
equal
deleted
inserted
replaced
1310:3882f8f3b2bc | 1311:4979af9fd905 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Maxim Dounin | |
4 # (C) Sergey Kandaurov | |
5 # (C) Nginx, Inc. | |
6 | |
7 # Tests for grpc module, grpc_next_upstream directive. | |
8 | |
9 ############################################################################### | |
10 | |
11 use warnings; | |
12 use strict; | |
13 | |
14 use Test::More; | |
15 | |
16 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
17 | |
18 use lib 'lib'; | |
19 use Test::Nginx; | |
20 | |
21 ############################################################################### | |
22 | |
23 select STDERR; $| = 1; | |
24 select STDOUT; $| = 1; | |
25 | |
26 my $t = Test::Nginx->new()->has(qw/http http_v2 grpc rewrite/); | |
27 | |
28 $t->write_file_expand('nginx.conf', <<'EOF'); | |
29 | |
30 %%TEST_GLOBALS%% | |
31 | |
32 daemon off; | |
33 | |
34 events { | |
35 } | |
36 | |
37 http { | |
38 %%TEST_GLOBALS_HTTP%% | |
39 | |
40 upstream u { | |
41 server 127.0.0.1:8081 max_fails=2; | |
42 server 127.0.0.1:8082; | |
43 } | |
44 | |
45 upstream u2 { | |
46 server 127.0.0.1:8081; | |
47 server 127.0.0.1:8082; | |
48 } | |
49 | |
50 server { | |
51 listen 127.0.0.1:8080; | |
52 server_name localhost; | |
53 | |
54 location / { | |
55 grpc_pass u; | |
56 grpc_next_upstream http_500 http_404 invalid_header; | |
57 } | |
58 | |
59 location /all/ { | |
60 grpc_pass u2; | |
61 grpc_next_upstream http_500 http_404; | |
62 error_page 404 /all/404; | |
63 grpc_intercept_errors on; | |
64 } | |
65 | |
66 location /all/404 { | |
67 return 200 "$upstream_addr\n"; | |
68 } | |
69 } | |
70 | |
71 server { | |
72 listen 127.0.0.1:8081 http2; | |
73 server_name localhost; | |
74 | |
75 location / { | |
76 return 404; | |
77 } | |
78 location /ok { | |
79 return 200 "AND-THIS\n"; | |
80 } | |
81 location /500 { | |
82 return 500; | |
83 } | |
84 location /444 { | |
85 return 444; | |
86 } | |
87 | |
88 location /all/ { | |
89 return 404; | |
90 } | |
91 } | |
92 | |
93 server { | |
94 listen 127.0.0.1:8082 http2; | |
95 server_name localhost; | |
96 | |
97 location / { | |
98 return 200 "TEST-OK-IF-YOU-SEE-THIS\n"; | |
99 } | |
100 | |
101 location /all/ { | |
102 return 404; | |
103 } | |
104 } | |
105 } | |
106 | |
107 EOF | |
108 | |
109 $t->try_run('no grpc')->plan(9); | |
110 | |
111 ############################################################################### | |
112 | |
113 my ($p1, $p2) = (port(8081), port(8082)); | |
114 | |
115 # check if both request fallback to a backend | |
116 # which returns valid response | |
117 | |
118 like(http_get('/'), qr/SEE-THIS/, 'grpc request'); | |
119 like(http_get('/'), qr/SEE-THIS/, 'second request'); | |
120 | |
121 # make sure backend isn't switched off after | |
122 # grpc_next_upstream http_404 | |
123 | |
124 like(http_get('/ok') . http_get('/ok'), qr/AND-THIS/, 'not down'); | |
125 | |
126 # next upstream on invalid_header | |
127 | |
128 like(http_get('/444'), qr/SEE-THIS/, 'request 444'); | |
129 like(http_get('/444'), qr/SEE-THIS/, 'request 444 second'); | |
130 | |
131 # next upstream on http_500 | |
132 | |
133 like(http_get('/500'), qr/SEE-THIS/, 'request 500'); | |
134 like(http_get('/500'), qr/SEE-THIS/, 'request 500 second'); | |
135 | |
136 # make sure backend switched off with http_500 | |
137 | |
138 unlike(http_get('/ok') . http_get('/ok'), qr/AND-THIS/, 'down after 500'); | |
139 | |
140 # make sure all backends are tried once | |
141 | |
142 like(http_get('/all/rr'), | |
143 qr/^127.0.0.1:($p1, 127.0.0.1:$p2|$p2, 127.0.0.1:$p1)$/mi, | |
144 'all tried once'); | |
145 | |
146 ############################################################################### |