mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-05 05:27:35 +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
|
service.value.upstream.nodes = new_nodes
|
||||||
end
|
end
|
||||||
|
|
||||||
core.log.info("filter service: ", core.json.delay_encode(service))
|
core.log.info("filter service: ", core.json.delay_encode(service, true))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ local function filter(route)
|
|||||||
route.value.upstream.nodes = new_nodes
|
route.value.upstream.nodes = new_nodes
|
||||||
end
|
end
|
||||||
|
|
||||||
core.log.info("filter route: ", core.json.delay_encode(route))
|
core.log.info("filter route: ", core.json.delay_encode(route, true))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ function _M.init_worker()
|
|||||||
upstream.value.nodes = new_nodes
|
upstream.value.nodes = new_nodes
|
||||||
end
|
end
|
||||||
|
|
||||||
core.log.info("filter upstream: ", core.json.delay_encode(upstream))
|
core.log.info("filter upstream: ", core.json.delay_encode(upstream, true))
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
if not upstreams then
|
if not upstreams then
|
||||||
|
@ -330,8 +330,22 @@ passed
|
|||||||
|
|
||||||
|
|
||||||
=== TEST 10: hit prometheus route
|
=== 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
|
--- request
|
||||||
GET /apisix/prometheus/metrics
|
GET /t
|
||||||
--- error_code: 403
|
--- error_code: 403
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,13 +26,14 @@ run_tests;
|
|||||||
|
|
||||||
__DATA__
|
__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
|
--- config
|
||||||
location /t {
|
location /t {
|
||||||
content_by_lua_block {
|
content_by_lua_block {
|
||||||
local t = require("lib.test_admin").test
|
local t = require("lib.test_admin").test
|
||||||
local etcd = require("apisix.core.etcd")
|
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,
|
ngx.HTTP_PUT,
|
||||||
[[{
|
[[{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
@ -50,7 +51,7 @@ __DATA__
|
|||||||
"type": "roundrobin",
|
"type": "roundrobin",
|
||||||
"desc": "new upstream"
|
"desc": "new upstream"
|
||||||
},
|
},
|
||||||
"key": "/apisix/upstreams/1"
|
"key": "/apisix/upstreams/admin_up"
|
||||||
},
|
},
|
||||||
"action": "set"
|
"action": "set"
|
||||||
}]]
|
}]]
|
||||||
@ -59,7 +60,7 @@ __DATA__
|
|||||||
ngx.status = code
|
ngx.status = code
|
||||||
ngx.say(body)
|
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
|
local create_time = res.body.node.value.create_time
|
||||||
assert(create_time ~= nil, "create_time is nil")
|
assert(create_time ~= nil, "create_time is nil")
|
||||||
local update_time = res.body.node.value.update_time
|
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
|
--- config
|
||||||
location /t {
|
location /t {
|
||||||
content_by_lua_block {
|
content_by_lua_block {
|
||||||
local t = require("lib.test_admin").test
|
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,
|
ngx.HTTP_GET,
|
||||||
nil,
|
nil,
|
||||||
[[{
|
[[{
|
||||||
@ -92,7 +93,7 @@ passed
|
|||||||
"type": "roundrobin",
|
"type": "roundrobin",
|
||||||
"desc": "new upstream"
|
"desc": "new upstream"
|
||||||
},
|
},
|
||||||
"key": "/apisix/upstreams/1"
|
"key": "/apisix/upstreams/admin_up"
|
||||||
},
|
},
|
||||||
"action": "get"
|
"action": "get"
|
||||||
}]]
|
}]]
|
||||||
@ -111,12 +112,12 @@ passed
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
=== TEST 3: delete upstream(id: 1)
|
=== TEST 3: delete upstream
|
||||||
--- config
|
--- config
|
||||||
location /t {
|
location /t {
|
||||||
content_by_lua_block {
|
content_by_lua_block {
|
||||||
local t = require("lib.test_admin").test
|
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,
|
ngx.HTTP_DELETE,
|
||||||
nil,
|
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
|
--- config
|
||||||
location /t {
|
location /t {
|
||||||
content_by_lua_block {
|
content_by_lua_block {
|
||||||
local t = require("lib.test_admin").test
|
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,
|
ngx.HTTP_PUT,
|
||||||
[[{
|
[[{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
@ -1936,7 +1937,7 @@ passed
|
|||||||
"create_time": 1602883670,
|
"create_time": 1602883670,
|
||||||
"update_time": 1602893670
|
"update_time": 1602893670
|
||||||
},
|
},
|
||||||
"key": "/apisix/upstreams/1"
|
"key": "/apisix/upstreams/up_create_update_time"
|
||||||
},
|
},
|
||||||
"action": "set"
|
"action": "set"
|
||||||
}]]
|
}]]
|
||||||
@ -1955,12 +1956,12 @@ passed
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
=== TEST 56: delete test upstream(id: 1)
|
=== TEST 56: delete test upstream
|
||||||
--- config
|
--- config
|
||||||
location /t {
|
location /t {
|
||||||
content_by_lua_block {
|
content_by_lua_block {
|
||||||
local t = require("lib.test_admin").test
|
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,
|
ngx.HTTP_DELETE,
|
||||||
nil,
|
nil,
|
||||||
[[{
|
[[{
|
||||||
|
@ -78,7 +78,7 @@ __DATA__
|
|||||||
content_by_lua_block {
|
content_by_lua_block {
|
||||||
local json = require("toolkit.json")
|
local json = require("toolkit.json")
|
||||||
local t = require("lib.test_admin").test
|
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,
|
ngx.HTTP_PUT,
|
||||||
[[{
|
[[{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
@ -101,7 +101,7 @@ __DATA__
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
--- response_body
|
--- 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 {
|
content_by_lua_block {
|
||||||
local json = require("toolkit.json")
|
local json = require("toolkit.json")
|
||||||
local t = require("lib.test_admin").test
|
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,
|
ngx.HTTP_PATCH,
|
||||||
[[{
|
[[{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
@ -134,7 +134,7 @@ __DATA__
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
--- response_body
|
--- 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 {
|
content_by_lua_block {
|
||||||
local json = require("toolkit.json")
|
local json = require("toolkit.json")
|
||||||
local t = require("lib.test_admin").test
|
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
|
ngx.HTTP_GET
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -161,7 +161,7 @@ __DATA__
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
--- response_body
|
--- 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 {
|
content_by_lua_block {
|
||||||
local json = require("toolkit.json")
|
local json = require("toolkit.json")
|
||||||
local t = require("lib.test_admin").test
|
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
|
ngx.HTTP_DELETE
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -186,7 +186,7 @@ __DATA__
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
--- response_body
|
--- 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
|
--- config
|
||||||
location /t {
|
location /t {
|
||||||
content_by_lua_block {
|
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
|
--- config
|
||||||
location /t {
|
location /t {
|
||||||
content_by_lua_block {
|
content_by_lua_block {
|
||||||
@ -371,39 +371,12 @@ qr/host: httpbin.org/
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
=== TEST 16: set route(upstream deleted)
|
=== TEST 16: delete upstream in used
|
||||||
--- 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
|
|
||||||
--- config
|
--- config
|
||||||
location /t {
|
location /t {
|
||||||
content_by_lua_block {
|
content_by_lua_block {
|
||||||
local t = require("lib.test_admin").test
|
local t = require("lib.test_admin").test
|
||||||
|
ngx.sleep(0.5) -- wait for data synced
|
||||||
local code, body = t('/apisix/admin/upstreams/1',
|
local code, body = t('/apisix/admin/upstreams/1',
|
||||||
ngx.HTTP_DELETE
|
ngx.HTTP_DELETE
|
||||||
)
|
)
|
||||||
@ -411,21 +384,13 @@ passed
|
|||||||
if code >= 300 then
|
if code >= 300 then
|
||||||
ngx.status = code
|
ngx.status = code
|
||||||
end
|
end
|
||||||
ngx.say(body)
|
ngx.print(body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--- request
|
--- request
|
||||||
GET /t
|
GET /t
|
||||||
|
--- error_code: 400
|
||||||
--- response_body
|
--- response_body
|
||||||
passed
|
{"error_msg":"can not delete this upstream, route [1] is still using it now"}
|
||||||
--- no_error_log
|
--- no_error_log
|
||||||
[error]
|
[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