MCPcopy Index your code
hub / github.com/coder/coder / BenchmarkCacher

Function BenchmarkCacher

coderd/rbac/authz_test.go:289–315  ·  view source on GitHub ↗

BenchmarkCacher benchmarks the performance of the cacher.

(b *testing.B)

Source from the content-addressed store, hash-verified

287
288// BenchmarkCacher benchmarks the performance of the cacher.
289func BenchmarkCacher(b *testing.B) {
290 ctx := context.Background()
291 authz := rbac.Cacher(&coderdtest.FakeAuthorizer{})
292
293 rats := []int{1, 10, 100}
294
295 for _, rat := range rats {
296 b.Run(fmt.Sprintf("%v:1", rat), func(b *testing.B) {
297 b.ReportAllocs()
298 var (
299 subj rbac.Subject
300 obj rbac.Object
301 action policy.Action
302 )
303 for i := 0; i < b.N; i++ {
304 if i%rat == 0 {
305 // Cache miss
306 b.StopTimer()
307 subj, obj, action = coderdtest.RandomRBACSubject(), coderdtest.RandomRBACObject(), coderdtest.RandomRBACAction()
308 b.StartTimer()
309 }
310
311 _ = authz.Authorize(ctx, subj, action, obj)
312 }
313 })
314 }
315}
316
317func TestCache(t *testing.T) {
318 t.Parallel()

Callers

nothing calls this directly

Calls 6

CacherFunction · 0.92
RandomRBACSubjectFunction · 0.92
RandomRBACObjectFunction · 0.92
RandomRBACActionFunction · 0.92
RunMethod · 0.65
AuthorizeMethod · 0.65

Tested by

no test coverage detected