comparison proxy_upgrade.t @ 583:5276aceb32a6

Tests: style, no functional changes.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 20 May 2015 14:42:51 +0300
parents fc6b8270469c
children 7d6db4ac6ab0
comparison
equal deleted inserted replaced
582:dc97097100a5 583:5276aceb32a6
1 #!/usr/bin/perl 1 #!/usr/bin/perl
2 2
3 # (C) Maxim Dounin 3 # (C) Maxim Dounin
4 4
5 # Tests for http proxy upgrade support. In contrast to proxy_websocket.t 5 # Tests for http proxy upgrade support.
6 # this test doesn't try to use binary WebSocket protocol, but uses simple 6 # In contrast to proxy_websocket.t, this test doesn't try to use binary
7 # plain text protocol instead. 7 # WebSocket protocol, but uses simple plain text protocol instead.
8 8
9 ############################################################################### 9 ###############################################################################
10 10
11 use warnings; 11 use warnings;
12 use strict; 12 use strict;
13 13
14 use Test::More; 14 use Test::More;
15 15
16 use IO::Poll; 16 use IO::Poll;
17 use IO::Select; 17 use IO::Select;
18 use IO::Socket::INET;
19 use Socket qw/ CRLF /; 18 use Socket qw/ CRLF /;
20 19
21 BEGIN { use FindBin; chdir($FindBin::Bin); } 20 BEGIN { use FindBin; chdir($FindBin::Bin); }
22 21
23 use lib 'lib'; 22 use lib 'lib';
95 like(upgrade_read($s), qr/^(bar){16384}\d+$/, "upgrade $i"); 94 like(upgrade_read($s), qr/^(bar){16384}\d+$/, "upgrade $i");
96 is(upgrade_read($s), 'bazz' . $i, "upgrade small $i"); 95 is(upgrade_read($s), 'bazz' . $i, "upgrade small $i");
97 } 96 }
98 } 97 }
99 98
99 undef $s;
100
100 # establish connection with some pipelined data 101 # establish connection with some pipelined data
101 # and make sure they are correctly passed upstream 102 # and make sure they are correctly passed upstream
102 103
103 undef $s;
104 $s = upgrade_connect(message => "foo"); 104 $s = upgrade_connect(message => "foo");
105 ok($s, "handshake pipelined"); 105 ok($s, "handshake pipelined");
106 106
107 SKIP: { 107 SKIP: {
108 skip "handshake failed", 2 unless $s; 108 skip "handshake failed", 2 unless $s;
111 111
112 upgrade_write($s, "foo"); 112 upgrade_write($s, "foo");
113 is(upgrade_read($s), "bar", "next to pipelined"); 113 is(upgrade_read($s), "bar", "next to pipelined");
114 } 114 }
115 115
116 undef $s;
117
116 # connection should not be upgraded unless upgrade was actually 118 # connection should not be upgraded unless upgrade was actually
117 # requested and allowed by configuration 119 # requested and allowed by configuration
118 120
119 undef $s;
120 $s = upgrade_connect(noheader => 1); 121 $s = upgrade_connect(noheader => 1);
121 ok(!$s, "handshake noupgrade"); 122 ok(!$s, "handshake noupgrade");
122 123
123 ############################################################################### 124 ###############################################################################
124 125
125 sub upgrade_connect { 126 sub upgrade_connect {
126 my (%opts) = @_; 127 my (%opts) = @_;
127 128
128 my $s = IO::Socket::INET->new( 129 my $s = IO::Socket::INET->new(
129 Proto => 'tcp', 130 Proto => 'tcp',
130 PeerAddr => '127.0.0.1:8080' 131 PeerAddr => '127.0.0.1:8080',
131 ) 132 )
132 or die "Can't connect to nginx: $!\n"; 133 or die "Can't connect to nginx: $!\n";
133 134
134 # send request, $h->to_string 135 # send request, $h->to_string
135 136