comparison worker_shutdown_timeout_proxy_upgrade.t @ 1246:ebaa2c72879d

Tests: worker_shutdown_timeout on upgraded http connection.
author Sergey Kandaurov <pluknet@nginx.com>
date Mon, 20 Nov 2017 17:59:56 +0300
parents
children 97c8280de681
comparison
equal deleted inserted replaced
1245:6d7707405632 1246:ebaa2c72879d
1 #!/usr/bin/perl
2
3 # (C) Sergey Kandaurov
4 # (C) Nginx, Inc.
5
6 # Tests for worker_shutdown_timeout directive with http proxy upgrade stub.
7
8 ###############################################################################
9
10 use warnings;
11 use strict;
12
13 use Test::More;
14
15 use IO::Select;
16
17 BEGIN { use FindBin; chdir($FindBin::Bin); }
18
19 use lib 'lib';
20 use Test::Nginx;
21
22 ###############################################################################
23
24 select STDERR; $| = 1;
25 select STDOUT; $| = 1;
26
27 my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(2)
28 ->write_file_expand('nginx.conf', <<'EOF');
29
30 %%TEST_GLOBALS%%
31
32 daemon off;
33 worker_shutdown_timeout 10ms;
34
35 events {
36 }
37
38 http {
39 %%TEST_GLOBALS_HTTP%%
40
41 server {
42 listen 127.0.0.1:8080;
43 server_name localhost;
44
45 location / {
46 proxy_pass http://127.0.0.1:8081;
47 proxy_http_version 1.1;
48 proxy_set_header Upgrade foo;
49 proxy_set_header Connection Upgrade;
50 }
51 }
52 }
53
54 EOF
55
56 $t->run_daemon(\&http_daemon);
57 $t->run()->waitforsocket('127.0.0.1:' . port(8081));
58
59 ###############################################################################
60
61 my $s = http(<<EOF, start => 1);
62 GET / HTTP/1.1
63 Host: localhost
64 Upgrade: foo
65 Connection: Upgrade
66
67 EOF
68
69 my ($sel, $buf) = IO::Select->new($s);
70 if ($sel->can_read(5)) {
71 $s->sysread($buf, 1024);
72 log_in($buf);
73 };
74
75 like($buf, qr!HTTP/1.1 101!, 'upgraded connection');
76
77 $t->reload();
78
79 TODO: {
80 local $TODO = 'not yet' unless $t->has_version('1.13.7');
81
82 ok($sel->can_read(3), 'upgraded connection shutdown');
83
84 }
85
86 undef $s;
87
88 ###############################################################################
89
90 sub http_daemon {
91 my $server = IO::Socket::INET->new(
92 Proto => 'tcp',
93 LocalHost => '127.0.0.1:' . port(8081),
94 Listen => 5,
95 Reuse => 1
96 )
97 or die "Can't create listening socket: $!\n";
98
99 local $SIG{PIPE} = 'IGNORE';
100
101 my $client;
102
103 while ($client = $server->accept()) {
104 $client->autoflush(1);
105
106 my $headers = '';
107 my $uri = '';
108
109 while (<$client>) {
110 $headers .= $_;
111 last if (/^\x0d?\x0a?$/);
112 }
113
114 next if $headers eq '';
115
116 print $client <<'EOF';
117 HTTP/1.1 101 Switching
118 Upgrade: foo
119 Connection: Upgrade
120
121 EOF
122
123 }
124 }
125
126 ###############################################################################