Skip to content

Commit 5d614b0

Browse files
committed
added a (passing) fuzz test case for shdict.
1 parent b57d60d commit 5d614b0

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

t/126-shdict-frag.t

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use Test::Nginx::Socket::Lua;
88

99
#repeat_each(2);
1010

11-
plan tests => repeat_each() * 36;
11+
plan tests => repeat_each() * 39;
1212

1313
#no_diff();
1414
no_long_string();
@@ -1203,3 +1203,46 @@ failed to safe set baz: no memory
12031203
--- no_error_log
12041204
[error]
12051205
1206+
1207+
1208+
=== TEST 10: fuzz testing
1209+
--- http_config
1210+
lua_shared_dict dogs 200k;
1211+
--- config
1212+
location = /t {
1213+
content_by_lua '
1214+
local rand = math.random
1215+
local dogs = ngx.shared.dogs
1216+
local maxsz = 9000
1217+
local maxkeyidx = 30
1218+
local rep = string.rep
1219+
1220+
math.randomseed(ngx.time())
1221+
for i = 1, 30000 do
1222+
local key = "mylittlekey" .. rand(maxkeyidx)
1223+
local ok, err = dogs:get(key)
1224+
if not ok or rand() > 0.6 then
1225+
sz = rand(maxsz)
1226+
val = rep("a", sz)
1227+
local ok, err, forcible = dogs:set(key, val)
1228+
if err then
1229+
ngx.log(ngx.ERR, "failed to set key: ", err)
1230+
-- return
1231+
end
1232+
if forcible then
1233+
-- error("forcible")
1234+
end
1235+
end
1236+
end
1237+
ngx.say("ok")
1238+
';
1239+
}
1240+
--- request
1241+
GET /t
1242+
--- response_body
1243+
ok
1244+
1245+
--- no_error_log
1246+
[error]
1247+
--- timeout: 30
1248+

0 commit comments

Comments
 (0)