comparison lib/Test/Nginx.pm @ 270:f857180657c9

Tests: whitespace, no functional changes.
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 20 Mar 2013 19:42:16 +0400
parents 8dac281ff522
children 1a6eef7ac914
comparison
equal deleted inserted replaced
269:970bb423e59f 270:f857180657c9
400 } 400 }
401 401
402 sub http($;%) { 402 sub http($;%) {
403 my ($request, %extra) = @_; 403 my ($request, %extra) = @_;
404 my $reply; 404 my $reply;
405
405 eval { 406 eval {
406 local $SIG{ALRM} = sub { die "timeout\n" }; 407 local $SIG{ALRM} = sub { die "timeout\n" };
407 local $SIG{PIPE} = sub { die "sigpipe\n" }; 408 local $SIG{PIPE} = sub { die "sigpipe\n" };
408 alarm($extra{timeout} || 2); 409 alarm($extra{timeout} || 2);
410
409 my $s = $extra{socket} || IO::Socket::INET->new( 411 my $s = $extra{socket} || IO::Socket::INET->new(
410 Proto => 'tcp', 412 Proto => 'tcp',
411 PeerAddr => '127.0.0.1:8080' 413 PeerAddr => '127.0.0.1:8080'
412 ) 414 )
413 or die "Can't connect to nginx: $!\n"; 415 or die "Can't connect to nginx: $!\n";
416
414 log_out($request); 417 log_out($request);
415 $s->print($request); 418 $s->print($request);
416 local $/; 419
417 select undef, undef, undef, $extra{sleep} if $extra{sleep}; 420 select undef, undef, undef, $extra{sleep} if $extra{sleep};
418 return '' if $extra{aborted}; 421 return '' if $extra{aborted};
422
423 local $/;
419 $reply = $s->getline(); 424 $reply = $s->getline();
425
420 alarm(0); 426 alarm(0);
421 }; 427 };
422 alarm(0); 428 alarm(0);
423 if ($@) { 429 if ($@) {
424 log_in("died: $@"); 430 log_in("died: $@");
425 return undef; 431 return undef;
426 } 432 }
433
427 log_in($reply); 434 log_in($reply);
428 return $reply; 435 return $reply;
429 } 436 }
430 437
431 ############################################################################### 438 ###############################################################################