spacewander commented on a change in pull request #6282: URL: https://github.com/apache/apisix/pull/6282#discussion_r816412026
########## File path: t/discovery/nacos2.t ########## @@ -112,3 +112,105 @@ GET /hello --- error_code_like: ^(?:50\d)$ --- error_log nacos login fail + + + +=== TEST 3: same service is registered in route, service and upstream, de-duplicate +--- yaml_config +apisix: + node_listen: 1984 + admin_key: null +--- extra_yaml_config +discovery: + nacos: + host: + - "http://127.0.0.1:8858" + fetch_interval: 1 +--- 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": "/hello", + "upstream": { + "service_name": "APISIX-NACOS", + "discovery_type": "nacos", + "scheme": "http", + "type": "roundrobin", + "discovery_args": { + "namespace_id": "public", + "group_name": "DEFAULT_GROUP" + } + } + }]] + ) + + if code >= 300 then + ngx.status = code + end + + local code, body = t('/apisix/admin/services/1', + ngx.HTTP_PUT, + [[{ + "upstream": { + "type": "roundrobin", + "scheme": "http", + "discovery_type": "nacos", + "pass_host": "pass", + "service_name": "APISIX-NACOS", + "discovery_args": { + "namespace_id": "public", + "group_name": "DEFAULT_GROUP" + } + } + }]] + ) + + if code >= 300 then + ngx.status = code + end + + local code, body = t('/apisix/admin/upstreams/1', + ngx.HTTP_PUT, + [[{ + "type": "roundrobin", + "scheme": "http", + "discovery_type": "nacos", + "pass_host": "pass", + "service_name": "APISIX-NACOS", + "discovery_args": { + "namespace_id": "public", + "group_name": "DEFAULT_GROUP" + } + }]] + ) + + if code >= 300 then + ngx.status = code + end + + ngx.sleep(1.5) + + local json_decode = require("toolkit.json").decode + local http = require "resty.http" + local httpc = http.new() + local dump_uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/v1/discovery/nacos/dump" + local res, err = httpc:request_uri(dump_uri, { method = "GET"}) + if err then + ngx.log(ngx.ERR, err) + ngx.status = res.status + return + end + + local body = json_decode(res.body) + local services = body.services + local service = services["public"]["DEFAULT_GROUP"]["APISIX-NACOS"] + local number = table.getn(service) + ngx.say(number) + } + } +--- response_body +2 Review comment: Should be 1 after deduplicating? -- 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]
