comparison upstream_zone.t @ 1201:76640144791b

Tests: basic upstream zone tests.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 02 Aug 2017 16:13:08 +0300
parents
children 97c8280de681
comparison
equal deleted inserted replaced
1200:630c3e7a5d40 1201:76640144791b
1 #!/usr/bin/perl
2
3 # (C) Sergey Kandaurov
4 # (C) Nginx, Inc.
5
6 # Tests for upstream zone.
7
8 ###############################################################################
9
10 use warnings;
11 use strict;
12
13 use Test::More;
14
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
16
17 use lib 'lib';
18 use Test::Nginx;
19
20 ###############################################################################
21
22 select STDERR; $| = 1;
23 select STDOUT; $| = 1;
24
25 my $t = Test::Nginx->new()->has(qw/http proxy upstream_zone/)->plan(2)
26 ->write_file_expand('nginx.conf', <<'EOF');
27
28 %%TEST_GLOBALS%%
29
30 daemon off;
31
32 events {
33 }
34
35 http {
36 %%TEST_GLOBALS_HTTP%%
37
38 upstream u {
39 zone u 1m;
40 server 127.0.0.1:8081;
41 }
42
43 upstream u2 {
44 zone u;
45 server 127.0.0.1:8081 down;
46 server 127.0.0.1:8081 backup down;
47 }
48
49 server {
50 listen 127.0.0.1:8081;
51 server_name localhost;
52
53 location / {}
54 }
55
56 server {
57 listen 127.0.0.1:8080;
58 server_name localhost;
59
60 add_header X-Name $upstream_addr always;
61
62 location / {
63 proxy_pass http://u/;
64 }
65
66 location /down {
67 proxy_pass http://u2/;
68 }
69 }
70 }
71
72 EOF
73
74 $t->write_file('index.html', '');
75 $t->run();
76
77 ###############################################################################
78
79 my $p = port(8081);
80
81 TODO: {
82 todo_skip 'leaves coredump', 2 unless $^O ne 'MSWin32'
83 or $ENV{TEST_NGINX_UNSAFE} or $t->has_version('1.13.4');
84
85 like(http_get('/'), qr/X-Name: 127.0.0.1:$p/, 'upstream name');
86 like(http_get('/down'), qr/X-Name: u2/, 'no live upstreams');
87
88 }
89
90 ###############################################################################