Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jayantxie committed Jan 22, 2025
1 parent 47594c0 commit 91e914b
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 66 deletions.
2 changes: 1 addition & 1 deletion pkg/transmeta/ttheader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func TestTTHeaderServerReadMetainfo(t *testing.T) {

func TestTTHeaderServerWriteMetainfo(t *testing.T) {
ctx := context.Background()
ri := rpcinfo.NewRPCInfo(nil, nil, rpcinfo.NewInvocation("", ""),
ri := rpcinfo.NewRPCInfo(nil, rpcinfo.NewEndpointInfo("", "mock", nil, nil), rpcinfo.NewInvocation("", ""),
rpcinfo.NewRPCConfig(), rpcinfo.NewRPCStats())
msg := remote.NewMessage(nil, mocks.ServiceInfo(), ri, remote.Call, remote.Client)

Expand Down
136 changes: 71 additions & 65 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -979,80 +979,86 @@ func TestInvokeHandlerPanic(t *testing.T) {
}

func TestRegisterService(t *testing.T) {
svr := NewServer()
time.AfterFunc(time.Second, func() {
err := svr.Stop()
test.Assert(t, err == nil, err)
})
{
svr := NewServer()
time.AfterFunc(time.Second, func() {
err := svr.Stop()
test.Assert(t, err == nil, err)
})

svr.Run()
svr.Run()

test.PanicAt(t, func() {
_ = svr.RegisterService(mocks.ServiceInfo(), mocks.MyServiceHandler())
}, func(err interface{}) bool {
if errMsg, ok := err.(string); ok {
return strings.Contains(errMsg, "server is running")
}
return true
})
svr.Stop()
test.PanicAt(t, func() {
_ = svr.RegisterService(mocks.ServiceInfo(), mocks.MyServiceHandler())
}, func(err interface{}) bool {
if errMsg, ok := err.(string); ok {
return strings.Contains(errMsg, "server is running")
}
return true
})
svr.Stop()
}

svr = NewServer()
time.AfterFunc(time.Second, func() {
err := svr.Stop()
test.Assert(t, err == nil, err)
})
{
svr := NewServer()
time.AfterFunc(time.Second, func() {
err := svr.Stop()
test.Assert(t, err == nil, err)
})

test.PanicAt(t, func() {
_ = svr.RegisterService(nil, mocks.MyServiceHandler())
}, func(err interface{}) bool {
if errMsg, ok := err.(string); ok {
return strings.Contains(errMsg, "svcInfo is nil")
}
return true
})
test.PanicAt(t, func() {
_ = svr.RegisterService(nil, mocks.MyServiceHandler())
}, func(err interface{}) bool {
if errMsg, ok := err.(string); ok {
return strings.Contains(errMsg, "svcInfo is nil")
}
return true
})

test.PanicAt(t, func() {
_ = svr.RegisterService(mocks.ServiceInfo(), nil)
}, func(err interface{}) bool {
if errMsg, ok := err.(string); ok {
return strings.Contains(errMsg, "handler is nil")
}
return true
})
test.PanicAt(t, func() {
_ = svr.RegisterService(mocks.ServiceInfo(), nil)
}, func(err interface{}) bool {
if errMsg, ok := err.(string); ok {
return strings.Contains(errMsg, "handler is nil")
}
return true
})

test.PanicAt(t, func() {
_ = svr.RegisterService(mocks.ServiceInfo(), mocks.MyServiceHandler(), WithFallbackService())
_ = svr.RegisterService(mocks.ServiceInfo(), mocks.MyServiceHandler())
}, func(err interface{}) bool {
if errMsg, ok := err.(string); ok {
return strings.Contains(errMsg, "Service[MockService] is already defined")
}
return true
})
test.PanicAt(t, func() {
_ = svr.RegisterService(mocks.ServiceInfo(), mocks.MyServiceHandler(), WithFallbackService())
_ = svr.RegisterService(mocks.ServiceInfo(), mocks.MyServiceHandler())
}, func(err interface{}) bool {
if errMsg, ok := err.(string); ok {
return strings.Contains(errMsg, "Service[MockService] is already defined")
}
return true
})

test.PanicAt(t, func() {
_ = svr.RegisterService(mocks.Service2Info(), mocks.MyServiceHandler(), WithFallbackService())
}, func(err interface{}) bool {
if errMsg, ok := err.(string); ok {
return strings.Contains(errMsg, "multiple fallback services cannot be registered")
}
return true
})
svr.Stop()
test.PanicAt(t, func() {
_ = svr.RegisterService(mocks.Service2Info(), mocks.MyServiceHandler(), WithFallbackService())
}, func(err interface{}) bool {
if errMsg, ok := err.(string); ok {
return strings.Contains(errMsg, "multiple fallback services cannot be registered")
}
return true
})
svr.Stop()
}

svr = NewServer()
time.AfterFunc(time.Second, func() {
err := svr.Stop()
test.Assert(t, err == nil, err)
})
{
svr := NewServer()
time.AfterFunc(time.Second, func() {
err := svr.Stop()
test.Assert(t, err == nil, err)
})

_ = svr.RegisterService(mocks.ServiceInfo(), mocks.MyServiceHandler())
_ = svr.RegisterService(mocks.Service3Info(), mocks.MyServiceHandler())
err := svr.Run()
test.Assert(t, err != nil)
test.Assert(t, err.Error() == "method name [mock] is conflicted between services but no fallback service is specified")
svr.Stop()
_ = svr.RegisterService(mocks.ServiceInfo(), mocks.MyServiceHandler())
_ = svr.RegisterService(mocks.Service3Info(), mocks.MyServiceHandler())
err := svr.Run()
test.Assert(t, err != nil)
test.Assert(t, err.Error() == "method name [mock] is conflicted between services but no fallback service is specified")
svr.Stop()
}
}

func TestRegisterServiceWithMiddleware(t *testing.T) {
Expand Down

0 comments on commit 91e914b

Please sign in to comment.