bugfix: added the plugin load. (#95)

* bugfix: added the plugin load.

* test: added test cases for limit count.

* test: added Lua sleep at the end of init_worker.

left enough time for read data from etcd, otherwise worker maybe deal with request before get data from etcd.

* test: added no_shuffle();
This commit is contained in:
WenMing 2019-06-14 16:11:14 +08:00 committed by GitHub
parent 17a4f3c8e8
commit ba576985b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 76 additions and 1 deletions

View File

@ -13,6 +13,9 @@ events {
worker_connections 10620;
}
worker_rlimit_core 500M;
working_directory /tmp/cores/;
worker_shutdown_timeout 3;
http {

View File

@ -42,6 +42,7 @@ end
function _M.init_worker()
require("apisix.route").init_worker()
require("apisix.balancer").init_worker()
require("apisix.plugin").init_worker()
require("apisix.service").init_worker()
require("apisix.consumer").init_worker()
require("apisix.heartbeat").init_worker()

View File

@ -139,4 +139,9 @@ function _M.merge_service_route(service_conf, route_conf)
end
function _M.init_worker()
load()
end
return _M

View File

@ -56,6 +56,7 @@ _EOC_
init_worker_by_lua_block {
require("apisix").init_worker()
os.execute("sleep 1")
}
server {

View File

@ -3,6 +3,7 @@ use t::APISix 'no_plan';
repeat_each(2);
no_long_string();
no_root_location();
no_shuffle();
run_tests;
__DATA__

View File

@ -1,7 +1,8 @@
use t::APISix 'no_plan';
repeat_each(2);
repeat_each(1);
no_long_string();
no_shuffle();
no_root_location();
run_tests;
@ -49,3 +50,66 @@ invalid "enum" in docuement at pointer "#/key"
done
--- no_error_log
[error]
=== TEST 3: set route(id: 1)
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"methods": ["GET"],
"plugins": {
"limit-count": {
"count": 2,
"time_window": 60,
"rejected_code": 503,
"key": "remote_addr"
}
},
"id":1,
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/hello"
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]
=== TEST 4: up the limit
--- pipelined_requests eval
["GET /hello", "GET /hello", "GET /hello", "GET /hello"]
--- error_code eval
[200, 200, 503, 503]
--- no_error_log
[error]
=== TEST 5: up the limit
--- pipelined_requests eval
["GET /hello1", "GET /hello", "GET /hello2", "GET /hello", "GET /hello"]
--- error_code eval
[404, 200, 404, 200, 503]
--- no_error_log
[error]