chore: add unit tests (#1615)

* test: add more tests

* test: add more tests
This commit is contained in:
Kevin Wan
2022-03-04 17:54:09 +08:00
committed by GitHub
parent 60760b52ab
commit 3b7ca86e4f
19 changed files with 108 additions and 69 deletions

View File

@@ -36,7 +36,7 @@ func TestServer_setupInterceptors(t *testing.T) {
func TestServer(t *testing.T) {
SetServerSlowThreshold(time.Second)
srv := MustNewServer(RpcServerConf{
svr := MustNewServer(RpcServerConf{
ServiceConf: service.ServiceConf{
Log: logx.LogConf{
ServiceName: "foo",
@@ -52,11 +52,11 @@ func TestServer(t *testing.T) {
CpuThreshold: 0,
}, func(server *grpc.Server) {
})
srv.AddOptions(grpc.ConnectionTimeout(time.Hour))
srv.AddUnaryInterceptors(serverinterceptors.UnaryCrashInterceptor)
srv.AddStreamInterceptors(serverinterceptors.StreamCrashInterceptor)
go srv.Start()
srv.Stop()
svr.AddOptions(grpc.ConnectionTimeout(time.Hour))
svr.AddUnaryInterceptors(serverinterceptors.UnaryCrashInterceptor)
svr.AddStreamInterceptors(serverinterceptors.StreamCrashInterceptor)
go svr.Start()
svr.Stop()
}
func TestServerError(t *testing.T) {
@@ -79,7 +79,7 @@ func TestServerError(t *testing.T) {
}
func TestServer_HasEtcd(t *testing.T) {
srv := MustNewServer(RpcServerConf{
svr := MustNewServer(RpcServerConf{
ServiceConf: service.ServiceConf{
Log: logx.LogConf{
ServiceName: "foo",
@@ -94,15 +94,15 @@ func TestServer_HasEtcd(t *testing.T) {
Redis: redis.RedisKeyConf{},
}, func(server *grpc.Server) {
})
srv.AddOptions(grpc.ConnectionTimeout(time.Hour))
srv.AddUnaryInterceptors(serverinterceptors.UnaryCrashInterceptor)
srv.AddStreamInterceptors(serverinterceptors.StreamCrashInterceptor)
go srv.Start()
srv.Stop()
svr.AddOptions(grpc.ConnectionTimeout(time.Hour))
svr.AddUnaryInterceptors(serverinterceptors.UnaryCrashInterceptor)
svr.AddStreamInterceptors(serverinterceptors.StreamCrashInterceptor)
go svr.Start()
svr.Stop()
}
func TestServer_StartFailed(t *testing.T) {
srv := MustNewServer(RpcServerConf{
svr := MustNewServer(RpcServerConf{
ServiceConf: service.ServiceConf{
Log: logx.LogConf{
ServiceName: "foo",
@@ -113,7 +113,7 @@ func TestServer_StartFailed(t *testing.T) {
}, func(server *grpc.Server) {
})
assert.Panics(t, srv.Start)
assert.Panics(t, svr.Start)
}
type mockedServer struct {