tzssangglass commented on issue #5767:
URL: https://github.com/apache/apisix/issues/5767#issuecomment-999329326


   As I had difficulty setting up a nacos environment to simulate this test 
(which took me a long time), I opted to hack my way through it.
   
   here's how I hack
   
   ```diff
   diff --git a/apisix/discovery/nacos/init.lua 
b/apisix/discovery/nacos/init.lua
   index d163b395..8e1f71da 100644
   --- a/apisix/discovery/nacos/init.lua
   +++ b/apisix/discovery/nacos/init.lua
   @@ -104,7 +104,10 @@ end
    
    
    local function get_url(request_uri, path)
   -    return request(request_uri, path, nil, 'GET', nil)
   +    local json = 
[[{"name":"DEFAULT_GROUP@@demo1026","groupName":"DEFAULT_GROUP","clusters":"","cacheMillis":10000,"hosts":[{"instanceId":"172.16.11.13#8086#DEFAULT#DEFAULT_GROUP@@demo1026","ip":"127.0.0.1","port":8080,"weight":1.0,"healthy":true,"enabled":true,"ephemeral":true,"clusterName":"DEFAULT","serviceName":"DEFAULT_GROUP@@demo1026","metadata":{"preserved.register.source":"SPRING_CLOUD"},"instanceHeartBeatInterval":5000,"instanceHeartBeatTimeOut":15000,"ipDeleteTimeout":30000}],"lastRefTime":1640069415699,"checksum":"","allIPs":false,"reachProtectionThreshold":false,"valid":true}]]
   +    local data = core.json.decode(json)
   +    return data
   +    --return request(request_uri, path, nil, 'GET', nil)
    end
    
    
   diff --git a/apisix/upstream.lua b/apisix/upstream.lua
   index 4e23fbff..992b218c 100644
   --- a/apisix/upstream.lua
   +++ b/apisix/upstream.lua
   @@ -248,6 +248,7 @@ function _M.set_by_route(route, api_ctx)
                return HTTP_CODE_UPSTREAM_UNAVAILABLE, "no valid upstream node: 
" .. (err or "nil")
            end
    
   +        core.log.warn("upstream.lua return 
nodes:",core.json.delay_encode(new_nodes,true))
            local same = upstream_util.compare_upstream_node(up_conf, new_nodes)
            if not same then
                local pass, err = 
core.schema.check(core.schema.discovery_nodes, new_nodes)
   diff --git a/t/toolkit b/t/toolkit
   index 94f471d3..ab2471cc 160000
   --- a/t/toolkit
   +++ b/t/toolkit
   @@ -1 +1 @@
   -Subproject commit 94f471d3a9045667bc1f1784a21f89315cd64f7e
   +Subproject commit ab2471cc9cbeec6fe605120160eeb9dd17ddda2c
   ```
   
   the error.log as
   
   ```
   2021/12/22 14:43:12 [warn] 51278#8892400: *18 [lua] upstream.lua:251: 
set_upstream(): upstream.lua return 
nodes:[{"weight":1,"port":8080,"host":"127.0.0.1"}], client: 127.0.0.1, server: 
localhost, request: "GET /hello HTTP/1.1", host: "localhost"
   ```
   
   my test case is 
   
   ```
   use t::APISIX 'no_plan';
   
   repeat_each(1);
   log_level('info');
   no_root_location();
   no_shuffle();
   workers(4);
   
   our $yaml_config = <<_EOC_;
   apisix:
     node_listen: 1984
     config_center: yaml
     enable_admin: false
   discovery:
     nacos:
         host:
           - "http://127.0.0.1:8848";
         prefix: "/nacos/v1/"
         fetch_interval: 1
         weight: 1
         timeout:
           connect: 2000
           send: 2000
           read: 5000
   
   _EOC_
   
   our $yaml_auth_config = <<_EOC_;
   apisix:
     node_listen: 1984
     config_center: yaml
     enable_admin: false
   discovery:
     nacos:
         host:
           - "http://nacos:nacos\@127.0.0.1:8848";
         prefix: "/nacos/v1/"
         fetch_interval: 1
         weight: 1
         timeout:
           connect: 2000
           send: 2000
           read: 5000
   
   _EOC_
   
   run_tests();
   
   __DATA__
   
   === TEST 1: get APISIX-NACOS info from NACOS - no auth
   --- yaml_config eval: $::yaml_config
   --- apisix_yaml
   routes:
     -
       uri: /hello
       upstream:
         service_name: demo1026
         discovery_type: nacos
         type: roundrobin
   #END
   --- pipelined_requests eval
   [
       "GET /hello",
       "GET /hello",
   ]
   --- response_body_like eval
   [
       qr/server [1-2]/,
       qr/server [1-2]/,
   ]
   --- no_error_log
   [error, error]
   ```


-- 
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