Skip to content

Commit

Permalink
Merge pull request #983 from josephschorr/dispatch-goleak
Browse files Browse the repository at this point in the history
Dispatch goleak checking
  • Loading branch information
josephschorr authored Nov 7, 2022
2 parents f801c2f + e4a59eb commit 8823e6b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 9 deletions.
13 changes: 11 additions & 2 deletions internal/dispatch/graph/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import (
"fmt"
"testing"

log "github.com/authzed/spicedb/internal/logging"

"github.com/stretchr/testify/require"
"go.uber.org/goleak"

"github.com/authzed/spicedb/internal/datastore/common"
"github.com/authzed/spicedb/internal/datastore/memdb"
"github.com/authzed/spicedb/internal/dispatch"
"github.com/authzed/spicedb/internal/dispatch/caching"
"github.com/authzed/spicedb/internal/dispatch/keys"
"github.com/authzed/spicedb/internal/graph"
log "github.com/authzed/spicedb/internal/logging"
datastoremw "github.com/authzed/spicedb/internal/middleware/datastore"
"github.com/authzed/spicedb/internal/testfixtures"
"github.com/authzed/spicedb/pkg/datastore"
Expand All @@ -25,7 +25,16 @@ import (

var ONR = tuple.ObjectAndRelation

var goleakIgnores = []goleak.Option{
goleak.IgnoreTopFunction("github.com/golang/glog.(*loggingT).flushDaemon"),
goleak.IgnoreTopFunction("github.com/dgraph-io/ristretto.(*lfuPolicy).processItems"),
goleak.IgnoreTopFunction("github.com/dgraph-io/ristretto.(*Cache).processItems"),
goleak.IgnoreCurrent(),
}

func TestSimpleCheck(t *testing.T) {
defer goleak.VerifyNone(t, goleakIgnores...)

type expected struct {
relation string
isMember bool
Expand Down
5 changes: 5 additions & 0 deletions internal/dispatch/graph/expand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
"google.golang.org/protobuf/testing/protocmp"

"github.com/authzed/spicedb/internal/datastore/common"
Expand Down Expand Up @@ -129,6 +130,8 @@ var (
)

func TestExpand(t *testing.T) {
defer goleak.VerifyNone(t, goleakIgnores...)

testCases := []struct {
start *core.ObjectAndRelation
expansionMode v1.DispatchExpandRequest_ExpansionMode
Expand Down Expand Up @@ -264,6 +267,8 @@ func onrExpr(onr *core.ObjectAndRelation) ast.Expr {
}

func TestMaxDepthExpand(t *testing.T) {
defer goleak.VerifyNone(t, goleakIgnores...)

require := require.New(t)

rawDS, err := memdb.NewMemdbDatastore(0, 0, memdb.DisableGC)
Expand Down
6 changes: 4 additions & 2 deletions internal/dispatch/graph/lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
"time"

"github.com/stretchr/testify/require"

core "github.com/authzed/spicedb/pkg/proto/core/v1"
"go.uber.org/goleak"

"github.com/authzed/spicedb/internal/datastore/memdb"
datastoremw "github.com/authzed/spicedb/internal/middleware/datastore"
"github.com/authzed/spicedb/internal/testfixtures"
core "github.com/authzed/spicedb/pkg/proto/core/v1"
v1 "github.com/authzed/spicedb/pkg/proto/dispatch/v1"
"github.com/authzed/spicedb/pkg/tuple"
)
Expand All @@ -26,6 +26,8 @@ func RR(namespaceName string, relationName string) *core.RelationReference {
}

func TestSimpleLookup(t *testing.T) {
defer goleak.VerifyNone(t, goleakIgnores...)

testCases := []struct {
start *core.RelationReference
target *core.ObjectAndRelation
Expand Down
6 changes: 4 additions & 2 deletions internal/dispatch/graph/lookupsubjects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"sort"
"testing"

log "github.com/authzed/spicedb/internal/logging"

"github.com/stretchr/testify/require"
"go.uber.org/goleak"

"github.com/authzed/spicedb/internal/datastore/common"
"github.com/authzed/spicedb/internal/datastore/memdb"
"github.com/authzed/spicedb/internal/dispatch"
log "github.com/authzed/spicedb/internal/logging"
datastoremw "github.com/authzed/spicedb/internal/middleware/datastore"
"github.com/authzed/spicedb/internal/testfixtures"
"github.com/authzed/spicedb/pkg/datastore"
Expand All @@ -22,6 +22,8 @@ import (
)

func TestSimpleLookupSubjects(t *testing.T) {
defer goleak.VerifyNone(t, goleakIgnores...)

testCases := []struct {
resourceType string
resourceID string
Expand Down
6 changes: 4 additions & 2 deletions internal/dispatch/graph/reachableresources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"testing"

"github.com/stretchr/testify/require"

core "github.com/authzed/spicedb/pkg/proto/core/v1"
"go.uber.org/goleak"

"github.com/authzed/spicedb/internal/datastore/memdb"
"github.com/authzed/spicedb/internal/dispatch"
datastoremw "github.com/authzed/spicedb/internal/middleware/datastore"
"github.com/authzed/spicedb/internal/testfixtures"
core "github.com/authzed/spicedb/pkg/proto/core/v1"
v1 "github.com/authzed/spicedb/pkg/proto/dispatch/v1"
"github.com/authzed/spicedb/pkg/tuple"
)
Expand All @@ -31,6 +31,8 @@ func reachable(onr *core.ObjectAndRelation, hasPermission bool) reachableResourc
}

func TestSimpleReachableResources(t *testing.T) {
defer goleak.VerifyNone(t, goleakIgnores...)

testCases := []struct {
start *core.RelationReference
target *core.ObjectAndRelation
Expand Down
2 changes: 1 addition & 1 deletion internal/graph/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func expandSetOperation(

resultChans := make([]chan ExpandResult, 0, len(requests))
for _, req := range requests {
resultChan := make(chan ExpandResult)
resultChan := make(chan ExpandResult, 1)
resultChans = append(resultChans, resultChan)
go req(childCtx, resultChan)
}
Expand Down

0 comments on commit 8823e6b

Please sign in to comment.