track anon uploads
This commit is contained in:
parent
36e5cbbdd5
commit
b88cdf6d76
|
@ -51,7 +51,7 @@ function _M.track_upload(skylink, status_code, auth_headers)
|
||||||
local has_auth_headers = not utils.is_table_empty(auth_headers)
|
local has_auth_headers = not utils.is_table_empty(auth_headers)
|
||||||
local status_success = status_code >= 200 and status_code <= 299
|
local status_success = status_code >= 200 and status_code <= 299
|
||||||
|
|
||||||
if skylink and status_success and has_auth_headers then
|
if skylink and status_success then
|
||||||
local ok, err = ngx.timer.at(0, _M.track_upload_timer, skylink, auth_headers)
|
local ok, err = ngx.timer.at(0, _M.track_upload_timer, skylink, auth_headers)
|
||||||
if not ok then ngx.log(ngx.ERR, "Failed to create timer: ", err) end
|
if not ok then ngx.log(ngx.ERR, "Failed to create timer: ", err) end
|
||||||
end
|
end
|
||||||
|
|
|
@ -231,12 +231,17 @@ describe("track_upload", function()
|
||||||
assert.stub(ngx.timer.at).was_not_called()
|
assert.stub(ngx.timer.at).was_not_called()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("should not schedule a timer if auth headers are empty", function()
|
it("should schedule a timer if auth headers are empty", function()
|
||||||
ngx.timer.at.invokes(function() return true, nil end)
|
ngx.timer.at.invokes(function() return true, nil end)
|
||||||
|
|
||||||
skynet_tracker.track_upload(valid_skylink, valid_status_code, {})
|
skynet_tracker.track_upload(valid_skylink, valid_status_code, {})
|
||||||
|
|
||||||
assert.stub(ngx.timer.at).was_not_called()
|
assert.stub(ngx.timer.at).was_called_with(
|
||||||
|
0,
|
||||||
|
skynet_tracker.track_upload_timer,
|
||||||
|
valid_skylink,
|
||||||
|
{}
|
||||||
|
)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("should log an error if timer failed to create", function()
|
it("should log an error if timer failed to create", function()
|
||||||
|
|
Reference in New Issue