zhoujiexiong commented on issue #11421:
URL: https://github.com/apache/apisix/issues/11421#issuecomment-2264689320

   @jagerzhang 
   
   This dynamic way is also behaving like the static.
   You could adjust the priority of the routes to satisfy.
   
   ```
   use t::APISIX 'no_plan';
   
   repeat_each(1);
   no_long_string();
   no_shuffle();
   no_root_location();
   run_tests;
   
   __DATA__
   
   === TEST 1: route_test1 set 1st, pri_test1 > pri_test2; route_test2(set pri 
= 100), pri_test2 > pri_test1
   --- config
       location /t {
           content_by_lua_block {
               local t = require("lib.test_admin").test
               local code, body = t('/apisix/admin/upstreams/test',
                   ngx.HTTP_PUT,
                   [[{
                       "nodes": {
                           "localhost:1980": 1
                       },
                       "type": "roundrobin"
                   }]]
               )
               assert(body == "passed")
               
               local code, body = t('/apisix/admin/services/test',
                   ngx.HTTP_PUT,
                   [[{
                       "upstream_id": "test",
                       "hosts": ["test1.com", "test2.com"]
                   }]]
               )
               assert(body == "passed")
   
               local code, body = t('/apisix/admin/routes/test1',
                   ngx.HTTP_PUT,
                   [[{
                       "uris": ["/111*"],
                       "plugins": {
                           "echo": {
                               "body": "test1"
                           }
                       },
                       "service_id": "test"
                   }]]
               )
               assert(body == "passed")
   
               local code, body = t('/apisix/admin/routes/test2',
                   ngx.HTTP_PUT,
                   [[{
                       "uris": ["/111*"],
                       "hosts": ["test2.com"],
                       "plugins": {
                           "echo": {
                               "body": "test2"
                           }
                       },
                       "upstream_id": "test"
                   }]]
               )
               assert(body == "passed")
               
               local code, body = t('/apisix/admin/routes/test3',
                   ngx.HTTP_PUT,
                   [[{
                       "plugins": {
                           "serverless-pre-function": {
                               "phase": "rewrite",
                               "functions": [
                                   "return function (conf, ctx) 
ngx.say(\"test3\"); ngx.exit(200) end"
                               ]
                           }
                       },
                       "uri": "/111*"
                   }]]
               )
               assert(body == "passed")
   
               ngx.sleep(3)
   
               local http = require "resty.http"
               local httpc = http.new()
               local uri1 = "http://127.0.0.1:"; .. ngx.var.server_port .. "/111"
               local res, err = httpc:request_uri(uri1, { method = "GET", 
headers = { Host = "test2.com" }})
               if err then
                   ngx.log(ngx.ERR, err)
                   ngx.status = res.status
                   return
               end
               ngx.say(res.body)
   
               local code, body = t('/apisix/admin/routes/test2',
                   ngx.HTTP_PUT,
                   [[{
                       "uris": ["/111*"],
                       "hosts": ["test2.com"],
                       "plugins": {
                           "echo": {
                               "body": "test2"
                           }
                       },
                       "priority": 100,
                       "upstream_id": "test"
                   }]]
               )
               assert(body == "passed")
               
               ngx.sleep(3)
   
               local http = require "resty.http"
               local httpc = http.new()
               local uri1 = "http://127.0.0.1:"; .. ngx.var.server_port .. "/111"
               local res, err = httpc:request_uri(uri1, { method = "GET", 
headers = { Host = "test2.com" }})
               if err then
                   ngx.log(ngx.ERR, err)
                   ngx.status = res.status
                   return
               end
               ngx.say(res.body)
           }
       }
   --- request
   GET /t
   --- response_body
   test1
   test2
   --- timeout: 30
   
   ```


-- 
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: notifications-unsubscr...@apisix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to