You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2021/07/14 02:53:13 UTC
[apisix] branch master updated: test: clean fake upstream API
(#4578)
This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 302073e test: clean fake upstream API (#4578)
302073e is described below
commit 302073ed223bdbe4a09a329fa2bfa2cfe57281e0
Author: 罗泽轩 <sp...@gmail.com>
AuthorDate: Wed Jul 14 10:53:05 2021 +0800
test: clean fake upstream API (#4578)
Signed-off-by: spacewander <sp...@gmail.com>
---
t/core/etcd.t | 4 ++--
t/lib/server.lua | 38 +++++++++++----------------------
t/node/timeout-upstream.t | 8 +++----
t/node/upstream-status-5xx.t | 4 ++--
t/plugin/api-breaker.t | 16 +++++++-------
t/plugin/prometheus.t | 8 +++----
t/router/radixtree-uri-keep-end-slash.t | 3 +--
7 files changed, 34 insertions(+), 47 deletions(-)
diff --git a/t/core/etcd.t b/t/core/etcd.t
index 5a7ac44..8d1bdc9 100644
--- a/t/core/etcd.t
+++ b/t/core/etcd.t
@@ -180,7 +180,7 @@ Host: foo.com
"type": "roundrobin"
},
"host": "foo.com",
- "uri": "/hello_"
+ "uri": "/hello_chunked"
}]],
nil
)
@@ -221,7 +221,7 @@ Host: foo.com
}
--- pipelined_requests eval
["GET /add", "GET /hello", "GET /update", "GET /hello", "GET /status", "GET /delete", "GET /status",
-"GET /add2", "GET /hello_", "GET /update2", "GET /hello_", "GET /hello1", "GET /delete", "GET /hello1"]
+"GET /add2", "GET /hello_chunked", "GET /update2", "GET /hello_chunked", "GET /hello1", "GET /delete", "GET /hello1"]
--- more_headers
Host: foo.com
--- error_code eval
diff --git a/t/lib/server.lua b/t/lib/server.lua
index 9fc6078..0b6079f 100644
--- a/t/lib/server.lua
+++ b/t/lib/server.lua
@@ -52,11 +52,6 @@ function _M.hello1()
end
-function _M.hello_()
- ngx.say("hello world")
-end
-
-
-- Fake endpoint, needed for testing authz-keycloak plugin.
function _M.course_foo()
ngx.say("course foo")
@@ -118,12 +113,6 @@ function _M.status()
end
-function _M.sleep1()
- ngx.sleep(1)
- ngx.say("ok")
-end
-
-
function _M.ewma()
if ngx.var.server_port == "1981"
or ngx.var.server_port == "1982" then
@@ -143,7 +132,6 @@ local builtin_hdr_ignore_list = {
}
function _M.uri()
- -- ngx.sleep(1)
ngx.say("uri: ", ngx.var.uri)
local headers = ngx.req.get_headers()
@@ -164,7 +152,6 @@ _M.uri_plugin_proxy_rewrite_args = _M.uri
function _M.old_uri()
- -- ngx.sleep(1)
ngx.say("uri: ", ngx.var.uri)
local headers = ngx.req.get_headers()
@@ -372,18 +359,6 @@ for i = 1, 100 do
end
-function _M.go()
- local action = string.sub(ngx.var.uri, 2)
- action = string.gsub(action, "[/\\.-]", "_")
- if not action or not _M[action] then
- return ngx.exit(404)
- end
-
- inject_headers()
- return _M[action]()
-end
-
-
function _M.headers()
local args = ngx.req.get_uri_args()
for name, val in pairs(args) do
@@ -434,4 +409,17 @@ function _M._well_known_openid_configuration()
end
+-- Please add your fake upstream above
+function _M.go()
+ local action = string.sub(ngx.var.uri, 2)
+ action = string.gsub(action, "[/\\.-]", "_")
+ if not action or not _M[action] then
+ return ngx.exit(404)
+ end
+
+ inject_headers()
+ return _M[action]()
+end
+
+
return _M
diff --git a/t/node/timeout-upstream.t b/t/node/timeout-upstream.t
index 38a4a90..c860559 100644
--- a/t/node/timeout-upstream.t
+++ b/t/node/timeout-upstream.t
@@ -46,7 +46,7 @@ __DATA__
"read": 0.5
}
},
- "uri": "/sleep1"
+ "uri": "/mysleep"
}]]
)
@@ -67,7 +67,7 @@ passed
=== TEST 2: hit routes (timeout)
--- request
-GET /sleep1
+GET /mysleep?seconds=1
--- error_code: 504
--- response_body eval
qr/504 Gateway Time-out/
@@ -101,7 +101,7 @@ timed out) while reading response header from upstream
"read": 2
}
},
- "uri": "/sleep1"
+ "uri": "/mysleep"
}]]
)
@@ -122,7 +122,7 @@ passed
=== TEST 4: hit routes (timeout)
--- request
-GET /sleep1
+GET /mysleep?seconds=1
--- error_code: 504
--- response_body eval
qr/504 Gateway Time-out/
diff --git a/t/node/upstream-status-5xx.t b/t/node/upstream-status-5xx.t
index c69b5cb..fa6639a 100644
--- a/t/node/upstream-status-5xx.t
+++ b/t/node/upstream-status-5xx.t
@@ -93,7 +93,7 @@ qr/X-APISIX-Upstream-Status: 200/
"read": 0.5
}
},
- "uri": "/sleep1"
+ "uri": "/mysleep"
}]]
)
@@ -114,7 +114,7 @@ passed
=== TEST 4: hit routes (timeout) and $upstream_status is 504
--- request
-GET /sleep1
+GET /mysleep?seconds=1
--- error_code: 504
--- response_body eval
qr/504 Gateway Time-out/
diff --git a/t/plugin/api-breaker.t b/t/plugin/api-breaker.t
index ea38a84..2858f5a 100644
--- a/t/plugin/api-breaker.t
+++ b/t/plugin/api-breaker.t
@@ -516,8 +516,8 @@ GET /api_breaker?code=500
=== TEST 16: unhealthy -> timeout -> normal
--- config
- location /sleep1 {
- proxy_pass "http://127.0.0.1:1980/sleep1";
+ location /mysleep {
+ proxy_pass "http://127.0.0.1:1980/mysleep?seconds=1";
}
--- request eval
[
@@ -526,9 +526,9 @@ GET /api_breaker?code=500
"GET /api_breaker?code=500",
"GET /api_breaker?code=200",
- "GET /sleep1",
- "GET /sleep1",
- "GET /sleep1",
+ "GET /mysleep",
+ "GET /mysleep",
+ "GET /mysleep",
"GET /api_breaker?code=200",
"GET /api_breaker?code=200",
@@ -548,15 +548,15 @@ GET /api_breaker?code=500
=== TEST 17: unhealthy -> timeout -> unhealthy
--- config
-location /sleep1 {
- proxy_pass "http://127.0.0.1:1980/sleep1";
+location /mysleep {
+ proxy_pass "http://127.0.0.1:1980/mysleep?seconds=1";
}
--- request eval
[
"GET /api_breaker?code=500", "GET /api_breaker?code=500",
"GET /api_breaker?code=500", "GET /api_breaker?code=200",
- "GET /sleep1", "GET /sleep1", "GET /sleep1",
+ "GET /mysleep", "GET /mysleep", "GET /mysleep",
"GET /api_breaker?code=500","GET /api_breaker?code=500",
"GET /api_breaker?code=500","GET /api_breaker?code=500"
diff --git a/t/plugin/prometheus.t b/t/plugin/prometheus.t
index 216fcf2..68055f9 100644
--- a/t/plugin/prometheus.t
+++ b/t/plugin/prometheus.t
@@ -572,7 +572,7 @@ passed
-=== TEST 27: add a route 4 to redirect /sleep1
+=== TEST 27: add a route 4 to redirect /mysleep?seconds=1
--- config
location /t {
content_by_lua_block {
@@ -581,7 +581,7 @@ passed
ngx.HTTP_PUT,
[[{
"service_id": 3,
- "uri": "/sleep1"
+ "uri": "/mysleep"
}]]
)
@@ -600,9 +600,9 @@ passed
-=== TEST 28: request from client to /sleep1 ( all hit)
+=== TEST 28: request from client to /mysleep?seconds=1 ( all hit)
--- pipelined_requests eval
-["GET /sleep1", "GET /sleep1", "GET /sleep1"]
+["GET /mysleep?seconds=1", "GET /mysleep?seconds=1", "GET /mysleep?seconds=1"]
--- error_code eval
[200, 200, 200]
--- no_error_log
diff --git a/t/router/radixtree-uri-keep-end-slash.t b/t/router/radixtree-uri-keep-end-slash.t
index 46c9b9c..d51ac07 100644
--- a/t/router/radixtree-uri-keep-end-slash.t
+++ b/t/router/radixtree-uri-keep-end-slash.t
@@ -82,7 +82,6 @@ hello world
--- request
GET /hello/
--- yaml_config eval: $::yaml_config
---- response_body
-hello world
+--- error_code: 404
--- no_error_log
[error]