mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-04 21:17:36 +08:00
test: make ci stable (#3329)
This commit is contained in:
parent
da99a03cbf
commit
319c3ebefd
@ -85,7 +85,7 @@ local function filter(service)
|
||||
service.value.upstream.nodes = new_nodes
|
||||
end
|
||||
|
||||
core.log.info("filter service: ", core.json.delay_encode(service))
|
||||
core.log.info("filter service: ", core.json.delay_encode(service, true))
|
||||
end
|
||||
|
||||
|
||||
|
@ -70,7 +70,7 @@ local function filter(route)
|
||||
route.value.upstream.nodes = new_nodes
|
||||
end
|
||||
|
||||
core.log.info("filter route: ", core.json.delay_encode(route))
|
||||
core.log.info("filter route: ", core.json.delay_encode(route, true))
|
||||
end
|
||||
|
||||
|
||||
|
@ -237,7 +237,7 @@ function _M.init_worker()
|
||||
upstream.value.nodes = new_nodes
|
||||
end
|
||||
|
||||
core.log.info("filter upstream: ", core.json.delay_encode(upstream))
|
||||
core.log.info("filter upstream: ", core.json.delay_encode(upstream, true))
|
||||
end,
|
||||
})
|
||||
if not upstreams then
|
||||
|
@ -330,8 +330,22 @@ passed
|
||||
|
||||
|
||||
=== TEST 10: hit prometheus route
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
ngx.sleep(1) -- wait for data synced
|
||||
local t = require("lib.test_admin").test
|
||||
local code, body = t('/apisix/prometheus/metrics',
|
||||
ngx.HTTP_GET)
|
||||
|
||||
if code >= 300 then
|
||||
ngx.status = code
|
||||
end
|
||||
ngx.say(body)
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /apisix/prometheus/metrics
|
||||
GET /t
|
||||
--- error_code: 403
|
||||
|
||||
|
||||
|
@ -26,13 +26,14 @@ run_tests;
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: set upstream(id: 1)
|
||||
=== TEST 1: set upstream (use an id can't be referred by other route
|
||||
so that we can delete it later)
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local t = require("lib.test_admin").test
|
||||
local etcd = require("apisix.core.etcd")
|
||||
local code, body = t('/apisix/admin/upstreams/1',
|
||||
local code, body = t('/apisix/admin/upstreams/admin_up',
|
||||
ngx.HTTP_PUT,
|
||||
[[{
|
||||
"nodes": {
|
||||
@ -50,7 +51,7 @@ __DATA__
|
||||
"type": "roundrobin",
|
||||
"desc": "new upstream"
|
||||
},
|
||||
"key": "/apisix/upstreams/1"
|
||||
"key": "/apisix/upstreams/admin_up"
|
||||
},
|
||||
"action": "set"
|
||||
}]]
|
||||
@ -59,7 +60,7 @@ __DATA__
|
||||
ngx.status = code
|
||||
ngx.say(body)
|
||||
|
||||
local res = assert(etcd.get('/upstreams/1'))
|
||||
local res = assert(etcd.get('/upstreams/admin_up'))
|
||||
local create_time = res.body.node.value.create_time
|
||||
assert(create_time ~= nil, "create_time is nil")
|
||||
local update_time = res.body.node.value.update_time
|
||||
@ -75,12 +76,12 @@ passed
|
||||
|
||||
|
||||
|
||||
=== TEST 2: get upstream(id: 1)
|
||||
=== TEST 2: get upstream
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local t = require("lib.test_admin").test
|
||||
local code, body = t('/apisix/admin/upstreams/1',
|
||||
local code, body = t('/apisix/admin/upstreams/admin_up',
|
||||
ngx.HTTP_GET,
|
||||
nil,
|
||||
[[{
|
||||
@ -92,7 +93,7 @@ passed
|
||||
"type": "roundrobin",
|
||||
"desc": "new upstream"
|
||||
},
|
||||
"key": "/apisix/upstreams/1"
|
||||
"key": "/apisix/upstreams/admin_up"
|
||||
},
|
||||
"action": "get"
|
||||
}]]
|
||||
@ -111,12 +112,12 @@ passed
|
||||
|
||||
|
||||
|
||||
=== TEST 3: delete upstream(id: 1)
|
||||
=== TEST 3: delete upstream
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local t = require("lib.test_admin").test
|
||||
local code, message = t('/apisix/admin/upstreams/1',
|
||||
local code, message = t('/apisix/admin/upstreams/admin_up',
|
||||
ngx.HTTP_DELETE,
|
||||
nil,
|
||||
[[{
|
||||
@ -1911,12 +1912,12 @@ passed
|
||||
|
||||
|
||||
|
||||
=== TEST 55: create upstream with create_time and update_time(id: 1)
|
||||
=== TEST 55: create upstream with create_time and update_time
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local t = require("lib.test_admin").test
|
||||
local code, body = t('/apisix/admin/upstreams/1',
|
||||
local code, body = t('/apisix/admin/upstreams/up_create_update_time',
|
||||
ngx.HTTP_PUT,
|
||||
[[{
|
||||
"nodes": {
|
||||
@ -1936,7 +1937,7 @@ passed
|
||||
"create_time": 1602883670,
|
||||
"update_time": 1602893670
|
||||
},
|
||||
"key": "/apisix/upstreams/1"
|
||||
"key": "/apisix/upstreams/up_create_update_time"
|
||||
},
|
||||
"action": "set"
|
||||
}]]
|
||||
@ -1955,12 +1956,12 @@ passed
|
||||
|
||||
|
||||
|
||||
=== TEST 56: delete test upstream(id: 1)
|
||||
=== TEST 56: delete test upstream
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local t = require("lib.test_admin").test
|
||||
local code, message = t('/apisix/admin/upstreams/1',
|
||||
local code, message = t('/apisix/admin/upstreams/up_create_update_time',
|
||||
ngx.HTTP_DELETE,
|
||||
nil,
|
||||
[[{
|
||||
|
@ -78,7 +78,7 @@ __DATA__
|
||||
content_by_lua_block {
|
||||
local json = require("toolkit.json")
|
||||
local t = require("lib.test_admin").test
|
||||
local code, message, res = t('/apisix/admin/upstreams/1',
|
||||
local code, message, res = t('/apisix/admin/upstreams/unwanted',
|
||||
ngx.HTTP_PUT,
|
||||
[[{
|
||||
"nodes": {
|
||||
@ -101,7 +101,7 @@ __DATA__
|
||||
}
|
||||
}
|
||||
--- response_body
|
||||
{"action":"set","node":{"key":"/apisix/upstreams/1","value":{"hash_on":"vars","id":"1","nodes":{"127.0.0.1:8080":1},"pass_host":"pass","type":"roundrobin"}}}
|
||||
{"action":"set","node":{"key":"/apisix/upstreams/unwanted","value":{"hash_on":"vars","id":"unwanted","nodes":{"127.0.0.1:8080":1},"pass_host":"pass","type":"roundrobin"}}}
|
||||
|
||||
|
||||
|
||||
@ -111,7 +111,7 @@ __DATA__
|
||||
content_by_lua_block {
|
||||
local json = require("toolkit.json")
|
||||
local t = require("lib.test_admin").test
|
||||
local code, message, res = t('/apisix/admin/upstreams/1',
|
||||
local code, message, res = t('/apisix/admin/upstreams/unwanted',
|
||||
ngx.HTTP_PATCH,
|
||||
[[{
|
||||
"nodes": {
|
||||
@ -134,7 +134,7 @@ __DATA__
|
||||
}
|
||||
}
|
||||
--- response_body
|
||||
{"action":"compareAndSwap","node":{"key":"/apisix/upstreams/1","value":{"hash_on":"vars","id":"1","nodes":{"127.0.0.1:8080":1},"pass_host":"pass","type":"roundrobin"}}}
|
||||
{"action":"compareAndSwap","node":{"key":"/apisix/upstreams/unwanted","value":{"hash_on":"vars","id":"unwanted","nodes":{"127.0.0.1:8080":1},"pass_host":"pass","type":"roundrobin"}}}
|
||||
|
||||
|
||||
|
||||
@ -144,7 +144,7 @@ __DATA__
|
||||
content_by_lua_block {
|
||||
local json = require("toolkit.json")
|
||||
local t = require("lib.test_admin").test
|
||||
local code, message, res = t('/apisix/admin/upstreams/1',
|
||||
local code, message, res = t('/apisix/admin/upstreams/unwanted',
|
||||
ngx.HTTP_GET
|
||||
)
|
||||
|
||||
@ -161,7 +161,7 @@ __DATA__
|
||||
}
|
||||
}
|
||||
--- response_body
|
||||
{"action":"get","count":"1","node":{"key":"/apisix/upstreams/1","value":{"hash_on":"vars","id":"1","nodes":{"127.0.0.1:8080":1},"pass_host":"pass","type":"roundrobin"}}}
|
||||
{"action":"get","count":"1","node":{"key":"/apisix/upstreams/unwanted","value":{"hash_on":"vars","id":"unwanted","nodes":{"127.0.0.1:8080":1},"pass_host":"pass","type":"roundrobin"}}}
|
||||
|
||||
|
||||
|
||||
@ -171,7 +171,7 @@ __DATA__
|
||||
content_by_lua_block {
|
||||
local json = require("toolkit.json")
|
||||
local t = require("lib.test_admin").test
|
||||
local code, message, res = t('/apisix/admin/upstreams/1',
|
||||
local code, message, res = t('/apisix/admin/upstreams/unwanted',
|
||||
ngx.HTTP_DELETE
|
||||
)
|
||||
|
||||
@ -186,7 +186,7 @@ __DATA__
|
||||
}
|
||||
}
|
||||
--- response_body
|
||||
{"action":"delete","deleted":"1","key":"/apisix/upstreams/1","node":{}}
|
||||
{"action":"delete","deleted":"1","key":"/apisix/upstreams/unwanted","node":{}}
|
||||
|
||||
|
||||
|
||||
|
@ -300,7 +300,7 @@ qr/"Host": "httpbin.org"/
|
||||
|
||||
|
||||
|
||||
=== TEST 13: set upstream(id: 1, using `rewrite` mode to pass upstream host)
|
||||
=== TEST 13: set upstream(using `rewrite` mode to pass upstream host)
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
@ -333,7 +333,7 @@ passed
|
||||
|
||||
|
||||
|
||||
=== TEST 14: set route(id: 1, using `rewrite` mode to pass upstream host)
|
||||
=== TEST 14: set route(using `rewrite` mode to pass upstream host)
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
@ -371,39 +371,12 @@ qr/host: httpbin.org/
|
||||
|
||||
|
||||
|
||||
=== TEST 16: set route(upstream deleted)
|
||||
--- 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,
|
||||
[[{
|
||||
"uri": "/uri",
|
||||
"upstream_id": "1"
|
||||
}]]
|
||||
)
|
||||
|
||||
if code >= 300 then
|
||||
ngx.status = code
|
||||
end
|
||||
ngx.say(body)
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
passed
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 17: delete upstream
|
||||
=== TEST 16: delete upstream in used
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local t = require("lib.test_admin").test
|
||||
ngx.sleep(0.5) -- wait for data synced
|
||||
local code, body = t('/apisix/admin/upstreams/1',
|
||||
ngx.HTTP_DELETE
|
||||
)
|
||||
@ -411,21 +384,13 @@ passed
|
||||
if code >= 300 then
|
||||
ngx.status = code
|
||||
end
|
||||
ngx.say(body)
|
||||
ngx.print(body)
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- error_code: 400
|
||||
--- response_body
|
||||
passed
|
||||
{"error_msg":"can not delete this upstream, route [1] is still using it now"}
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 18: hit route
|
||||
--- request
|
||||
GET /uri
|
||||
--- error_code: 502
|
||||
--- error_log
|
||||
failed to find upstream by id: 1
|
||||
|
Loading…
Reference in New Issue
Block a user