comparison upstream.t @ 293:719285b89d7e

Tests: upstream.t minor fixes.
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 08 Jun 2013 02:38:50 +0400
parents ba5b92378653
children a9621dbbd0d4
comparison
equal deleted inserted replaced
292:2da774b0fc7d 293:719285b89d7e
62 62
63 $t->run_daemon(\&http_daemon, 8081); 63 $t->run_daemon(\&http_daemon, 8081);
64 $t->run_daemon(\&http_daemon, 8082); 64 $t->run_daemon(\&http_daemon, 8082);
65 $t->run(); 65 $t->run();
66 66
67 $t->waitforsocket('127.0.0.1:8081');
68 $t->waitforsocket('127.0.0.1:8082');
69
67 ############################################################################### 70 ###############################################################################
68 71
69 is(many('/', 30), '8081: 15, 8082: 15', 'balanced'); 72 is(many('/', 30), '8081: 15, 8082: 15', 'balanced');
70 73
71 # from 9 first requests to 8081, only 6 will be successfull, 74 # from 9 first requests to 8081, only 6 will be successfull,
92 95
93 sub many { 96 sub many {
94 my ($uri, $count, %opts) = @_; 97 my ($uri, $count, %opts) = @_;
95 my %ports; 98 my %ports;
96 99
97 for (1 .. 30) { 100 for (1 .. $count) {
98 if (http_get($uri) =~ /X-Port: (\d+)/) { 101 if (http_get($uri) =~ /X-Port: (\d+)/) {
99 $ports{$1} = 0 unless defined $ports{$1}; 102 $ports{$1} = 0 unless defined $ports{$1};
100 $ports{$1}++; 103 $ports{$1}++;
101 } 104 }
102 105
118 LocalPort => $port, 121 LocalPort => $port,
119 Listen => 5, 122 Listen => 5,
120 Reuse => 1 123 Reuse => 1
121 ) 124 )
122 or die "Can't create listening socket: $!\n"; 125 or die "Can't create listening socket: $!\n";
126
127 local $SIG{PIPE} = 'IGNORE';
123 128
124 while (my $client = $server->accept()) { 129 while (my $client = $server->accept()) {
125 $client->autoflush(1); 130 $client->autoflush(1);
126 131
127 my $headers = ''; 132 my $headers = '';