MCPcopy
hub / github.com/ory/keto / BenchmarkComputedUsersets

Function BenchmarkComputedUsersets

internal/check/bench_test.go:138–174  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

136var ProjectOPLConfig string
137
138func BenchmarkComputedUsersets(b *testing.B) {
139 ctx := context.Background()
140
141 spans := tracetest.NewSpanRecorder()
142 tracer := trace.NewTracerProvider(trace.WithSpanProcessor(spans)).Tracer("")
143 reg := driver.NewSqliteTestRegistry(b, false,
144 driver.WithLogLevel("debug"),
145 driver.WithOPL(ProjectOPLConfig),
146 driver.WithTracer(tracer),
147 driver.WithConfig(config.KeyNamespacesExperimentalStrictMode, true))
148 reg.Logger().Logger.SetLevel(logrus.DebugLevel)
149
150 insertFixtures(b, reg.RelationTupleManager(), []string{
151 "Project:Ory#owner@User:Admin",
152 "Project:Ory#developer@User:Dev",
153 })
154
155 e := check.NewEngine(reg)
156
157 query := tupleFromString(b, "Project:Ory#readProject@User:Dev")
158
159 b.Run("Computed userset", func(b *testing.B) {
160 initialDBSpans := dbSpans(spans)
161 for i := 0; i < b.N; i++ {
162 res := e.CheckRelationTuple(ctx, query, 0)
163 assert.NoError(b, res.Err)
164 if res.Err != nil {
165 b.Errorf("got unexpected error: %v", res.Err)
166 }
167 if res.Membership != checkgroup.IsMember {
168 b.Error("check failed")
169 }
170 }
171 b.ReportMetric((float64(dbSpans(spans)-initialDBSpans))/float64(b.N), "queries/op")
172 })
173
174}
175
176func dbSpans(spans *tracetest.SpanRecorder) (count int) {
177 for _, s := range spans.Started() {

Callers

nothing calls this directly

Calls 15

CheckRelationTupleMethod · 0.95
NewSqliteTestRegistryFunction · 0.92
WithLogLevelFunction · 0.92
WithOPLFunction · 0.92
WithTracerFunction · 0.92
WithConfigFunction · 0.92
NewEngineFunction · 0.92
insertFixturesFunction · 0.85
tupleFromStringFunction · 0.85
dbSpansFunction · 0.85
TracerMethod · 0.65
LoggerMethod · 0.65

Tested by

no test coverage detected