test: add more tests (#1119)
parent
4c6234f108
commit
9b114e3251
@ -1,16 +1,45 @@
|
|||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/tal-tech/go-zero/core/stat"
|
"github.com/tal-tech/go-zero/core/stat"
|
||||||
|
"github.com/tal-tech/go-zero/zrpc/internal/mock"
|
||||||
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWithMetrics(t *testing.T) {
|
func TestRpcServer(t *testing.T) {
|
||||||
metrics := stat.NewMetrics("foo")
|
metrics := stat.NewMetrics("foo")
|
||||||
opt := WithMetrics(metrics)
|
server := NewRpcServer("localhost:54321", WithMetrics(metrics))
|
||||||
var options rpcServerOptions
|
server.SetName("mock")
|
||||||
opt(&options)
|
var wg sync.WaitGroup
|
||||||
assert.Equal(t, metrics, options.metrics)
|
var grpcServer *grpc.Server
|
||||||
|
var lock sync.Mutex
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
err := server.Start(func(server *grpc.Server) {
|
||||||
|
lock.Lock()
|
||||||
|
mock.RegisterDepositServiceServer(server, new(mock.DepositServer))
|
||||||
|
grpcServer = server
|
||||||
|
lock.Unlock()
|
||||||
|
wg.Done()
|
||||||
|
})
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}()
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
lock.Lock()
|
||||||
|
grpcServer.GracefulStop()
|
||||||
|
lock.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRpcServer_WithBadAddress(t *testing.T) {
|
||||||
|
server := NewRpcServer("localhost:111111")
|
||||||
|
server.SetName("mock")
|
||||||
|
err := server.Start(func(server *grpc.Server) {
|
||||||
|
mock.RegisterDepositServiceServer(server, new(mock.DepositServer))
|
||||||
|
})
|
||||||
|
assert.NotNil(t, err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue