membphis commented on issue #11774:
URL: https://github.com/apache/apisix/issues/11774#issuecomment-2803876982

   I make a try with the latest APISIX: 
https://github.com/apache/apisix/commit/a8519524e16cbb5b32fe3f6e20978d2fdf08f07a
   
   Tried to bind the `limit-count` to route or global rule, all are fine.
   
   ```
   $ prove t/plugin/limit-count-redis-*-consumer.t
   t/plugin/limit-count-redis-route-consumer.t ... ok
   t/plugin/limit-count-redis-global-consumer.t .. ok
   All tests successful.
   Files=2, Tests=26,  3 wallclock secs ( 0.01 usr  0.01 sys +  0.58 cusr  0.26 
csys =  0.86 CPU)
   Result: PASS
   ```
   
   We need more information to reproduce your issue, waiting for @jeremy1392 's 
response ^_^
   
   # enable plugin limit-count on route
   
   Test results: There is no problem with this case, it runs normally without 
any errors.
   
   Here are the steps:
   
   ```perl
   # t/plugin/limit-count-redis-route-consumer.t
   BEGIN {
       if ($ENV{TEST_NGINX_CHECK_LEAK}) {
           $SkipReason = "unavailable for the hup tests";
   
       } else {
           $ENV{TEST_NGINX_USE_HUP} = 1;
           undef $ENV{TEST_NGINX_USE_STAP};
       }
   }
   
   use t::APISIX 'no_plan';
   
   repeat_each(1);
   no_long_string();
   no_shuffle();
   no_root_location();
   
   add_block_preprocessor(sub {
       my ($block) = @_;
   
       if (!$block->request) {
           $block->set_value("request", "GET /t");
       }
   
       if (!$block->error_log && !$block->no_error_log) {
           $block->set_value("no_error_log", "[error]\n[alert]");
       }
   });
   
   run_tests;
   
   __DATA__
   
   
   === TEST 1: add consumer with username
   --- config
       location /t {
           content_by_lua_block {
               local t = require("lib.test_admin").test
               local code, body = t('/apisix/admin/consumers',
                   ngx.HTTP_PUT,
                   [[{
                       "username": "jack",
                       "plugins": {
                           "key-auth": {
                               "key": "auth-one"
                           }
                       }
                   }]]
                   )
   
               if code >= 300 then
                   ngx.status = code
               end
               ngx.say(body)
           }
       }
   --- response_body
   passed
   
   
   === TEST 2: set route, with redis host and port
   --- 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": 1,
                               "time_window": 5,
                               "rejected_code": 503,
                               "key_type": "var",
                               "key": "consumer_name",
                               "allow_degradation": false,
                               "show_limit_quota_header": true,
                               "policy": "redis",
                               "redis_host": "127.0.0.1",
                               "redis_port": 6379,
                               "redis_timeout": 1001
                           },
                           "key-auth": {}
                       },
                       "upstream": {
                           "nodes": {
                               "127.0.0.1:1980": 1
                           },
                           "type": "roundrobin"
                       }
                   }]]
                   )
   
               if code >= 300 then
                   ngx.status = code
               end
               ngx.say(body)
           }
       }
   --- response_body
   passed
   
   
   
   === TEST 3: up the limit
   --- request
   GET /hello
   --- more_headers
   apikey: auth-one
   --- error_log
   try to lock with key route&consumer#1&jack#redis
   unlock with key route&consumer#1&jack#redis
   
   ```
   
   # enable plugin limit-count on global_rule
   
   Test results: There is no problem with this case, it runs normally without 
any errors.
   
   Here are the steps:
   
   ```perl
   # t/plugin/limit-count-redis-global-consumer.t
   
   BEGIN {
       if ($ENV{TEST_NGINX_CHECK_LEAK}) {
           $SkipReason = "unavailable for the hup tests";
   
       } else {
           $ENV{TEST_NGINX_USE_HUP} = 1;
           undef $ENV{TEST_NGINX_USE_STAP};
       }
   }
   
   use t::APISIX 'no_plan';
   
   repeat_each(1);
   no_long_string();
   no_shuffle();
   no_root_location();
   
   add_block_preprocessor(sub {
       my ($block) = @_;
   
       if (!$block->request) {
           $block->set_value("request", "GET /t");
       }
   
       if (!$block->error_log && !$block->no_error_log) {
           $block->set_value("no_error_log", "[error]\n[alert]");
       }
   });
   
   run_tests;
   
   __DATA__
   
   
   === TEST 1: add consumer with username
   --- config
       location /t {
           content_by_lua_block {
               local t = require("lib.test_admin").test
               local code, body = t('/apisix/admin/consumers',
                   ngx.HTTP_PUT,
                   [[{
                       "username": "jack",
                       "plugins": {
                           "key-auth": {
                               "key": "auth-one"
                           }
                       }
                   }]]
                   )
   
               if code >= 300 then
                   ngx.status = code
               end
               ngx.say(body)
           }
       }
   --- response_body
   passed
   
   
   
   === TEST 2: set global rule, with redis host and port
   --- config
       location /t {
           content_by_lua_block {
               local t = require("lib.test_admin").test
               local code, body = t('/apisix/admin/global_rules/1',
                   ngx.HTTP_PUT,
                   [[{
                       "plugins": {
                           "limit-count": {
                               "count": 2,
                               "time_window": 5,
                               "rejected_code": 503,
                               "key_type": "var",
                               "key": "consumer_name",
                               "policy": "redis",
                               "redis_host": "127.0.0.1",
                               "redis_port": 6379,
                               "redis_timeout": 1001
                           }
                       }
                   }]]
                   )
   
               if code >= 300 then
                   ngx.status = code
               end
               ngx.say(body)
           }
       }
   --- response_body
   passed
   
   
   
   === TEST 3: set route, with redis host and port
   --- 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": {
                           "key-auth": {}
                       },
                       "upstream": {
                           "nodes": {
                               "127.0.0.1:1980": 1
                           },
                           "type": "roundrobin"
                       }
                   }]]
                   )
   
               if code >= 300 then
                   ngx.status = code
               end
               ngx.say(body)
           }
       }
   --- response_body
   passed
   
   
   
   === TEST 4: up the limit
   --- request
   GET /hello
   --- more_headers
   apikey: auth-one
   --- error_log
   try to lock with key global_rule#1#redis
   unlock with key global_rule#1#redis
   ```


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