Skip to content

Commit

Permalink
create benchmark test for send and publish
Browse files Browse the repository at this point in the history
  • Loading branch information
ssengalanto committed Jan 20, 2023
1 parent c421848 commit e63acea
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
44 changes: 44 additions & 0 deletions midt_benchmark_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package midt_test

import (
"context"
"testing"

"github.com/ssengalanto/midt"
)

func Benchmark_Send(b *testing.B) {
m := midt.New()

hdlr := &CommandHandler{}
err := m.RegisterRequestHandler(hdlr)
if err != nil {
b.Error(err)
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := m.Send(context.Background(), &CommandRequest{})
if err != nil {
b.Error(err)
}
}
}

func Benchmark_Publish(b *testing.B) {
m := midt.New()

hdlr := &NotificationHandler{}
err := m.RegisterNotificationHandler(hdlr)
if err != nil {
b.Error(err)
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := m.Send(context.Background(), &NotificationRequest{})
if err != nil {
b.Error(err)
}
}
}
4 changes: 2 additions & 2 deletions midt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func TestMidt_RegisterRequestHandler(t *testing.T) {
t.Run("it should register all request handlers successfully", func(t *testing.T) {
m := midt.New()

hdlr1 := &CommandHandler{}
err := m.RegisterRequestHandler(hdlr1)
hdlr := &CommandHandler{}
err := m.RegisterRequestHandler(hdlr)
require.NoError(t, err)
})
t.Run("it should return an error when trying to register an already existing request handler", func(t *testing.T) {
Expand Down

0 comments on commit e63acea

Please sign in to comment.