Skip to content

Commit

Permalink
bugfix: Dgram: insert a receive block only if "--- dgram_response" is…
Browse files Browse the repository at this point in the history
… specified.
  • Loading branch information
alonbg committed Sep 4, 2016
1 parent 196f9f7 commit a38f74e
Showing 1 changed file with 50 additions and 35 deletions.
85 changes: 50 additions & 35 deletions lib/Test/Nginx/Socket/Lua/Dgram.pm
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,11 @@ _EOC_
_EOC_
} else {
$new_http_server_config .= <<_EOC_;
sock:send('trigger dgram req')
local data, err = sock:receive()
if not data then
sock:close()
ngx.say("receive stream response error: ", err)
return
end
local bytes, err = sock:send('trigger dgram req')
if not bytes then
ngx.say("send stream request error: ", err)
return
end
_EOC_
}

Expand All @@ -128,6 +126,14 @@ _EOC_
|| defined $block->dgram_response
|| defined $block->dgram_response_like)
{
$new_http_server_config .= <<_EOC_;
local data, err = sock:receive()
if not data then
sock:close()
ngx.say("receive stream response error: ", err)
return
end
_EOC_
if (defined $block->log_dgram_response) {
$new_http_server_config .= <<_EOC_;
print("stream response: ", data)
Expand Down Expand Up @@ -162,24 +168,29 @@ _EOC_
return
end
_EOC_
}

$new_http_server_config .= <<_EOC_;
sock:send('trigger_dgram_req2')
local data, err = sock:receive()
if not data then
ngx.say("receive stream response error: ", err)
return
end
} else {
$new_http_server_config .= <<_EOC_;
local bytes, err = sock:send('trigger dgram req 2')
if not bytes then
ngx.say("send stream request error: ", err)
return
end
_EOC_
}

if (defined $block->response_body
|| defined $block->response_body_like
|| defined $block->dgram_response
|| defined $block->dgram_response_like)
{
$new_http_server_config .= <<_EOC_;
ngx.print(data)
local data, err = sock:receive()
if not data then
sock:close()
ngx.say("receive stream response error: ", err)
return
end
ngx.print(data)
_EOC_
}
}
Expand All @@ -197,24 +208,22 @@ _EOC_
if (defined $dgram_req3) {
my $file = gen_data_file($dgram_req3);
$new_http_server_config .= <<_EOC_;
local f = assert(io.open('$file', 'r'))
local data = assert(f:read("*a"))
assert(f:close())
local bytes, err = sock:send(data)
if not bytes then
ngx.say("send stream request error: ", err)
return
end
local f = assert(io.open('$file', 'r'))
local data = assert(f:read("*a"))
assert(f:close())
local bytes, err = sock:send(data)
if not bytes then
ngx.say("send stream request error: ", err)
return
end
_EOC_
}

$new_http_server_config .= <<_EOC_;
sock:send('trigger_dgram_req3')
local data, err = sock:receive()
if not data then
ngx.say("receive stream response error: ", err)
return
end
} else {
$new_http_server_config .= <<_EOC_;
local bytes, err = sock:send('trigger dgram req 3')
if not bytes then
ngx.say("send stream request error: ", err)
return
end
_EOC_

if (defined $block->response_body
Expand All @@ -223,7 +232,13 @@ _EOC_
|| defined $block->dgram_response_like)
{
$new_http_server_config .= <<_EOC_;
ngx.print(data)
local data, err = sock:receive()
if not data then
sock:close()
ngx.say("receive stream response error: ", err)
return
end
ngx.print(data)
_EOC_
}
}
Expand Down

0 comments on commit a38f74e

Please sign in to comment.