Software / code / prosody
Comparison
spec/util_hashring_spec.lua @ 12802:4a8740e01813
Merge 0.12->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Mon, 12 Dec 2022 07:10:54 +0100 |
| parent | 12795:87424cbedc55 |
comparison
equal
deleted
inserted
replaced
| 12801:ebd6b4d8bf04 | 12802:4a8740e01813 |
|---|---|
| 1 local hashring = require "util.hashring"; | 1 local hashring = require "util.hashring"; |
| 2 | 2 |
| 3 describe("util.hashring", function () | 3 describe("util.hashring", function () |
| 4 randomize(false); | |
| 4 | 5 |
| 5 local sha256 = require "util.hashes".sha256; | 6 local sha256 = require "util.hashes".sha256; |
| 6 | 7 |
| 7 local ring = hashring.new(128, sha256); | 8 local ring = hashring.new(128, sha256); |
| 8 | 9 |
| 80 for i = 1, 100 do | 81 for i = 1, 100 do |
| 81 assert.is_equal("node1", ring:get_node(tostring(i))) | 82 assert.is_equal("node1", ring:get_node(tostring(i))) |
| 82 end | 83 end |
| 83 end); | 84 end); |
| 84 | 85 |
| 86 it("should support values associated with nodes", function () | |
| 87 local r = hashring.new(128, sha256); | |
| 88 r:add_node("node1", { a = 1 }); | |
| 89 local node, value = r:get_node("foo"); | |
| 90 assert.is_equal("node1", node); | |
| 91 assert.same({ a = 1 }, value); | |
| 92 end); | |
| 85 end); | 93 end); |