-
Notifications
You must be signed in to change notification settings - Fork 40
/
bench_test.go
66 lines (58 loc) · 1.36 KB
/
bench_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package gobrake_test
import (
"context"
"errors"
"fmt"
"net/http"
"net/http/httptest"
"testing"
"github.com/airbrake/gobrake/v5"
)
func BenchmarkSendNotice(b *testing.B) {
handler := func(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(http.StatusCreated)
_, err := w.Write([]byte(`{"id":"123"}`))
if err != nil {
panic(err)
}
}
server := httptest.NewServer(http.HandlerFunc(handler))
configServer := newConfigServer()
notifier := gobrake.NewNotifierWithOptions(&gobrake.NotifierOptions{
ProjectId: 1,
ProjectKey: "key",
Host: server.URL,
RemoteConfigHost: configServer.URL,
})
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
notice := notifier.Notice(errors.New("benchmark"), nil, 0)
for pb.Next() {
id, err := notifier.SendNotice(notice)
if err != nil {
b.Fatal(err)
}
if id != "123" {
b.Fatalf("got %q, wanted 123", id)
}
}
})
}
func BenchmarkRoutesNotify(b *testing.B) {
notifier := gobrake.NewNotifierWithOptions(&gobrake.NotifierOptions{
ProjectId: 1,
ProjectKey: "",
})
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
var i int
for pb.Next() {
_, metric := gobrake.NewRouteMetric(context.TODO(), "GET", fmt.Sprintf("/api/v4/groups/%d", i))
err := notifier.Routes.Notify(context.TODO(), metric)
if err != nil {
b.Fatal(err)
}
i++
}
})
}