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

Function BenchmarkRBACFilter

coderd/rbac/authz_test.go:233–263  ·  view source on GitHub ↗

BenchmarkRBACFilter benchmarks the rbac.Filter method. go test -bench '^BenchmarkRBACFilter$' -benchmem -memprofile memprofile.out -cpuprofile profile.out

(b *testing.B)

Source from the content-addressed store, hash-verified

231//
232// go test -bench '^BenchmarkRBACFilter$' -benchmem -memprofile memprofile.out -cpuprofile profile.out
233func BenchmarkRBACFilter(b *testing.B) {
234 benchCases, user, orgs := benchmarkUserCases()
235 users := append([]uuid.UUID{},
236 user,
237 uuid.MustParse("4ca78b1d-f2d2-4168-9d76-cd93b51c6c1e"),
238 uuid.MustParse("0632b012-49e0-4d70-a5b3-f4398f1dcd52"),
239 uuid.MustParse("70dbaa7a-ea9c-4f68-a781-97b08af8461d"),
240 )
241
242 authorizer := rbac.NewStrictCachingAuthorizer(prometheus.NewRegistry())
243
244 for _, c := range benchCases {
245 b.Run("PrepareOnly-"+c.Name, func(b *testing.B) {
246 obType := rbac.ResourceWorkspace.Type
247 for i := 0; i < b.N; i++ {
248 _, err := authorizer.Prepare(context.Background(), c.Actor, policy.ActionRead, obType)
249 require.NoError(b, err)
250 }
251 })
252 }
253
254 for _, c := range benchCases {
255 b.Run(c.Name, func(b *testing.B) {
256 objects := benchmarkSetup(orgs, users, b.N)
257 b.ResetTimer()
258 allowed, err := rbac.Filter(context.Background(), authorizer, c.Actor, policy.ActionRead, objects)
259 require.NoError(b, err)
260 _ = allowed
261 })
262 }
263}
264
265func benchmarkSetup(orgs []uuid.UUID, users []uuid.UUID, size int, opts ...func(object rbac.Object) rbac.Object) []rbac.Object {
266 // Create a "random" but deterministic set of objects.

Callers

nothing calls this directly

Calls 6

FilterFunction · 0.92
benchmarkUserCasesFunction · 0.85
benchmarkSetupFunction · 0.85
RunMethod · 0.65
PrepareMethod · 0.65

Tested by

no test coverage detected