Merge pull request #15851 from serathius/robustness-generic

tests/robustness: Make weighted pick random generic
dependabot/go_modules/github.com/prometheus/procfs-0.11.0
Marek Siarkowicz 2023-05-09 10:36:11 +02:00 committed by GitHub
commit f6161673af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 26 deletions

View File

@ -45,14 +45,14 @@ var (
keyCount: 10,
leaseTTL: DefaultLeaseTTL,
largePutSize: 32769,
writeChoices: []choiceWeight{
{choice: string(Put), weight: 45},
{choice: string(LargePut), weight: 5},
{choice: string(Delete), weight: 10},
{choice: string(MultiOpTxn), weight: 10},
{choice: string(PutWithLease), weight: 10},
{choice: string(LeaseRevoke), weight: 10},
{choice: string(CompareAndSet), weight: 10},
writeChoices: []choiceWeight[etcdRequestType]{
{choice: Put, weight: 45},
{choice: LargePut, weight: 5},
{choice: Delete, weight: 10},
{choice: MultiOpTxn, weight: 10},
{choice: PutWithLease, weight: 10},
{choice: LeaseRevoke, weight: 10},
{choice: CompareAndSet, weight: 10},
},
},
}
@ -66,10 +66,10 @@ var (
keyCount: 10,
largePutSize: 32769,
leaseTTL: DefaultLeaseTTL,
writeChoices: []choiceWeight{
{choice: string(Put), weight: 85},
{choice: string(MultiOpTxn), weight: 10},
{choice: string(LargePut), weight: 5},
writeChoices: []choiceWeight[etcdRequestType]{
{choice: Put, weight: 85},
{choice: MultiOpTxn, weight: 10},
{choice: LargePut, weight: 5},
},
},
}
@ -82,10 +82,10 @@ var (
averageKeyCount: 5,
resource: "pods",
namespace: "default",
writeChoices: []choiceWeight{
{choice: string(KubernetesUpdate), weight: 75},
{choice: string(KubernetesDelete), weight: 15},
{choice: string(KubernetesCreate), weight: 10},
writeChoices: []choiceWeight[KubernetesRequestType]{
{choice: KubernetesUpdate, weight: 75},
{choice: KubernetesDelete, weight: 15},
{choice: KubernetesCreate, weight: 10},
},
},
}
@ -99,9 +99,9 @@ var (
keyCount: 10,
largePutSize: 8196,
leaseTTL: DefaultLeaseTTL,
writeChoices: []choiceWeight{
{choice: string(Put), weight: 95},
{choice: string(LargePut), weight: 5},
writeChoices: []choiceWeight[etcdRequestType]{
{choice: Put, weight: 95},
{choice: LargePut, weight: 5},
},
},
}

View File

@ -110,7 +110,7 @@ type Traffic interface {
type etcdTraffic struct {
keyCount int
writeChoices []choiceWeight
writeChoices []choiceWeight[etcdRequestType]
leaseTTL int64
largePutSize int
}
@ -132,7 +132,7 @@ type kubernetesTraffic struct {
averageKeyCount int
resource string
namespace string
writeChoices []choiceWeight
writeChoices []choiceWeight[KubernetesRequestType]
}
type KubernetesRequestType string
@ -174,7 +174,7 @@ func (t kubernetesTraffic) Write(ctx context.Context, c *recordingClient, ids id
if len(objects) > t.averageKeyCount*3/2 {
err = t.Delete(writeCtx, c, string(randomPod.Key), randomPod.ModRevision)
} else {
op := KubernetesRequestType(pickRandom(t.writeChoices))
op := pickRandom(t.writeChoices)
switch op {
case KubernetesDelete:
err = t.Delete(writeCtx, c, string(randomPod.Key), randomPod.ModRevision)
@ -256,7 +256,7 @@ func (t etcdTraffic) Write(ctx context.Context, c *recordingClient, limiter *rat
writeCtx, cancel := context.WithTimeout(ctx, RequestTimeout)
var err error
switch etcdRequestType(pickRandom(t.writeChoices)) {
switch pickRandom(t.writeChoices) {
case Put:
err = c.Put(writeCtx, key, fmt.Sprintf("%d", id.RequestId()))
case LargePut:
@ -356,12 +356,12 @@ func randString(size int) string {
return data.String()
}
type choiceWeight struct {
choice string
type choiceWeight[T any] struct {
choice T
weight int
}
func pickRandom(choices []choiceWeight) string {
func pickRandom[T any](choices []choiceWeight[T]) T {
sum := 0
for _, op := range choices {
sum += op.weight