1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-18 08:26:38 +02:00
go-micro/test/benchmark.go
2024-06-04 21:40:43 +01:00

65 lines
1.1 KiB
Go

package test
import (
"testing"
"go-micro.dev/v5"
"go-micro.dev/v5/broker"
"go-micro.dev/v5/client"
"go-micro.dev/v5/registry"
"go-micro.dev/v5/server"
"go-micro.dev/v5/transport"
"go-micro.dev/v5/util/test"
)
func BenchmarkService(b *testing.B) {
cfg := ServiceTestConfig{
Name: "test-service",
NewService: newService,
Parallel: []int{1, 8, 16, 32, 64},
Sequential: []int{0},
Streams: []int{0},
// PubSub: []int{10},
}
cfg.Run(b)
}
func newService(name string, opts ...micro.Option) (micro.Service, error) {
r := registry.NewMemoryRegistry(
registry.Services(test.Data),
)
b := broker.NewMemoryBroker()
t := transport.NewHTTPTransport()
c := client.NewClient(
client.Transport(t),
client.Broker(b),
)
s := server.NewRPCServer(
server.Name(name),
server.Registry(r),
server.Transport(t),
server.Broker(b),
)
if err := s.Init(); err != nil {
return nil, err
}
options := []micro.Option{
micro.Name(name),
micro.Server(s),
micro.Client(c),
micro.Registry(r),
micro.Broker(b),
}
options = append(options, opts...)
srv := micro.NewService(options...)
return srv, nil
}