github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/internal/services/integrationtesting/perf_test.go (about)

     1  //go:build ci && docker && !skipintegrationtests
     2  // +build ci,docker,!skipintegrationtests
     3  
     4  package integrationtesting_test
     5  
     6  import (
     7  	"context"
     8  	"slices"
     9  	"sync"
    10  	"testing"
    11  	"time"
    12  
    13  	v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
    14  	"github.com/stretchr/testify/require"
    15  
    16  	"github.com/authzed/spicedb/internal/datastore/spanner"
    17  	tf "github.com/authzed/spicedb/internal/testfixtures"
    18  	"github.com/authzed/spicedb/internal/testserver"
    19  	testdatastore "github.com/authzed/spicedb/internal/testserver/datastore"
    20  	"github.com/authzed/spicedb/internal/testserver/datastore/config"
    21  	dsconfig "github.com/authzed/spicedb/pkg/cmd/datastore"
    22  	"github.com/authzed/spicedb/pkg/datastore"
    23  	"github.com/authzed/spicedb/pkg/tuple"
    24  	"github.com/authzed/spicedb/pkg/zedtoken"
    25  )
    26  
    27  func TestBurst(t *testing.T) {
    28  	blacklist := []string{
    29  		spanner.Engine, // spanner emulator doesn't support parallel transactions
    30  	}
    31  
    32  	for _, engine := range datastore.Engines {
    33  		if slices.Contains(blacklist, engine) {
    34  			continue
    35  		}
    36  		b := testdatastore.RunDatastoreEngine(t, engine)
    37  		t.Run(engine, func(t *testing.T) {
    38  			ds := b.NewDatastore(t, config.DatastoreConfigInitFunc(t,
    39  				dsconfig.WithWatchBufferLength(0),
    40  				dsconfig.WithGCWindow(time.Duration(90_000_000_000_000)),
    41  				dsconfig.WithRevisionQuantization(10),
    42  				dsconfig.WithMaxRetries(50),
    43  				dsconfig.WithRequestHedgingEnabled(false)))
    44  			ds, revision := tf.StandardDatastoreWithData(ds, require.New(t))
    45  
    46  			conns, cleanup := testserver.TestClusterWithDispatch(t, 1, ds)
    47  			t.Cleanup(cleanup)
    48  
    49  			client := v1.NewPermissionsServiceClient(conns[0])
    50  			var wg sync.WaitGroup
    51  			for i := 0; i < 100; i++ {
    52  				rel := tuple.MustToRelationship(tuple.Parse(tf.StandardTuples[i%(len(tf.StandardTuples))]))
    53  				run := make(chan struct{})
    54  				wg.Add(1)
    55  				go func() {
    56  					<-run
    57  					defer wg.Done()
    58  					_, err := client.CheckPermission(context.Background(), &v1.CheckPermissionRequest{
    59  						Consistency: &v1.Consistency{
    60  							Requirement: &v1.Consistency_AtLeastAsFresh{
    61  								AtLeastAsFresh: zedtoken.MustNewFromRevision(revision),
    62  							},
    63  						},
    64  						Resource:   rel.Resource,
    65  						Permission: "viewer",
    66  						Subject:    rel.Subject,
    67  					})
    68  					require.NoError(t, err)
    69  				}()
    70  				run <- struct{}{}
    71  			}
    72  			wg.Wait()
    73  		})
    74  	}
    75  }