apisix/t/core-schema.t
YuanSheng Wang 463e5601b3
optimize: used lru way to cache the validator object for schema. (#77)
* optimize: used `lru` way to cache the validator object for schema.

Fix #76.
2019-06-11 23:47:00 +08:00

84 lines
1.9 KiB
Perl

use t::APISix 'no_plan';
repeat_each(2);
no_long_string();
no_root_location();
log_level("info");
run_tests;
__DATA__
=== TEST 1: sanity
--- config
location /t {
content_by_lua_block {
local core = require("apisix.core")
local schema = {
type = "object",
properties = {
i = {type = "number", minimum = 0},
s = {type = "string"},
t = {type = "array", minItems = 1},
}
}
for i = 1, 10 do
local ok, err = core.schema.check(schema,
{i = i, s = "s" .. i, t = {i}})
assert(ok)
assert(err == nil)
end
ngx.say("passed")
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]
=== TEST 2: same schema in different timer
--- config
location /t {
content_by_lua_block {
local core = require("apisix.core")
local schema = {
type = "object",
properties = {
i = {type = "number", minimum = 0},
s = {type = "string"},
t = {type = "array", minItems = 1},
}
}
local count = 0
local function test()
for i = 1, 10 do
local ok, err = core.schema.check(schema,
{i = i, s = "s" .. i, t = {i}})
assert(ok)
assert(err == nil)
count = count + 1
end
end
ngx.timer.at(0, test)
ngx.timer.at(0, test)
ngx.timer.at(0, test)
ngx.sleep(1)
ngx.say("passed: ", count)
}
}
--- request
GET /t
--- response_body
passed: 30
--- no_error_log
[error]