Skip to content

Commit e1567d1

Browse files
committed
Check that we start with roughly equal bucket assignments
1 parent 83310fc commit e1567d1

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

binderhub/tests/test_utils.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ def test_rendezvous_redistribution():
2929
# when one is added
3030
n_keys = 3000
3131

32-
# counnt how many keys were moved and which bucket were they moved from
32+
# count how many keys were moved, which bucket a key started from and
33+
# which bucket a key was moved from (to the new bucket)
3334
n_moved = 0
34-
from_b1 = 0
35-
from_b2 = 0
35+
from_bucket = {"b1": 0, "b2": 0}
36+
start_in = {"b1": 0, "b2": 0}
3637

3738
for i in range(n_keys):
3839
key = f"key-{i}"
3940
two_buckets = utils.rendezvous_rank(["b1", "b2"], key)
41+
start_in[two_buckets[0]] += 1
4042
three_buckets = utils.rendezvous_rank(["b1", "b2", "b3"], key)
4143

4244
if two_buckets[0] != three_buckets[0]:
4345
n_moved += 1
44-
if two_buckets[0] == "b1":
45-
from_b1 += 1
46-
if two_buckets[0] == "b2":
47-
from_b2 += 1
46+
from_bucket[two_buckets[0]] += 1
47+
4848
# should always move to the newly added bucket
4949
assert three_buckets[0] == "b3"
5050

@@ -53,4 +53,8 @@ def test_rendezvous_redistribution():
5353
assert 0.31 < n_moved / n_keys < 0.35
5454
# keys should move from the two original buckets with approximately
5555
# equal probability
56-
assert abs(from_b1 - from_b2) < 10
56+
assert abs(from_bucket["b1"] - from_bucket["b2"]) < 10
57+
58+
# use the standard deviation of the expected number of entries in each
59+
# bucket to get an idea for a reasonable (order of magnitude) difference
60+
assert abs(start_in["b1"] - start_in["b2"]) < (n_keys/2)**0.5

0 commit comments

Comments
 (0)