Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow timer to restart #112

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/skywalking/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ local initialized = false
-- After report instance properties successfully, it sends keep alive packages.
function Client:startBackendTimer(backend_http_uri)
initialized = true
self.stopped = false
local metadata_buffer = ngx.shared.tracing_buffer

-- The codes of timer setup is following the OpenResty timer doc
Expand All @@ -42,6 +43,7 @@ function Client:startBackendTimer(backend_http_uri)

check = function(premature)
if not premature and not self.stopped then
log(ngx.INFO, "running timer")
local instancePropertiesSubmitted = metadata_buffer:get('instancePropertiesSubmitted')
if (instancePropertiesSubmitted == nil or instancePropertiesSubmitted == false) then
self:reportServiceInstance(metadata_buffer, backend_http_uri)
Expand Down
34 changes: 34 additions & 0 deletions t/client.t
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,37 @@ true
--- no_error_log
language: lua
Go keepAlive



=== TEST 3: start backend timer then destory then restart backend timer
--- config
location /t {
content_by_lua_block {
local client = require("skywalking.client")
client.backendTimerDelay = 0.1
client:startBackendTimer("http://127.0.0.1:" .. ngx.var.server_port)
ngx.sleep(0.1)
ngx.say('ok')

local ok, err = client:destroyBackendTimer()
if not err then
ngx.say(ok)
else
ngx.say(err)
end

client:startBackendTimer("http://127.0.0.1:" .. ngx.var.server_port)
ngx.sleep(0.1)
ngx.say('ok')
}
}
--- response_body
ok
true
ok
--- grep_error_log: running timer
--- grep_error_log_out
running timer
running timer
running timer
Loading