Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for array of requests with delays to pipelined_requests #117

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 47 additions & 6 deletions lib/Test/Nginx/Socket.pm
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ sub get_req_from_block ($) {
"$name - invalid entries in --- pipelined_requests");
}
my $i = 0;
my $prq = "";
my @prq = ();
for my $request (@$reqs) {
my $conn_type;
if ($i == @$reqs - 1) {
Expand All @@ -399,15 +399,56 @@ sub get_req_from_block ($) {
} else {
($hdr, $is_chunked) = parse_more_headers($more_headers);
}

if (!ref $request) {
# This request is a good old string.
my $r_br = build_request_from_packets($name, $hdr,
$is_chunked, $conn_type,
[$request] );

push @prq, {value => $$r_br[0]};

} elsif (ref $request eq 'ARRAY') {
# Request expressed as a serie of packets
my @packet_array = ();
for my $one_packet (@$request) {
if (!ref $one_packet) {
# Packet is a string.
push @packet_array, $one_packet;
} elsif (ref $one_packet eq 'HASH'){
# Packet is a hash with a value...
push @packet_array, $one_packet->{value};
} else {
bail_out "$name - Invalid syntax. $one_packet should be a string or hash with value.";
}
}

my $transformed_packet_array = build_request_from_packets($name, $hdr,
$is_chunked, $conn_type,
\@packet_array);
my @transformed_req = ();
my $idx = 0;
for my $one_transformed_packet (@$transformed_packet_array) {
if (!ref $$request[$idx]) {
# it is a string
push @transformed_req, {value => $one_transformed_packet};
} else {
# Is a HASH (checked above as $one_packet)
$$request[$idx]->{value} = $one_transformed_packet;
push @transformed_req, $$request[$idx];
}
$idx++;
}

push @prq, @transformed_req
} else {
bail_out "$name - Invalid syntax. $request should be a string or an array of packets.";
}

my $r_br = build_request_from_packets($name, $hdr,
$is_chunked, $conn_type,
[$request] );
$prq .= $$r_br[0];
$i++;
}
push @req_list, [{value =>$prq}];

push @req_list, \@prq;
} else {
my ($is_chunked, $hdr);

Expand Down
13 changes: 10 additions & 3 deletions t/get_req_from_block.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Unit tests for Test::Nginx::Socket::get_req_from_block
use lib 'lib';
use Test::Nginx::Socket tests => 7;
use Test::Nginx::Socket tests => 8;

my @block_list = blocks();
my $i = 0; # Use $i to make copy/paste of tests easier.
Expand All @@ -12,8 +12,8 @@ is_deeply(Test::Nginx::Socket::get_req_from_block($block_list[$i]),
."\r\nContent-Length: 15\r\n\r\nvalue=N%3A12345"}]],
$block_list[$i++]->name);
is_deeply(Test::Nginx::Socket::get_req_from_block($block_list[$i]),
[[{ value => "HEAD /foo HTTP/1.1\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n".
"GET /bar HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"}]],
[[{ value => "HEAD /foo HTTP/1.1\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n"},
{ value => "GET /bar HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"}]],
$block_list[$i++]->name);
is_deeply(Test::Nginx::Socket::get_req_from_block($block_list[$i]),
[[{ value => "POST /foo HTTP/1.1\r
Expand All @@ -38,6 +38,10 @@ is_deeply(Test::Nginx::Socket::get_req_from_block($block_list[$i]),
[{value =>"GET "},
{value =>"/foo HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"}]],
$block_list[$i++]->name);
is_deeply(Test::Nginx::Socket::get_req_from_block($block_list[$i]),
[[{value =>"GET /foo HTTP/1.1\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n"},
{value =>"GET /bar HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n",delay_before => 3}]],
$block_list[$i++]->name);
__DATA__

=== request: basic string
Expand Down Expand Up @@ -73,3 +77,6 @@ rub my face in the dirt"
--- request eval
[["POST /foo\r\n", {value => "value=N%3A12345", delay_before =>3}],
[{value => "GET "}, {value => "/foo"}]]
=== pipelined_requests: an array of requests with delays.
--- pipelined_requests eval
["GET /foo", [{value => "GET /bar", delay_before =>3}]]