Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wait for all servers to finish initializing #102

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions thrift_streaming/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ package thrift_streaming
import (
"log"
"net"
"sync"
"testing"
"time"

"github.com/cloudwego/kitex"
"github.com/cloudwego/kitex/server"

"github.com/cloudwego/kitex-tests/pkg/utils/serverutils"
"github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/combine/combineservice"
"github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/echo"
Expand All @@ -31,7 +34,6 @@ import (
kitexpbservice "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/kitex_pb/pbservice"
cross_echo "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen_cross/echo"
cross_echoservice "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen_cross/echo/echoservice"
"github.com/cloudwego/kitex/server"
)

func WithServerAddr(hostPort string) server.Option {
Expand Down Expand Up @@ -117,19 +119,41 @@ var (
)

func TestMain(m *testing.M) {
var wg sync.WaitGroup
wg.Add(6)
thriftAddr = serverutils.NextListenAddr()
crossAddr = serverutils.NextListenAddr()
slimAddr = serverutils.NextListenAddr()
grpcAddr = serverutils.NextListenAddr()
pbAddr = serverutils.NextListenAddr()
combineAddr = serverutils.NextListenAddr()
var thriftSvr, thriftCrossSvr, slimServer, grpcServer, pbServer, combineServer server.Server
go func() { thriftSvr = RunThriftServer(&EchoServiceImpl{}, thriftAddr) }()
go func() { thriftCrossSvr = RunThriftCrossServer(&CrossEchoServiceImpl{}, crossAddr) }()
go func() { grpcServer = RunGRPCPBServer(&GRPCPBServiceImpl{}, grpcAddr) }()
go func() { pbServer = RunKitexPBServer(&KitexPBServiceImpl{}, pbAddr) }()
go func() { slimServer = RunSlimThriftServer(&SlimEchoServiceImpl{}, slimAddr) }()
go func() { combineServer = RunCombineThriftServer(&CombineServiceImpl{}, combineAddr) }()
go func() {
thriftSvr = RunThriftServer(&EchoServiceImpl{}, thriftAddr)
wg.Done()
}()
go func() {
thriftCrossSvr = RunThriftCrossServer(&CrossEchoServiceImpl{}, crossAddr)
wg.Done()
}()
go func() {
grpcServer = RunGRPCPBServer(&GRPCPBServiceImpl{}, grpcAddr)
wg.Done()
}()
go func() {
pbServer = RunKitexPBServer(&KitexPBServiceImpl{}, pbAddr)
wg.Done()
}()
go func() {
slimServer = RunSlimThriftServer(&SlimEchoServiceImpl{}, slimAddr)
wg.Done()
}()
go func() {
combineServer = RunCombineThriftServer(&CombineServiceImpl{}, combineAddr)
wg.Done()
}()
// wait for all servers to start
wg.Wait()
defer func() {
if thriftSvr != nil {
thriftSvr.Stop()
Expand Down