Skip to content

Commit

Permalink
sync'd Test::Nginx to git HEAD.
Browse files Browse the repository at this point in the history
  • Loading branch information
agentzh committed May 12, 2010
1 parent 8027a24 commit 5531050
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 12 deletions.
4 changes: 3 additions & 1 deletion test/lib/Test/Nginx/LWP.pm
Expand Up @@ -32,6 +32,8 @@ use Test::Nginx::Util qw(
master_process_enabled
config_preamble
repeat_each
no_shuffle
no_root_location
);

our $UserAgent = LWP::UserAgent->new;
Expand All @@ -43,7 +45,7 @@ $UserAgent->agent(__PACKAGE__);
our @EXPORT = qw( plan run_tests run_test
repeat_each config_preamble worker_connections
master_process_enabled
no_long_string);
no_long_string no_shuffle no_root_location);

sub no_long_string () {
$NoLongString = 1;
Expand Down
35 changes: 28 additions & 7 deletions test/lib/Test/Nginx/Socket.pm
Expand Up @@ -7,12 +7,14 @@ use Test::Base -Base;

our $VERSION = '0.08';

use Encode;
use Data::Dumper;
use Time::HiRes qw(sleep time);
use Test::LongString;
use List::MoreUtils qw( any );
use IO::Select ();

our $ServerAddr = 'localhost';
our $Timeout = 2;

use Test::Nginx::Util qw(
Expand All @@ -38,6 +40,8 @@ use Test::Nginx::Util qw(
workers
master_on
log_level
no_shuffle
no_root_location
);

#use Smart::Comments::JSON '###';
Expand All @@ -53,9 +57,11 @@ our @EXPORT = qw( plan run_tests run_test
repeat_each config_preamble worker_connections
master_process_enabled
no_long_string workers master_on
log_level);
log_level no_shuffle no_root_location
server_addr
);

sub send_request ($$$);
sub send_request ($$$$);

sub run_test_helper ($);

Expand All @@ -67,6 +73,15 @@ sub no_long_string () {
$NoLongString = 1;
}

sub server_addr (@) {
if (@_) {
#warn "setting server addr to $_[0]\n";
$ServerAddr = shift;
} else {
return $ServerAddr;
}
}

$RunTestHelper = \&run_test_helper;

sub parse_request ($$) {
Expand Down Expand Up @@ -199,7 +214,7 @@ $parsed_req->{content}";
}

my $raw_resp = send_request($req, $block->raw_request_middle_delay,
$timeout);
$timeout, $block->name);

#warn "raw resonse: [$raw_resp]\n";

Expand Down Expand Up @@ -297,6 +312,10 @@ $parsed_req->{content}";
$expected = $block->response_body;
}

if ($block->charset) {
Encode::from_to($expected, 'UTF-8', $block->charset);
}

$expected =~ s/\$ServerPort\b/$ServerPort/g;
$expected =~ s/\$ServerPortForClient\b/$ServerPortForClient/g;
#warn show_all_chars($content);
Expand All @@ -322,13 +341,13 @@ $parsed_req->{content}";
}
}

sub send_request ($$$) {
my ($req, $middle_delay, $timeout) = @_;
sub send_request ($$$$) {
my ($req, $middle_delay, $timeout, $name) = @_;

my @req_bits = ref $req ? @$req : ($req);

my $sock = IO::Socket::INET->new(
PeerAddr => 'localhost',
PeerAddr => $ServerAddr,
PeerPort => $ServerPortForClient,
Proto => 'tcp'
) or die "Can't connect to localhost:$ServerPortForClient: $!\n";
Expand All @@ -347,6 +366,7 @@ sub send_request ($$$) {
write_buf => shift @req_bits,
middle_delay => $middle_delay,
sock => $sock,
name => $name,
};

my $readable_hdls = IO::Select->new($sock);
Expand Down Expand Up @@ -469,7 +489,8 @@ sub send_request ($$$) {
}

sub timeout_event_handler ($) {
warn "socket client: timed out";
my $ctx = shift;
warn "socket client: timed out - $ctx->{name}\n";
}

sub error_event_handler ($) {
Expand Down
37 changes: 33 additions & 4 deletions test/lib/Test/Nginx/Util.pm
Expand Up @@ -13,13 +13,20 @@ use HTTP::Response;
use Module::Install::Can;
use Cwd qw( cwd );
use List::Util qw( shuffle );
use Time::HiRes qw( sleep );

our $NoNginxManager = 0;
our $Profiling = 0;

our $RepeatEach = 1;
our $MAX_PROCESSES = 10;

our $NoShuffle = 0;

sub no_shuffle () {
$NoShuffle = 1;
}

our $ForkManager;

if ($Profiling) {
Expand All @@ -36,7 +43,8 @@ our $LogLevel = 'debug';
our $MasterProcessEnabled = 'off';
our $DaemonEnabled = 'on';
our $ServerPort = 1984;
our $ServerPortForClient = 1984;
our $ServerPortForClient = $ENV{TEST_NGINX_CLIENT_PORT} || 1984;
our $NoRootLocation = 0;
#our $ServerPortForClient = 1984;


Expand All @@ -56,6 +64,10 @@ sub worker_connections (@) {
}
}

sub no_root_location () {
$NoRootLocation = 1;
}

sub workers (@) {
if (@_) {
#warn "setting workers to $_[0]";
Expand Down Expand Up @@ -110,6 +122,8 @@ our @EXPORT_OK = qw(
repeat_each
master_process_enabled
log_level
no_shuffle
no_root_location
);


Expand Down Expand Up @@ -148,7 +162,7 @@ sub run_tests () {
#warn "[INFO] Using nginx version $NginxVersion ($NginxRawVersion)\n";
}

for my $block (shuffle Test::Base::blocks()) {
for my $block ($NoShuffle ? Test::Base::blocks() : shuffle Test::Base::blocks()) {
#for (1..3) {
run_test($block);
#}
Expand Down Expand Up @@ -213,11 +227,11 @@ http {
default_type text/plain;
keepalive_timeout 68;
$http_config
$http_config
server {
listen $ServerPort;
server_name localhost;
server_name 'localhost';
client_max_body_size 30M;
#client_body_buffer_size 4k;
Expand All @@ -230,10 +244,18 @@ $ConfigPreamble
$config
# End test case config.
_EOC_

if (! $NoRootLocation) {
print $out <<_EOC_;
location / {
root $HtmlDir;
index index.html index.htm;
}
_EOC_
}

print $out <<_EOC_;
}
}
Expand Down Expand Up @@ -440,6 +462,13 @@ start_nginx:
}
}

if ($block->init) {
eval $block->init;
if ($@) {
Test::More::BAIL_OUT("$name - init failed: $@");
}
}

my $i = 0;
while ($i++ < $RepeatEach) {
if ($should_skip) {
Expand Down

0 comments on commit 5531050

Please sign in to comment.