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

bugfix: fix a typo in chash.reinit #25

Merged
merged 2 commits into from
Feb 25, 2019
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: 1 addition & 1 deletion lib/resty/chash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ end


function _M.reinit(self, nodes)
self.ids, self.points, self.npoints, self.newnodes = _precompute(nodes)
self.ids, self.points, self.npoints, self.nodes = _precompute(nodes)
self.size = self.npoints
end

Expand Down
55 changes: 55 additions & 0 deletions t/chash.t
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,58 @@ diff: 9745
--- no_error_log
[error]
--- timeout: 30



=== TEST 5: reinit
--- http_config eval: $::HttpConfig
--- config
location /t {
content_by_lua_block {
local resty_chash = require "resty.chash"

local servers = {
["server1"] = 10,
["server2"] = 2,
["server3"] = 1,
}

local chash = resty_chash:new(servers)

for id, weight in pairs(chash.nodes) do
ngx.say(id, ": ", weight)
end
ngx.say("points number: ", chash.npoints)
ngx.say("size: ", chash.size)

ngx.say("reinit")

local new_servers = {
["server4"] = 1,
["server5"] = 2,
}
chash:reinit(new_servers)

for id, weight in pairs(chash.nodes) do
ngx.say(id, ": ", weight)
end
ngx.say("points number: ", chash.npoints)
ngx.say("size: ", chash.size)
}
}
--- request
GET /t
--- response_body
server1: 10
server2: 2
server3: 1
points number: 2080
size: 2080
reinit
server4: 1
server5: 2
points number: 480
size: 480
--- no_error_log
[error]
--- timeout: 30