shdict: improved the error handling a bit and also added more (passing) tests.

This commit is contained in:
Yichun Zhang (agentzh) 2014-01-04 21:56:52 -08:00
Родитель 5bf928ede0
Коммит f6d309ffd8
2 изменённых файлов: 58 добавлений и 1 удалений

Просмотреть файл

@ -885,7 +885,9 @@ ngx_http_lua_shdict_set_helper(lua_State *L, int flags)
case LUA_TNIL:
if (flags & (NGX_HTTP_LUA_SHDICT_ADD|NGX_HTTP_LUA_SHDICT_REPLACE)) {
return luaL_error(L, "attempt to add or replace nil values");
lua_pushnil(L);
lua_pushliteral(L, "attempt to add or replace nil values");
return 2;
}
value.len = 0;

Просмотреть файл

@ -2243,3 +2243,58 @@ get ok: 33, flags: nil
--- no_error_log
[error]
=== TEST 80: add nil values
--- http_config
lua_shared_dict dogs 1m;
--- config
location = /test {
content_by_lua '
local dogs = ngx.shared.dogs
local ok, err = dogs:add("foo", nil)
if not ok then
ngx.say("not ok: ", err)
return
end
ngx.say("ok")
';
}
--- request
GET /test
--- response_body
not ok: attempt to add or replace nil values
--- no_error_log
[error]
=== TEST 33: replace key with exptime
--- http_config
lua_shared_dict dogs 1m;
--- config
location = /test {
content_by_lua '
local dogs = ngx.shared.dogs
dogs:set("foo", 2, 0)
dogs:replace("foo", 32, 0.01)
local data = dogs:get("foo")
ngx.say("get foo: ", data)
ngx.location.capture("/sleep/0.02")
local res, err, forcible = dogs:replace("foo", 10502)
ngx.say("replace: ", res, " ", err, " ", forcible)
ngx.say("foo = ", dogs:get("foo"))
';
}
location ~ ^/sleep/(.+) {
echo_sleep $1;
}
--- request
GET /test
--- response_body
get foo: 32
replace: false not found false
foo = nil
--- no_error_log
[error]