File tree Expand file tree Collapse file tree 2 files changed +56
-1
lines changed Expand file tree Collapse file tree 2 files changed +56
-1
lines changed Original file line number Diff line number Diff line change 138138
139139
140140function _M .reinit (self , nodes )
141- self .ids , self .points , self .npoints , self .newnodes = _precompute (nodes )
141+ self .ids , self .points , self .npoints , self .nodes = _precompute (nodes )
142142 self .size = self .npoints
143143end
144144
Original file line number Diff line number Diff line change @@ -286,3 +286,58 @@ diff: 9745
286286--- no_error_log
287287[error]
288288--- timeout: 30
289+
290+
291+
292+ === TEST 5: reinit
293+ --- http_config eval: $::HttpConfig
294+ --- config
295+ location /t {
296+ content_by_lua_block {
297+ local resty_chash = require "resty.chash"
298+
299+ local servers = {
300+ ["server1"] = 10,
301+ ["server2"] = 2,
302+ ["server3"] = 1,
303+ }
304+
305+ local chash = resty_chash:new(servers)
306+
307+ for id, weight in pairs(chash.nodes) do
308+ ngx.say(id, ": ", weight)
309+ end
310+ ngx.say("points number: ", chash.npoints)
311+ ngx.say("size: ", chash.size)
312+
313+ ngx.say("reinit")
314+
315+ local new_servers = {
316+ ["server4"] = 1,
317+ ["server5"] = 2,
318+ }
319+ chash:reinit(new_servers)
320+
321+ for id, weight in pairs(chash.nodes) do
322+ ngx.say(id, ": ", weight)
323+ end
324+ ngx.say("points number: ", chash.npoints)
325+ ngx.say("size: ", chash.size)
326+ }
327+ }
328+ --- request
329+ GET /t
330+ --- response_body
331+ server1: 10
332+ server2: 2
333+ server3: 1
334+ points number: 2080
335+ size: 2080
336+ reinit
337+ server4: 1
338+ server5: 2
339+ points number: 480
340+ size: 480
341+ --- no_error_log
342+ [error]
343+ --- timeout: 30
You can’t perform that action at this time.
0 commit comments