Skip to content
This repository was archived by the owner on Feb 20, 2019. It is now read-only.

Commit a705895

Browse files
authored
Merge pull request boltdb#642 from josharian/fix629
Ensure that keys generated by testing/quick are unique
2 parents b9eb643 + 18ced60 commit a705895

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

quick_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,17 @@ func (t testdata) Less(i, j int) bool { return bytes.Compare(t[i].Key, t[j].Key)
5050
func (t testdata) Generate(rand *rand.Rand, size int) reflect.Value {
5151
n := rand.Intn(qmaxitems-1) + 1
5252
items := make(testdata, n)
53+
used := make(map[string]bool)
5354
for i := 0; i < n; i++ {
5455
item := &items[i]
55-
item.Key = randByteSlice(rand, 1, qmaxksize)
56+
// Ensure that keys are unique by looping until we find one that we have not already used.
57+
for {
58+
item.Key = randByteSlice(rand, 1, qmaxksize)
59+
if !used[string(item.Key)] {
60+
used[string(item.Key)] = true
61+
break
62+
}
63+
}
5664
item.Value = randByteSlice(rand, 0, qmaxvsize)
5765
}
5866
return reflect.ValueOf(items)

0 commit comments

Comments
 (0)