Skip to content

Commit d4df563

Browse files
craig[bot]navsetlur
andcommitted
Merge #128618
128618: roachtest: Fix random node selection logic in LDR Network Partition test r=renatolabs a=navsetlur There was an edge case with selecting random nodes that would cause it to occasionally spin forever. Logic is fixed now. Release note: none Fixes: #128444 Co-authored-by: Naveen Setlur <naveen.setlur@cockroachlabs.com>
2 parents 769d76a + c216d27 commit d4df563

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

pkg/cmd/roachtest/option/node_list_option.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,9 @@ func (n NodeListOption) SeededRandList(rand *rand.Rand, size int) (NodeListOptio
8383
return NodeListOption{}, fmt.Errorf("cannot select list - size: %d > len: %d", size, len(n))
8484
}
8585

86-
nodes := make(map[int]struct{}, size)
87-
for range size {
88-
node := n[rand.Intn(len(n))]
89-
for _, ok := nodes[node]; ok; {
90-
node = n[rand.Intn(len(n))]
91-
}
92-
nodes[node] = struct{}{}
93-
}
94-
95-
result := make(NodeListOption, 0, size)
96-
for node := range nodes {
97-
result = append(result, node)
98-
}
99-
return result, nil
86+
nodes := append([]int{}, n...)
87+
rand.Shuffle(len(nodes), func(i, j int) { nodes[i], nodes[j] = nodes[j], nodes[i] })
88+
return nodes[:size], nil
10089
}
10190

10291
// NodeIDsString returns the nodes in the NodeListOption, separated by spaces.

0 commit comments

Comments
 (0)