Skip to content

Commit

Permalink
Benchmark hook.Run
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa committed Sep 21, 2023
1 parent 94f4cb2 commit 62a7849
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions plugin/plugin_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,45 @@ func Test_HookRegistry_Run_Remove(t *testing.T) {
assert.Equal(t, map[string]interface{}{}, result)
assert.Equal(t, 1, len(reg.Hooks()[v1.HookName_HOOK_NAME_ON_NEW_LOGGER]))
}

func BenchmarkHookRun(b *testing.B) {
cfg := logging.LoggerConfig{
Output: []config.LogOutput{config.Console},
TimeFormat: zerolog.TimeFormatUnix,
ConsoleTimeFormat: time.RFC3339,
Level: zerolog.DebugLevel,
NoColor: true,
}
logger := logging.NewLogger(context.Background(), cfg)
reg := NewRegistry(
context.Background(),
config.Loose,
config.PassDown,
config.Accept,
config.Stop,
logger,
false,
)
reg.Verification = config.PassDown
hookFunction := func(
ctx context.Context, args *v1.Struct, opts ...grpc.CallOption,
) (*v1.Struct, error) {
args.Fields["test"] = v1.NewStringValue("test1")
return args, nil
}
for priority := 0; priority < 1000; priority++ {
reg.AddHook(v1.HookName_HOOK_NAME_ON_NEW_LOGGER,
sdkPlugin.Priority(priority),
hookFunction,
)
}
for i := 0; i < b.N; i++ {
reg.Run(

Check failure on line 329 in plugin/plugin_registry_test.go

View workflow job for this annotation

GitHub Actions / Test GatewayD

Error return value of `reg.Run` is not checked (errcheck)
context.Background(),
map[string]interface{}{
"test": "test",
},
v1.HookName_HOOK_NAME_ON_NEW_LOGGER,
)
}
}

0 comments on commit 62a7849

Please sign in to comment.