Copilot commented on code in PR #13579:
URL: https://github.com/apache/apisix/pull/13579#discussion_r3449479164


##########
t/plugin/limit-count-redis-cluster.t:
##########
@@ -546,3 +546,78 @@ passed
 ["GET /hello", "GET /hello", "GET /hello", "GET /hello"]
 --- error_code eval
 [200, 200, 503, 503]
+
+
+
+=== TEST 17: set route and flush the cluster script cache
+--- 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",
+                    "plugins": {
+                        "limit-count": {
+                            "count": 9999,
+                            "time_window": 60,
+                            "key": "remote_addr",
+                            "policy": "redis-cluster",
+                            "redis_cluster_nodes": [
+                                "127.0.0.1:5000",
+                                "127.0.0.1:5001"
+                            ],
+                            "redis_cluster_name": "redis-cluster-1"
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1980": 1
+                        },
+                        "type": "roundrobin"
+                    }
+                }]]
+                )
+            if code >= 300 then
+                ngx.status = code
+                ngx.say(body)
+                return
+            end
+
+            -- drop any cached script on every node so the next evalsha 
returns NOSCRIPT
+            local redis = require("resty.redis")
+            local seed = redis:new()
+            seed:set_timeout(1000)
+            local ok, err = seed:connect("127.0.0.1", 5000)
+            if not ok then
+                ngx.say("failed to connect seed: ", err)
+                return
+            end
+            local nodes = seed:cluster("nodes")
+            seed:set_keepalive(10000, 100)
+            for addr in nodes:gmatch("(%d+%.%d+%.%d+%.%d+:%d+)@") do
+                local ip, port = addr:match("([^:]+):(%d+)")
+                local red = redis:new()
+                red:set_timeout(1000)
+                if red:connect(ip, tonumber(port)) then
+                    red:script("flush")
+                    red:set_keepalive(10000, 100)
+                end
+            end

Review Comment:
   `seed:cluster("nodes")` can return `nil, err` (e.g., if the seed node is 
down or CLUSTER is disabled). The current code assumes it always returns a 
string and will throw (`attempt to index a nil value`) at `nodes:gmatch(...)`, 
making the test fail with an unhelpful Lua error instead of a clear message.



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