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 8420a0f  feat: return 502 for upstream not found in the DP (#3050)
8420a0f is described below

commit 8420a0f39d0609f3086c8c01ec19c240baabd8a2
Author: 罗泽轩 <spacewander...@gmail.com>
AuthorDate: Tue Dec 15 18:04:10 2020 +0800

    feat: return 502 for upstream not found in the DP (#3050)
    
    Fix #3035
    
    Signed-off-by: spacewander <spacewander...@gmail.com>
---
 apisix/init.lua   |  2 +-
 t/node/upstream.t | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/apisix/init.lua b/apisix/init.lua
index 6012e52..5a4b075 100644
--- a/apisix/init.lua
+++ b/apisix/init.lua
@@ -432,7 +432,7 @@ function _M.http_access_phase()
             local upstream = upstreams:get(tostring(up_id))
             if not upstream then
                 core.log.error("failed to find upstream by id: " .. up_id)
-                return core.response.exit(500)
+                return core.response.exit(502)
             end
 
             if upstream.has_domain then
diff --git a/t/node/upstream.t b/t/node/upstream.t
index db0cdcb..326cc12 100644
--- a/t/node/upstream.t
+++ b/t/node/upstream.t
@@ -403,3 +403,64 @@ GET /uri
 qr/host: httpbin.org/
 --- no_error_log
 [error]
+
+
+
+=== TEST 17: 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 18: delete upstream
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/upstreams/1',
+                ngx.HTTP_DELETE
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 19: hit route
+--- request
+GET /uri
+--- error_code: 502
+--- error_log
+failed to find upstream by id: 1

Reply via email to