comparison http_resolver.t @ 974:882267679006

Tests: simplified parallel modifications in tests. Mail tests were simplified in c227348453db.
author Andrey Zelenkov <zelenkov@nginx.com>
date Tue, 12 Jul 2016 17:39:03 +0300
parents 0a87d9bcfb26
children 196d33c2bb45
comparison
equal deleted inserted replaced
973:7d7aef8b9f3a 974:882267679006
37 37
38 http { 38 http {
39 %%TEST_GLOBALS_HTTP%% 39 %%TEST_GLOBALS_HTTP%%
40 40
41 server { 41 server {
42 listen 127.0.0.1:%%PORT_0%%; 42 listen 127.0.0.1:8080;
43 server_name localhost; 43 server_name localhost;
44 44
45 location / { 45 location / {
46 resolver 127.0.0.1:%%PORT_1_UDP%%; 46 resolver 127.0.0.1:%%PORT_8081_UDP%%;
47 resolver_timeout 1s; 47 resolver_timeout 1s;
48 proxy_pass http://$host:%%PORT_0%%/backend; 48 proxy_pass http://$host:%%PORT_8080%%/backend;
49 49
50 proxy_next_upstream http_504 timeout error; 50 proxy_next_upstream http_504 timeout error;
51 proxy_intercept_errors on; 51 proxy_intercept_errors on;
52 proxy_connect_timeout 1s; 52 proxy_connect_timeout 1s;
53 error_page 504 502 /50x; 53 error_page 504 502 /50x;
54 } 54 }
55 location /two { 55 location /two {
56 resolver 127.0.0.1:%%PORT_1_UDP%% 127.0.0.1:%%PORT_2_UDP%%; 56 resolver 127.0.0.1:%%PORT_8081_UDP%% 127.0.0.1:%%PORT_8082_UDP%%;
57 proxy_pass http://$host:%%PORT_0%%/backend; 57 proxy_pass http://$host:%%PORT_8080%%/backend;
58 } 58 }
59 location /valid { 59 location /valid {
60 resolver 127.0.0.1:%%PORT_1_UDP%% valid=5s; 60 resolver 127.0.0.1:%%PORT_8081_UDP%% valid=5s;
61 proxy_pass http://$host:%%PORT_0%%/backend; 61 proxy_pass http://$host:%%PORT_8080%%/backend;
62 } 62 }
63 location /case { 63 location /case {
64 resolver 127.0.0.1:%%PORT_1_UDP%%; 64 resolver 127.0.0.1:%%PORT_8081_UDP%%;
65 proxy_pass http://$http_x_name:%%PORT_0%%/backend; 65 proxy_pass http://$http_x_name:%%PORT_8080%%/backend;
66 } 66 }
67 location /invalid { 67 location /invalid {
68 proxy_pass http://$host:%%PORT_0%%/backend; 68 proxy_pass http://$host:%%PORT_8080%%/backend;
69 } 69 }
70 location /long { 70 location /long {
71 resolver 127.0.0.1:%%PORT_1_UDP%%; 71 resolver 127.0.0.1:%%PORT_8081_UDP%%;
72 resolver_timeout 4s; 72 resolver_timeout 4s;
73 proxy_pass http://$host:%%PORT_0%%/backend; 73 proxy_pass http://$host:%%PORT_8080%%/backend;
74 } 74 }
75 location /resend { 75 location /resend {
76 resolver 127.0.0.1:%%PORT_1_UDP%%; 76 resolver 127.0.0.1:%%PORT_8081_UDP%%;
77 resolver_timeout 8s; 77 resolver_timeout 8s;
78 proxy_pass http://$host:%%PORT_0%%/backend; 78 proxy_pass http://$host:%%PORT_8080%%/backend;
79 } 79 }
80 location /bad { 80 location /bad {
81 resolver 127.0.0.1:%%PORT_4_UDP%%; 81 resolver 127.0.0.1:%%PORT_8084_UDP%%;
82 resolver_timeout 1s; 82 resolver_timeout 1s;
83 proxy_pass http://$host:%%PORT_0%%/backend; 83 proxy_pass http://$host:%%PORT_8080%%/backend;
84 } 84 }
85 location /tcp { 85 location /tcp {
86 resolver 127.0.0.1:%%PORT_3_UDP%% 127.0.0.1:%%PORT_2_UDP%%; 86 resolver 127.0.0.1:%%PORT_8083_UDP%% 127.0.0.1:%%PORT_8082_UDP%%;
87 resolver_timeout 1s; 87 resolver_timeout 1s;
88 proxy_pass http://$host:%%PORT_0%%/backend; 88 proxy_pass http://$host:%%PORT_8080%%/backend;
89 proxy_connect_timeout 1s; 89 proxy_connect_timeout 1s;
90 add_header X-IP $upstream_addr; 90 add_header X-IP $upstream_addr;
91 error_page 504 502 /50x; 91 error_page 504 502 /50x;
92 92
93 location /tcp2 { 93 location /tcp2 {
94 resolver_timeout 8s; 94 resolver_timeout 8s;
95 proxy_pass http://$host:%%PORT_0%%/backend; 95 proxy_pass http://$host:%%PORT_8080%%/backend;
96 } 96 }
97 } 97 }
98 98
99 location /backend { 99 location /backend {
100 return 200; 100 return 200;
105 } 105 }
106 } 106 }
107 107
108 EOF 108 EOF
109 109
110 $t->run_daemon(\&dns_daemon, port(1), $t); 110 $t->run_daemon(\&dns_daemon, port(8081), $t);
111 $t->run_daemon(\&dns_daemon, port(2), $t); 111 $t->run_daemon(\&dns_daemon, port(8082), $t);
112 112
113 $t->run_daemon(\&dns_daemon, port(3), $t, tcp => 1); 113 $t->run_daemon(\&dns_daemon, port(8083), $t, tcp => 1);
114 $t->waitforfile($t->testdir . '/' . port(3)); 114 $t->waitforfile($t->testdir . '/' . port(8083));
115 port(3, socket => 1)->close(); 115 port(8083, socket => 1)->close();
116 116
117 $t->run_daemon(\&dns_daemon, port(4), $t); 117 $t->run_daemon(\&dns_daemon, port(8084), $t);
118 118
119 $t->run()->plan(38); 119 $t->run()->plan(38);
120 120
121 $t->waitforfile($t->testdir . '/' . port(1)); 121 $t->waitforfile($t->testdir . '/' . port(8081));
122 $t->waitforfile($t->testdir . '/' . port(2)); 122 $t->waitforfile($t->testdir . '/' . port(8082));
123 $t->waitforfile($t->testdir . '/' . port(4)); 123 $t->waitforfile($t->testdir . '/' . port(8084));
124 124
125 ############################################################################### 125 ###############################################################################
126 126
127 my $p0 = port(0); 127 my $p0 = port(8080);
128 128
129 # schedule resend test, which takes about 5 seconds to complete 129 # schedule resend test, which takes about 5 seconds to complete
130 130
131 my $s = http_host_header('id.example.net', '/resend', start => 1); 131 my $s = http_host_header('id.example.net', '/resend', start => 1);
132 my $fe = http_host_header('fe.example.net', '/resend', start => 1); 132 my $fe = http_host_header('fe.example.net', '/resend', start => 1);
486 } 486 }
487 487
488 push @rdata, rd_addr(0, '127.0.0.1'); 488 push @rdata, rd_addr(0, '127.0.0.1');
489 489
490 } elsif ($name eq '2.example.net') { 490 } elsif ($name eq '2.example.net') {
491 if ($port == port(1)) { 491 if ($port == port(8081)) {
492 $state->{twocnt}++; 492 $state->{twocnt}++;
493 } 493 }
494 if ($state->{twocnt} & 1) { 494 if ($state->{twocnt} & 1) {
495 $rcode = SERVFAIL; 495 $rcode = SERVFAIL;
496 } 496 }
498 if ($type == A) { 498 if ($type == A) {
499 push @rdata, rd_addr($ttl, '127.0.0.1'); 499 push @rdata, rd_addr($ttl, '127.0.0.1');
500 } 500 }
501 501
502 } elsif ($name =~ /tcp2?.example.net/) { 502 } elsif ($name =~ /tcp2?.example.net/) {
503 $rcode = FORMERR if $port == port(2); 503 $rcode = FORMERR if $port == port(8082);
504 $hdr |= 0x0300 unless $extra{tcp}; 504 $hdr |= 0x0300 unless $extra{tcp};
505 push @rdata, rd_addr($ttl, $extra{tcp} 505 push @rdata, rd_addr($ttl, $extra{tcp}
506 ? '127.0.0.1' : '127.0.0.201') if $type == A; 506 ? '127.0.0.1' : '127.0.0.201') if $type == A;
507 } 507 }
508 508
534 534
535 my $sel = IO::Select->new($socket); 535 my $sel = IO::Select->new($socket);
536 my $tcp = 0; 536 my $tcp = 0;
537 537
538 if ($extra{tcp}) { 538 if ($extra{tcp}) {
539 $tcp = port(3, socket => 1); 539 $tcp = port(8083, socket => 1);
540 $sel->add($tcp); 540 $sel->add($tcp);
541 } 541 }
542 542
543 local $SIG{PIPE} = 'IGNORE'; 543 local $SIG{PIPE} = 'IGNORE';
544 544