Skip to content

Commit

Permalink
test(bench): add benchmark for computing Check request cache keys (#1095
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jon-whit authored Oct 31, 2023
1 parent 86c110a commit 17c7f7b
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions internal/graph/cached_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,44 @@ func TestCachedCheckDatastoreQueryCount(t *testing.T) {
require.NoError(t, err)
require.Equal(t, uint32(1), res.GetResolutionMetadata().DatastoreQueryCount)
}

var checkCacheKey string

func BenchmarkCheckRequestCacheKey(b *testing.B) {
storeID := ulid.Make().String()
modelID := ulid.Make().String()

var err error

for n := 0; n < b.N; n++ {
checkCacheKey, err = checkRequestCacheKey(&ResolveCheckRequest{
StoreID: storeID,
AuthorizationModelID: modelID,
TupleKey: tuple.NewTupleKey("document:1", "viewer", "user:jon"),
})
require.NoError(b, err)
}
}

func BenchmarkCheckRequestCacheKeyWithContextualTuples(b *testing.B) {
storeID := ulid.Make().String()
modelID := ulid.Make().String()

var err error

tuples := []*openfgav1.TupleKey{
tuple.NewTupleKey("document:x", "viewer", "user:x"),
tuple.NewTupleKey("document:y", "viewer", "user:y"),
tuple.NewTupleKey("document:z", "viewer", "user:z"),
}

for n := 0; n < b.N; n++ {
checkCacheKey, err = checkRequestCacheKey(&ResolveCheckRequest{
StoreID: storeID,
AuthorizationModelID: modelID,
TupleKey: tuple.NewTupleKey("document:1", "viewer", "user:jon"),
ContextualTuples: tuples,
})
require.NoError(b, err)
}
}

0 comments on commit 17c7f7b

Please sign in to comment.