Firstsawyou commented on a change in pull request #2596:
URL: https://github.com/apache/apisix/pull/2596#discussion_r518128204



##########
File path: t/plugin/log-rotate.t
##########
@@ -95,11 +95,89 @@ GET /t
             ngx.say("done")
         }
     }
---- request
-GET /t
 --- response_body
 done
 --- no_error_log
 [error]
 --- error_log
 start xxxxxx
+
+
+
+=== TEST 3: fix: ensure only one timer is running
+--- config
+    location /t {
+        content_by_lua_block {
+            ngx.sleep(0.5)
+            local t = require("lib.test_admin").test
+            local code, _, org_body = t('/apisix/admin/plugins/reload',
+                                        ngx.HTTP_PUT)

Review comment:
       For me, I think this line of code is not very long, we can write it on 
the same line, so it looks clearer. What do you think?

##########
File path: t/plugin/log-rotate.t
##########
@@ -95,11 +95,89 @@ GET /t
             ngx.say("done")
         }
     }
---- request
-GET /t
 --- response_body
 done
 --- no_error_log
 [error]
 --- error_log
 start xxxxxx
+
+
+
+=== TEST 3: fix: ensure only one timer is running
+--- config
+    location /t {
+        content_by_lua_block {
+            ngx.sleep(0.5)
+            local t = require("lib.test_admin").test
+            local code, _, org_body = t('/apisix/admin/plugins/reload',
+                                        ngx.HTTP_PUT)
+
+            ngx.status = code
+            ngx.say(org_body)
+
+            ngx.sleep(1)
+
+            local lfs = require("lfs")
+            for file_name in lfs.dir(ngx.config.prefix() .. "/logs/") do
+                if string.match(file_name, "__error.log$") then
+                    local f = assert(io.open(ngx.config.prefix() .. "/logs/" 
.. file_name, "r"))
+                    local content = f:read("*all")
+                    f:close()
+                    local counter = 0
+                    ngx.re.gsub(content, [=[run timer\[plugin#log-rotate\]]=], 
function()
+                        counter = counter + 1
+                        return ""
+                    end)
+
+                    if counter ~= 1 then
+                        ngx.say("not a single rotater run at the same time: ", 
file_name)
+                    end
+                end
+            end
+        }
+    }
+--- response_body
+done
+--- no_error_log
+[error]
+
+
+
+=== TEST 4: disable log-rotate via hot reload
+--- config
+    location /t {
+        content_by_lua_block {
+            local data = [[
+apisix:
+  node_listen: 1984
+  admin_key: null
+plugins:
+  - prometheus
+            ]]
+            require("lib.test_admin").set_config_yaml(data)
+            local t = require("lib.test_admin").test
+            local code, _, org_body = t('/apisix/admin/plugins/reload',
+                                        ngx.HTTP_PUT)

Review comment:
       ditto.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to