# Patchwork [3,of,3] test-pathencode: randomize length of each path component

Submitter Siddharth Agarwal June 20, 2013, 3:18 p.m. <33db99344b5c851de53d.1371741494@dev1091.prn1.facebook.com> mbox | patch /patch/1744/ Superseded, archived show

Siddharth Agarwal - June 20, 2013, 3:18 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1371708340 25200
#      Wed Jun 19 23:05:40 2013 -0700
# Node ID 33db99344b5c851de53d4a020ed78e1c134417a3
test-pathencode: randomize length of each path component

This makes it possible for long and short components to exist in the same path.
This also makes shorter path components more likely. For
randint(1, randint(1, n)), the likelihood that one sees a number k
(1 <= k <= n) is 1/n * (\sum_{k=i}^n 1/i). This decreases with k, much like in
the real world where shorter paths are more common than longer ones.

The previous fix and this one together cause issue3958 to be detected by this
test with reasonable frequency. When this test was run 100 times in a loop, the
issue was detected 30 of those times.


## Patch

diff --git a/tests/test-pathencode.py b/tests/test-pathencode.py
--- a/tests/test-pathencode.py
+++ b/tests/test-pathencode.py
@@ -125,7 +125,8 @@
p = pickfrom(rng, firsttable)(rng)
l = len(p)
ps = [p]
-    while l < k:
+    maxl = rng.randint(1, k)
+    while l < maxl:
p = pickfrom(rng, resttable)(rng)
l += len(p)
ps.append(p)