Skip to content

Commit

Permalink
Test Integration: Fix flaky secret & state fuzz tests (dapr#7619)
Browse files Browse the repository at this point in the history
The current fuzz generator for the state and secret fuzz Component names
can sometimes produce invalid names, making those tests flaky.

Update name generation to always output a valid name.

Signed-off-by: joshvanl <[email protected]>
Co-authored-by: Dapr Bot <[email protected]>
  • Loading branch information
JoshVanL and dapr-bot authored Apr 18, 2024
1 parent 2ce5d5d commit 014c171
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 24 deletions.
17 changes: 1 addition & 16 deletions tests/integration/suite/daprd/secret/http/fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ import (
"net/http"
"net/url"
"os"
"regexp"
"strings"
"testing"
"time"

fuzz "github.com/google/gofuzz"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/api/validation/path"

"github.com/dapr/dapr/tests/integration/framework"
procdaprd "github.com/dapr/dapr/tests/integration/framework/process/daprd"
Expand All @@ -54,21 +52,8 @@ type fuzzsecret struct {
func (f *fuzzsecret) Setup(t *testing.T) []framework.Option {
const numTests = 1000

reg, err := regexp.Compile("^([a-zA-Z].*)$")
require.NoError(t, err)

takenNames := make(map[string]bool)
fz := fuzz.New().Funcs(func(s *string, c fuzz.Continue) {
for *s == "" ||
takenNames[*s] ||
len(path.IsValidPathSegmentName(*s)) > 0 ||
!reg.MatchString(*s) ||
*s == "." {
*s = c.RandString()
}
takenNames[*s] = true
})
fz.Fuzz(&f.secretStoreName)
f.secretStoreName = util.RandomString(t, 10)

f.values = make(map[string]string)
for i := 0; i < numTests; i++ {
Expand Down
5 changes: 1 addition & 4 deletions tests/integration/suite/daprd/state/grpc/fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ func (f *fuzzstate) Setup(t *testing.T) []framework.Option {
},
}

for f.storeName == "" ||
len(path.IsValidPathSegmentName(f.storeName)) > 0 {
fuzz.New().Fuzz(&f.storeName)
}
f.storeName = util.RandomString(t, 10)

f.daprd = procdaprd.New(t, procdaprd.WithResourceFiles(fmt.Sprintf(`
apiVersion: dapr.io/v1alpha1
Expand Down
5 changes: 1 addition & 4 deletions tests/integration/suite/daprd/state/http/fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@ func (f *fuzzstate) Setup(t *testing.T) []framework.Option {
},
}

for f.storeName == "" ||
len(path.IsValidPathSegmentName(f.storeName)) > 0 {
fuzz.New().Fuzz(&f.storeName)
}
f.storeName = util.RandomString(t, 10)

f.daprd = procdaprd.New(t, procdaprd.WithResourceFiles(fmt.Sprintf(`
apiVersion: dapr.io/v1alpha1
Expand Down

0 comments on commit 014c171

Please sign in to comment.