Skip to content

Commit

Permalink
Merge pull request #15 from spacewander/watch_ignore_return
Browse files Browse the repository at this point in the history
fix watch/ignore return value
  • Loading branch information
membphis committed Feb 20, 2017
2 parents e07553a + d5d0a5d commit 1370f1e
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/resty/beanstalkd.lua
Expand Up @@ -95,7 +95,7 @@ function _M.watch(self, tube)
if size then
return size, line
end
return 0, line
return nil, line
end

function _M.ignore(self, tube)
Expand All @@ -116,7 +116,7 @@ function _M.ignore(self, tube)
if size then
return size, line
end
return 0, line
return nil, line
end

function _M.put(self, body, pri, delay, ttr)
Expand Down
38 changes: 37 additions & 1 deletion t/011-watch.t
Expand Up @@ -5,7 +5,7 @@ use Cwd qw(cwd);

repeat_each(2);

plan tests => repeat_each() * (3 * blocks());
plan tests => repeat_each() * (3 * blocks() + 1);

my $pwd = cwd();

Expand Down Expand Up @@ -56,3 +56,39 @@ watching: 1
--- no_error_log
[error]
=== TEST 2: handle watching failure
--- http_config eval: $::HttpConfig
--- config
location /t {
content_by_lua '
local beanstalkd = require "resty.beanstalkd"
local bean, err = beanstalkd:new()
local ok, err = bean:connect("127.0.0.1", 2017)
if not ok then
ngx.say("1: failed to connect: ", err)
return
end
local size, err = bean:watch("default")
if not size then
ngx.say("failed to watch tube: ", err)
return
end
ngx.say("watching: ", size)
bean:close()
';
}
--- request
GET /t
--- tcp_listen: 2017
--- tcp_query eval
"watch default\r\n"
--- tcp_reply eval
"OUT_OF_MEMORY\r\n"
--- response_body
failed to watch tube: OUT_OF_MEMORY
--- no_error_log
[error]
34 changes: 34 additions & 0 deletions t/012-ignore.t
Expand Up @@ -74,3 +74,37 @@ GET /t
--- no_error_log
[error]
=== TEST 2: handle ignore failure
--- http_config eval: $::HttpConfig
--- config
location /t {
content_by_lua '
local beanstalkd = require "resty.beanstalkd"
local bean, err = beanstalkd:new()
local ok, err = bean:connect("127.0.0.1", $TEST_NGINX_BEANSTALKD_PORT)
if not ok then
ngx.say("1: failed to connect: ", err)
return
end
local size, err = bean:ignore("default")
if not size then
ngx.say("2: failed to ignore tube: ", err)
return
end
ngx.say("watching: ", size)
bean:close()
';
}
--- request
GET /t
--- response_body_like chop
2: failed to ignore tube: NOT_IGNORED
--- no_error_log
[error]

0 comments on commit 1370f1e

Please sign in to comment.