tzssangglass commented on PR #8219:
URL: https://github.com/apache/apisix/pull/8219#issuecomment-1311487544

   ```diff
   diff --git apisix/admin/stream_routes.lua apisix/admin/stream_routes.lua
   index 57af650e..5baccb35 100644
   --- apisix/admin/stream_routes.lua
   +++ apisix/admin/stream_routes.lua
   @@ -17,11 +17,11 @@
    local core = require("apisix.core")
    local utils = require("apisix.admin.utils")
    local config_util = require("apisix.core.config_util")
   -local routes = require("apisix.stream.router.ip_port").routes
    local stream_route_checker = 
require("apisix.stream.router.ip_port").stream_route_checker
    local tostring = tostring
    local ngx = ngx
    local table = table
   +local tonumber = tonumber
    
    
    local _M = {
   @@ -169,16 +169,16 @@ function _M.delete(id)
            return 400, {error_msg = "missing stream route id"}
        end
    
   -    local items, _ = routes()
   -    local key = "/stream_routes/" .. id
   -    -- core.log.info("key: ", key)
   -    if items ~= nil then
   +    local status, body = _M.get()
   +    local items = body.list
   +    if tonumber(status) == 200 and #items > 1 then
            local warn_message = check_router_refer(items,id)
            if warn_message ~= nil then
   -            return 400,warn_message
   +            return 400, warn_message
            end
        end
   -
   +    local key = "/stream_routes/" .. id
   +    -- core.log.info("key: ", key)
        local res, err = core.etcd.delete(key)
        if not res then
            core.log.error("failed to delete stream route[", key, "]: ", err)
   diff --git apisix/cli/ngx_tpl.lua apisix/cli/ngx_tpl.lua
   index 514bdd70..fd45d7f8 100644
   --- apisix/cli/ngx_tpl.lua
   +++ apisix/cli/ngx_tpl.lua
   @@ -447,7 +447,6 @@ http {
    
        init_worker_by_lua_block {
            apisix.http_init_worker()
   -        apisix.stream_init_worker()
        }
    
        exit_worker_by_lua_block {
   diff --git t/admin/stream-routes.t t/admin/stream-routes.t
   index d362910b..6480fdef 100644
   --- t/admin/stream-routes.t
   +++ t/admin/stream-routes.t
   @@ -643,14 +643,37 @@ passed
    
    
    === TEST 17:  put reference route +  delete
   +--- stream_enable
    --- extra_yaml_config
    xrpc:
      protocols:
        - name: pingpong
    --- config
   -    location /t {
   +    location /test {
            content_by_lua_block {
                local t = require("lib.test_admin").test
   +            local etcd = require("apisix.core.etcd")
   +            local code, body = t('/apisix/admin/stream_routes/1',
   +                ngx.HTTP_PUT,
   +                [[{
   +                    "remote_addr": "127.0.0.1",
   +                    "desc": "test-desc",
   +                    "upstream": {
   +                        "nodes": {
   +                            "127.0.0.1:8080": 1
   +                        },
   +                        "type": "roundrobin"
   +                    },
   +                    "desc": "new route"
   +                }]]
   +            )
   +            if code > 300 then
   +                ngx.status = code
   +                ngx.print(body)
   +                return
   +            end
   +            ngx.sleep(0.5)
   +
                local code, body = t('/apisix/admin/stream_routes/12',
                    ngx.HTTP_PUT,
                    [[{
   @@ -667,20 +690,21 @@ xrpc:
                            "superior_id": "1"
                        }
                    }]]
   -                )
   +            )
                if code > 300 then
                    ngx.status = code
                    ngx.print(body)
                    return
                end
   +            ngx.sleep(0.5)
    
   -            code2, message = t('/apisix/admin/stream_routes/1', 
ngx.HTTP_DELETE)
   -            ngx.say("[delete] code: ", code2, " message: ", message)
   +            local code2, message = t('/apisix/admin/stream_routes/1', 
ngx.HTTP_DELETE)
   +            ngx.say("code: ", code2, " message: ", message)
            }
        }
    --- request
   -GET /t
   +GET /test
    --- response_body
   -[delete] code: 200 message: passed
   +code: 400 message: /stream_routes/1 is referred by _apisix_stream_routes_12
    --- no_error_log
    [error]
   ```
   
   Here is what I tried to modify, hope to help you.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to