Skip to content

Commit

Permalink
go: Fix cross test server
Browse files Browse the repository at this point in the history
Client: go

This was a bug introduced by 91565d4
that broke go's cross-test server, but because other CI issues we didn't
run cross-test so we didn't notice the issue.
  • Loading branch information
fishy committed Aug 14, 2024
1 parent 384cdeb commit c71d8ae
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
5 changes: 4 additions & 1 deletion test/go/src/bin/testserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ func main() {
return
}
} else {
http.ListenAndServe(fmt.Sprintf(":%d", *port), nil)
if err := http.ListenAndServe(fmt.Sprintf(":%d", *port), nil); err != nil {
fmt.Println(err)
return
}
}
} else {
server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
Expand Down
43 changes: 28 additions & 15 deletions test/go/src/common/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func GetServerParams(
) (thrift.TProcessor, thrift.TServerTransport, thrift.TTransportFactory, thrift.TProtocolFactory, string /* addr */, error) {

var err error
hostPort := fmt.Sprintf("%s:0", host)
hostPort := fmt.Sprintf("%s:%d", host, port)
var cfg *thrift.TConfiguration = nil

var protocolFactory thrift.TProtocolFactory
Expand All @@ -73,21 +73,32 @@ func GetServerParams(

var serverTransport thrift.TServerTransport
var addr string
if transport == "http" {
// In cross-test servers, we would call http.ListenAndServe
// again on the host:port, so don't use the listen to fill the
// addr and just generate it here instead.
addr = hostPort
if domain_socket != "" {
addr = domain_socket
}
}
if ssl {
cfg := new(tls.Config)
if cert, err := tls.LoadX509KeyPair(certPath+"/server.crt", certPath+"/server.key"); err != nil {
return nil, nil, nil, nil, "", err
} else {
cfg.Certificates = append(cfg.Certificates, cert)
}
transport, transportErr := thrift.NewTSSLServerSocket(hostPort, cfg)
serverSocket, transportErr := thrift.NewTSSLServerSocket(hostPort, cfg)
if transportErr == nil {
listenErr := transport.Listen()
if listenErr == nil {
serverTransport = transport
addr = transport.Addr().String()
} else {
err = listenErr
if transport != "http" {
listenErr := serverSocket.Listen()
if listenErr == nil {
serverTransport = serverSocket
addr = serverSocket.Addr().String()
} else {
err = listenErr
}
}
} else {
err = transportErr
Expand All @@ -97,14 +108,16 @@ func GetServerParams(
serverTransport, err = thrift.NewTServerSocket(domain_socket)
addr = domain_socket
} else {
transport, transportErr := thrift.NewTServerSocket(hostPort)
serverSocket, transportErr := thrift.NewTServerSocket(hostPort)
if transportErr == nil {
listenErr := transport.Listen()
if listenErr == nil {
serverTransport = transport
addr = transport.Addr().String()
} else {
err = listenErr
if transport != "http" {
listenErr := serverSocket.Listen()
if listenErr == nil {
serverTransport = serverSocket
addr = serverSocket.Addr().String()
} else {
err = listenErr
}
}
} else {
err = transportErr
Expand Down

0 comments on commit c71d8ae

Please sign in to comment.