Skip to content

Commit

Permalink
Add basic rpc benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
joshklop authored and omerfirmak committed Sep 22, 2023
1 parent 77692ca commit 3f6b7d3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions jsonrpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,3 +482,18 @@ func assertBatchResponse(t *testing.T, expectedStr, actualStr string) {

assert.ElementsMatch(t, expected, actual)
}

func BenchmarkHandle(b *testing.B) {
listener := CountingEventListener{}
server := jsonrpc.NewServer(1, utils.NewNopZapLogger()).WithValidator(validator.New()).WithListener(&listener)
require.NoError(b, server.RegisterMethods(jsonrpc.Method{
Name: "bench",
Handler: func() (int, *jsonrpc.Error) { return 0, nil },
}))

const request = `{"jsonrpc":"2.0","id":1,"method":"test"}`
for i := 0; i < b.N; i++ {
_, err := server.Handle(context.Background(), []byte(request))
require.NoError(b, err)
}
}

0 comments on commit 3f6b7d3

Please sign in to comment.