Skip to content

Commit

Permalink
Ensure that keys generated by testing/quick are unique
Browse files Browse the repository at this point in the history
Quick seed 21691 used to generate duplicate keys, 
which caused some Puts of values to overwrite other values,
causing spurious test failures.

Fixes boltdb#629.
  • Loading branch information
josharian committed Dec 28, 2016
1 parent b9eb643 commit 18ced60
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion quick_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,17 @@ func (t testdata) Less(i, j int) bool { return bytes.Compare(t[i].Key, t[j].Key)
func (t testdata) Generate(rand *rand.Rand, size int) reflect.Value {
n := rand.Intn(qmaxitems-1) + 1
items := make(testdata, n)
used := make(map[string]bool)
for i := 0; i < n; i++ {
item := &items[i]
item.Key = randByteSlice(rand, 1, qmaxksize)
// Ensure that keys are unique by looping until we find one that we have not already used.
for {
item.Key = randByteSlice(rand, 1, qmaxksize)
if !used[string(item.Key)] {
used[string(item.Key)] = true
break
}
}
item.Value = randByteSlice(rand, 0, qmaxvsize)
}
return reflect.ValueOf(items)
Expand Down

0 comments on commit 18ced60

Please sign in to comment.