-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add notification message and publish to mediatr
- Loading branch information
mehdihadeli
committed
Aug 3, 2022
1 parent
dac2b83
commit c4f8d3f
Showing
3 changed files
with
214 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package mediatr | ||
|
||
import ( | ||
"context" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func Benchmark_Send(b *testing.B) { | ||
// because benchmark method will run multiple times, we need to reset the request handler registry before each run. | ||
requestHandlersRegistrations = make(map[reflect.Type]interface{}) | ||
|
||
handler := &RequestTestHandler{} | ||
errRegister := RegisterRequestHandler[*RequestTest, *ResponseTest](handler) | ||
if errRegister != nil { | ||
b.Error(errRegister) | ||
} | ||
|
||
b.ResetTimer() | ||
ctx := context.Background() | ||
for i := 0; i < b.N; i++ { | ||
_, err := Send[*RequestTest, *ResponseTest](ctx, &RequestTest{Data: "test"}) | ||
if err != nil { | ||
b.Error(err) | ||
} | ||
} | ||
} | ||
|
||
func Benchmark_Publish(b *testing.B) { | ||
// because benchmark method will run multiple times, we need to reset the notification handlers registry before each run. | ||
notificationHandlersRegistrations = make(map[reflect.Type][]interface{}) | ||
|
||
handler := &NotificationTestHandler{} | ||
handler2 := &NotificationTestHandler4{} | ||
|
||
errRegister := RegisterNotificationHandlers[*NotificationTest](handler, handler2) | ||
if errRegister != nil { | ||
b.Error(errRegister) | ||
} | ||
|
||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
err := Publish[*NotificationTest](context.Background(), &NotificationTest{Data: "test"}) | ||
if err != nil { | ||
b.Error(err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters