BenchmarkCacher benchmarks the performance of the cacher.
(b *testing.B)
| 287 | |
| 288 | // BenchmarkCacher benchmarks the performance of the cacher. |
| 289 | func 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 | |
| 317 | func TestCache(t *testing.T) { |
| 318 | t.Parallel() |
nothing calls this directly
no test coverage detected