Skip to content

Commit b47ef2c

Browse files
committed
make unit tests faster
by enabling parallel tests. Made unit tests run 30% faster Also added some parallelism to Datastore tests, but opt-in. MemDB and datastore proxy tests are now parallel. Also changed CRDB test entry points to run in parallel, since the introduction of integrity tests meant double the tests to run, and sequentially
1 parent 6710269 commit b47ef2c

32 files changed

+264
-146
lines changed

internal/datastore/crdb/crdb_test.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func (cds *crdbDatastore) ExampleRetryableError() error {
5454
}
5555

5656
func TestCRDBDatastoreWithoutIntegrity(t *testing.T) {
57+
t.Parallel()
5758
b := testdatastore.RunCRDBForTesting(t, "")
5859
test.All(t, test.DatastoreTesterFunc(func(revisionQuantization, gcInterval, gcWindow time.Duration, watchBufferLength uint16) (datastore.Datastore, error) {
5960
ctx := context.Background()
@@ -72,10 +73,11 @@ func TestCRDBDatastoreWithoutIntegrity(t *testing.T) {
7273
})
7374

7475
return ds, nil
75-
}))
76+
}), false)
7677
}
7778

7879
func TestCRDBDatastoreWithFollowerReads(t *testing.T) {
80+
t.Parallel()
7981
followerReadDelay := time.Duration(4.8 * float64(time.Second))
8082
gcWindow := 100 * time.Second
8183

@@ -136,6 +138,7 @@ var defaultKeyForTesting = proxy.KeyConfig{
136138
}
137139

138140
func TestCRDBDatastoreWithIntegrity(t *testing.T) {
141+
t.Parallel()
139142
b := testdatastore.RunCRDBForTesting(t, "")
140143

141144
test.All(t, test.DatastoreTesterFunc(func(revisionQuantization, gcInterval, gcWindow time.Duration, watchBufferLength uint16) (datastore.Datastore, error) {
@@ -159,7 +162,7 @@ func TestCRDBDatastoreWithIntegrity(t *testing.T) {
159162
})
160163

161164
return ds, nil
162-
}))
165+
}), false)
163166

164167
unwrappedTester := test.DatastoreTesterFunc(func(revisionQuantization, gcInterval, gcWindow time.Duration, watchBufferLength uint16) (datastore.Datastore, error) {
165168
ctx := context.Background()
@@ -187,6 +190,7 @@ func TestCRDBDatastoreWithIntegrity(t *testing.T) {
187190
}
188191

189192
func TestWatchFeatureDetection(t *testing.T) {
193+
t.Parallel()
190194
pool, err := dockertest.NewPool("")
191195
require.NoError(t, err)
192196
cases := []struct {
@@ -229,7 +233,9 @@ func TestWatchFeatureDetection(t *testing.T) {
229233
},
230234
}
231235
for _, tt := range cases {
236+
tt := tt
232237
t.Run(tt.name, func(t *testing.T) {
238+
t.Parallel()
233239
ctx, cancel := context.WithCancel(context.Background())
234240
t.Cleanup(cancel)
235241
adminConn, connStrings := newCRDBWithUser(t, pool)

internal/datastore/memdb/memdb_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ func (mdbt memDBTest) New(revisionQuantization, _, gcWindow time.Duration, watch
2626
}
2727

2828
func TestMemdbDatastore(t *testing.T) {
29-
test.All(t, memDBTest{})
29+
t.Parallel()
30+
test.All(t, memDBTest{}, true)
3031
}
3132

3233
func TestConcurrentWritePanic(t *testing.T) {
34+
t.Parallel()
3335
require := require.New(t)
3436

3537
ds, err := NewMemdbDatastore(0, 1*time.Hour, 1*time.Hour)
@@ -81,6 +83,7 @@ func TestConcurrentWritePanic(t *testing.T) {
8183
}
8284

8385
func TestConcurrentWriteRelsError(t *testing.T) {
86+
t.Parallel()
8487
require := require.New(t)
8588

8689
ds, err := NewMemdbDatastore(0, 1*time.Hour, 1*time.Hour)

internal/datastore/mysql/datastore_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,16 @@ func createDatastoreTest(b testdatastore.RunningEngineForTest, tf datastoreTestF
9393
}
9494

9595
func TestMySQLDatastoreDSNWithoutParseTime(t *testing.T) {
96+
t.Parallel()
9697
_, err := NewMySQLDatastore(context.Background(), "root:password@(localhost:1234)/mysql")
9798
require.ErrorContains(t, err, "https://spicedb.dev/d/parse-time-mysql")
9899
}
99100

100101
func TestMySQL8Datastore(t *testing.T) {
102+
t.Parallel()
101103
b := testdatastore.RunMySQLForTestingWithOptions(t, testdatastore.MySQLTesterOptions{MigrateForNewDatastore: true}, "")
102104
dst := datastoreTester{b: b, t: t}
103-
test.AllWithExceptions(t, test.DatastoreTesterFunc(dst.createDatastore), test.WithCategories(test.WatchSchemaCategory, test.WatchCheckpointsCategory))
105+
test.AllWithExceptions(t, test.DatastoreTesterFunc(dst.createDatastore), test.WithCategories(test.WatchSchemaCategory, test.WatchCheckpointsCategory), true)
104106
additionalMySQLTests(t, b)
105107
}
106108

@@ -660,6 +662,7 @@ func TransactionTimestampsTest(t *testing.T, ds datastore.Datastore) {
660662
}
661663

662664
func TestMySQLMigrations(t *testing.T) {
665+
t.Parallel()
663666
req := require.New(t)
664667

665668
db := datastoreDB(t, false)
@@ -681,6 +684,7 @@ func TestMySQLMigrations(t *testing.T) {
681684
}
682685

683686
func TestMySQLMigrationsWithPrefix(t *testing.T) {
687+
t.Parallel()
684688
req := require.New(t)
685689

686690
prefix := "spicedb_"

internal/datastore/mysql/migrations/driver.go

-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
sq "github.com/Masterminds/squirrel"
1717
sqlDriver "github.com/go-sql-driver/mysql"
1818

19-
log "github.com/authzed/spicedb/internal/logging"
2019
"github.com/authzed/spicedb/pkg/migrate"
2120
)
2221

@@ -57,10 +56,6 @@ func NewMySQLDriverFromDSN(url string, tablePrefix string, credentialsProvider d
5756
}
5857

5958
db := sql.OpenDB(connector)
60-
err = sqlDriver.SetLogger(&log.Logger)
61-
if err != nil {
62-
return nil, fmt.Errorf("unable to set logging to mysql driver: %w", err)
63-
}
6459
return NewMySQLDriverFromDB(db, tablePrefix), nil
6560
}
6661

internal/datastore/postgres/postgres_shared_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func testPostgresDatastore(t *testing.T, pc []postgresConfig) {
101101
return ds
102102
})
103103
return ds, nil
104-
}))
104+
}), false)
105105

106106
t.Run("TransactionTimestamps", createDatastoreTest(
107107
b,
@@ -236,7 +236,7 @@ func testPostgresDatastoreWithoutCommitTimestamps(t *testing.T, pc []postgresCon
236236
return ds
237237
})
238238
return ds, nil
239-
}), test.WithCategories(test.WatchCategory))
239+
}), test.WithCategories(test.WatchCategory), false)
240240
})
241241
}
242242
}

internal/datastore/proxy/observable_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func (obs observableTest) New(revisionQuantization, _, gcWindow time.Duration, w
2020
}
2121

2222
func TestObservableProxy(t *testing.T) {
23-
test.All(t, observableTest{})
23+
test.All(t, observableTest{}, true)
2424
}
2525

2626
func (p *observableProxy) ExampleRetryableError() error {

internal/datastore/proxy/schemacaching/estimatedsize_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ func TestEstimatedDefinitionSizes(t *testing.T) {
9191
for _, caveatDef := range fullyResolved.CaveatDefinitions {
9292
caveatDef := caveatDef
9393
t.Run("caveat "+caveatDef.Name, func(t *testing.T) {
94+
t.Parallel()
95+
9496
serialized, _ := caveatDef.MarshalVT()
9597
sizevt := caveatDef.SizeVT()
9698
estimated := estimatedCaveatDefinitionSize(sizevt)

internal/datastore/spanner/spanner_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ func (sd *spannerDatastore) ExampleRetryableError() error {
2828
}
2929

3030
func TestSpannerDatastore(t *testing.T) {
31+
t.Parallel()
32+
3133
ctx := context.Background()
3234
b := testdatastore.RunSpannerForTesting(t, "", "head")
3335

@@ -43,7 +45,7 @@ func TestSpannerDatastore(t *testing.T) {
4345
return ds
4446
})
4547
return ds, nil
46-
}), test.WithCategories(test.GCCategory, test.WatchCategory, test.StatsCategory))
48+
}), test.WithCategories(test.GCCategory, test.WatchCategory, test.StatsCategory), true)
4749

4850
t.Run("TestFakeStats", createDatastoreTest(
4951
b,

internal/dispatch/graph/check_test.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"testing"
88

99
"github.com/stretchr/testify/require"
10-
"go.uber.org/goleak"
1110

1211
"github.com/authzed/spicedb/internal/datastore/common"
1312
"github.com/authzed/spicedb/internal/datastore/memdb"
@@ -30,7 +29,7 @@ import (
3029
var ONR = tuple.ObjectAndRelation
3130

3231
func TestSimpleCheck(t *testing.T) {
33-
defer goleak.VerifyNone(t, append(testutil.GoLeakIgnores(), goleak.IgnoreCurrent())...)
32+
t.Parallel()
3433

3534
type expected struct {
3635
relation string
@@ -119,6 +118,7 @@ func TestSimpleCheck(t *testing.T) {
119118
userset := userset
120119
expected := expected
121120
t.Run(name, func(t *testing.T) {
121+
t.Parallel()
122122
require := require.New(t)
123123

124124
ctx, dispatch, revision := newLocalDispatcher(t)
@@ -150,6 +150,7 @@ func TestSimpleCheck(t *testing.T) {
150150
}
151151

152152
func TestMaxDepth(t *testing.T) {
153+
t.Parallel()
153154
require := require.New(t)
154155

155156
rawDS, err := memdb.NewMemdbDatastore(0, 0, memdb.DisableGC)
@@ -182,6 +183,7 @@ func TestMaxDepth(t *testing.T) {
182183
}
183184

184185
func TestCheckMetadata(t *testing.T) {
186+
t.Parallel()
185187
type expected struct {
186188
relation string
187189
isMember bool
@@ -287,6 +289,7 @@ func TestCheckMetadata(t *testing.T) {
287289
}
288290

289291
func TestCheckPermissionOverSchema(t *testing.T) {
292+
t.Parallel()
290293
testCases := []struct {
291294
name string
292295
schema string
@@ -1370,6 +1373,7 @@ func addFrame(trace *v1.CheckDebugTrace, foundFrames *mapz.Set[string]) {
13701373
}
13711374

13721375
func TestCheckDebugging(t *testing.T) {
1376+
t.Parallel()
13731377
type expectedFrame struct {
13741378
resourceType *core.RelationReference
13751379
resourceIDs []string
@@ -1482,6 +1486,7 @@ func TestCheckDebugging(t *testing.T) {
14821486
}
14831487

14841488
func TestCheckWithHints(t *testing.T) {
1489+
t.Parallel()
14851490
testCases := []struct {
14861491
name string
14871492
schema string
@@ -1853,6 +1858,7 @@ func TestCheckWithHints(t *testing.T) {
18531858
}
18541859

18551860
func TestCheckHintsPartialApplication(t *testing.T) {
1861+
t.Parallel()
18561862
require := require.New(t)
18571863

18581864
dispatcher := NewLocalOnlyDispatcher(10, 100)
@@ -1898,6 +1904,7 @@ func TestCheckHintsPartialApplication(t *testing.T) {
18981904
}
18991905

19001906
func TestCheckHintsPartialApplicationOverArrow(t *testing.T) {
1907+
t.Parallel()
19011908
require := require.New(t)
19021909

19031910
dispatcher := NewLocalOnlyDispatcher(10, 100)

internal/dispatch/graph/dispatch_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
)
1616

1717
func TestDispatchChunking(t *testing.T) {
18+
t.Parallel()
1819
schema := `
1920
definition user {
2021
relation self: user
@@ -35,6 +36,7 @@ func TestDispatchChunking(t *testing.T) {
3536
ctx, dispatcher, revision := newLocalDispatcherWithSchemaAndRels(t, schema, append(enabled, resources...))
3637

3738
t.Run("check", func(t *testing.T) {
39+
t.Parallel()
3840
for _, tpl := range resources[:1] {
3941
checkResult, err := dispatcher.DispatchCheck(ctx, &v1.DispatchCheckRequest{
4042
ResourceRelation: RR(tpl.ResourceAndRelation.Namespace, "view"),
@@ -55,6 +57,8 @@ func TestDispatchChunking(t *testing.T) {
5557
})
5658

5759
t.Run("lookup-resources", func(t *testing.T) {
60+
t.Parallel()
61+
5862
for _, tpl := range resources[:1] {
5963
stream := dispatch.NewCollectingDispatchStream[*v1.DispatchLookupResourcesResponse](ctx)
6064
err := dispatcher.DispatchLookupResources(&v1.DispatchLookupResourcesRequest{
@@ -75,6 +79,8 @@ func TestDispatchChunking(t *testing.T) {
7579
})
7680

7781
t.Run("lookup-subjects", func(t *testing.T) {
82+
t.Parallel()
83+
7884
for _, tpl := range resources[:1] {
7985
stream := dispatch.NewCollectingDispatchStream[*v1.DispatchLookupSubjectsResponse](ctx)
8086

internal/dispatch/graph/expand_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
"github.com/google/go-cmp/cmp"
1313
"github.com/stretchr/testify/require"
14-
"go.uber.org/goleak"
1514
"google.golang.org/protobuf/encoding/prototext"
1615
"google.golang.org/protobuf/testing/protocmp"
1716

@@ -137,7 +136,7 @@ var (
137136
)
138137

139138
func TestExpand(t *testing.T) {
140-
defer goleak.VerifyNone(t, append(testutil.GoLeakIgnores(), goleak.IgnoreCurrent())...)
139+
t.Parallel()
141140

142141
testCases := []struct {
143142
start *core.ObjectAndRelation
@@ -275,7 +274,7 @@ func onrExpr(onr *core.ObjectAndRelation) ast.Expr {
275274
}
276275

277276
func TestMaxDepthExpand(t *testing.T) {
278-
defer goleak.VerifyNone(t, append(testutil.GoLeakIgnores(), goleak.IgnoreCurrent())...)
277+
t.Parallel()
279278

280279
require := require.New(t)
281280

@@ -306,7 +305,7 @@ func TestMaxDepthExpand(t *testing.T) {
306305
}
307306

308307
func TestExpandOverSchema(t *testing.T) {
309-
defer goleak.VerifyNone(t, append(testutil.GoLeakIgnores(), goleak.IgnoreCurrent())...)
308+
t.Parallel()
310309

311310
testCases := []struct {
312311
name string

internal/dispatch/graph/graph_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ import (
1313
)
1414

1515
func TestUnwrapStatusError(t *testing.T) {
16+
t.Parallel()
17+
1618
err := rewriteError(context.Background(), graph.NewCheckFailureErr(status.Error(codes.Canceled, "canceled")))
1719
grpcutil.RequireStatus(t, codes.Canceled, err)
1820
}
1921

2022
func TestConcurrencyLimitsWithOverallDefaultLimit(t *testing.T) {
23+
t.Parallel()
2124
cl := ConcurrencyLimits{}
2225
require.Equal(t, uint16(0), cl.Check)
2326
require.Equal(t, uint16(0), cl.LookupResources)
@@ -38,6 +41,7 @@ func TestConcurrencyLimitsWithOverallDefaultLimit(t *testing.T) {
3841
}
3942

4043
func TestSharedConcurrencyLimits(t *testing.T) {
44+
t.Parallel()
4145
cl := SharedConcurrencyLimits(42)
4246
require.Equal(t, uint16(42), cl.Check)
4347
require.Equal(t, uint16(42), cl.LookupResources)

0 commit comments

Comments
 (0)