Skip to content

Commit

Permalink
chore: wip add benchmark - flags
Browse files Browse the repository at this point in the history
  • Loading branch information
markphelps committed Jan 31, 2023
1 parent 481bfc4 commit 7e34f9b
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions internal/storage/sql/flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"testing"
"time"

"go.flipt.io/flipt/internal/storage"
Expand Down Expand Up @@ -752,3 +753,47 @@ func (s *DBTestSuite) TestDeleteVariant_NotFound() {

require.NoError(t, err)
}

func BenchmarkListFlags(b *testing.B) {
s := new(DBTestSuite)
t := &testing.T{}
s.SetT(t)
s.SetupSuite()

for i := 0; i < 1000; i++ {
reqs := []*flipt.CreateFlagRequest{
{
Key: uuid.Must(uuid.NewV4()).String(),
Name: fmt.Sprintf("foo_%d", i),
Enabled: true,
},
}

for _, req := range reqs {
f, err := s.store.CreateFlag(context.TODO(), req)
require.NoError(t, err)
assert.NotNil(t, f)

for j := 0; j < 10; j++ {
v, err := s.store.CreateVariant(context.TODO(), &flipt.CreateVariantRequest{
FlagKey: f.Key,
Key: uuid.Must(uuid.NewV4()).String(),
Name: fmt.Sprintf("variant_%d", j),
})

require.NoError(t, err)
assert.NotNil(t, v)
}
}
}

b.ResetTimer()

for i := 0; i < b.N; i++ {
flags, err := s.store.ListFlags(context.TODO())
require.NoError(t, err)
assert.NotEmpty(t, flags)
}

s.TearDownSuite()
}

0 comments on commit 7e34f9b

Please sign in to comment.