Update supported go versions
Client: go
With the release of go 1.23, update supported go versions to 1.22+1.23
according to our go support policy.
Also update the code to use the new range loop feature introduced in go
1.22 when appropriate.
Also fix a bug in TSSLServerSocket.Addr that it does not return the
listener address.
diff --git a/test/go/src/common/client.go b/test/go/src/common/client.go
index f9dfcaf..2383b82 100644
--- a/test/go/src/common/client.go
+++ b/test/go/src/common/client.go
@@ -37,14 +37,11 @@
}
func StartClient(
- host string,
- port int64,
- domain_socket string,
+ addr string,
transport string,
protocol string,
ssl bool,
) (client *thrifttest.ThriftTestClient, trans thrift.TTransport, err error) {
- hostPort := fmt.Sprintf("%s:%d", host, port)
cfg := &thrift.TConfiguration{
TLSConfig: &tls.Config{
InsecureSkipVerify: true,
@@ -70,13 +67,9 @@
protocolFactory = thrift.NewTDebugProtocolFactoryWithLogger(protocolFactory, "client:", thrift.StdLogger(nil))
}
if ssl {
- trans = thrift.NewTSSLSocketConf(hostPort, cfg)
+ trans = thrift.NewTSSLSocketConf(addr, cfg)
} else {
- if domain_socket != "" {
- trans = thrift.NewTSocketConf(domain_socket, nil)
- } else {
- trans = thrift.NewTSocketConf(hostPort, nil)
- }
+ trans = thrift.NewTSocketConf(addr, nil)
}
if err != nil {
return nil, nil, err
@@ -88,10 +81,9 @@
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr}
- trans, err = thrift.NewTHttpClientWithOptions(fmt.Sprintf("https://%s/", hostPort), thrift.THttpClientOptions{Client: client})
- fmt.Println(hostPort)
+ trans, err = thrift.NewTHttpClientWithOptions(fmt.Sprintf("https://%s/", addr), thrift.THttpClientOptions{Client: client})
} else {
- trans, err = thrift.NewTHttpClient(fmt.Sprintf("http://%s/", hostPort))
+ trans, err = thrift.NewTHttpClient(fmt.Sprintf("http://%s/", addr))
}
case "framed":
trans = thrift.NewTFramedTransportConf(trans, cfg)
diff --git a/test/go/src/common/clientserver_test.go b/test/go/src/common/clientserver_test.go
index a39519d..48203b6 100644
--- a/test/go/src/common/clientserver_test.go
+++ b/test/go/src/common/clientserver_test.go
@@ -22,6 +22,7 @@
import (
"context"
"errors"
+ "fmt"
"reflect"
"sync"
"testing"
@@ -42,10 +43,10 @@
}
var units = []test_unit{
- {"127.0.0.1", 9095, "", "", "binary", false},
- {"127.0.0.1", 9091, "", "", "compact", false},
- {"127.0.0.1", 9092, "", "", "binary", true},
- {"127.0.0.1", 9093, "", "", "compact", true},
+ {"127.0.0.1", 0, "", "", "binary", false},
+ {"127.0.0.1", 0, "", "", "compact", false},
+ {"127.0.0.1", 0, "", "", "binary", true},
+ {"127.0.0.1", 0, "", "", "compact", true},
}
func TestAllConnection(t *testing.T) {
@@ -61,29 +62,31 @@
}
func doUnit(t *testing.T, unit *test_unit) {
- ctrl := gomock.NewController(t)
- defer ctrl.Finish()
- handler := NewMockThriftTest(ctrl)
+ t.Run(fmt.Sprintf("%v", *unit), func(t *testing.T) {
+ ctrl := gomock.NewController(t)
+ defer ctrl.Finish()
+ handler := NewMockThriftTest(ctrl)
- processor, serverTransport, transportFactory, protocolFactory, err := GetServerParams(unit.host, unit.port, unit.domain_socket, unit.transport, unit.protocol, unit.ssl, "../../../keys", handler)
- if err != nil {
- t.Errorf("GetServerParams failed: %v", err)
- }
+ processor, serverTransport, transportFactory, protocolFactory, addr, err := GetServerParams(unit.host, unit.port, unit.domain_socket, unit.transport, unit.protocol, unit.ssl, "../../../keys", handler)
+ if err != nil {
+ t.Errorf("GetServerParams failed: %v", err)
+ }
- server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
- if err = server.Listen(); err != nil {
- t.Errorf("Unable to start server: %v", err)
- return
- }
- go server.Serve()
- defer server.Stop()
- client, trans, err := StartClient(unit.host, unit.port, unit.domain_socket, unit.transport, unit.protocol, unit.ssl)
- if err != nil {
- t.Errorf("Unable to start client: %v", err)
- return
- }
- defer trans.Close()
- callEverythingWithMock(t, client, handler)
+ server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
+ if err = server.Listen(); err != nil {
+ t.Errorf("Unable to start server: %v", err)
+ return
+ }
+ go server.Serve()
+ defer server.Stop()
+ client, trans, err := StartClient(addr, unit.transport, unit.protocol, unit.ssl)
+ if err != nil {
+ t.Errorf("Unable to start client: %v", err)
+ return
+ }
+ defer trans.Close()
+ callEverythingWithMock(t, client, handler)
+ })
}
var rmapmap = map[int32]map[int32]int32{
diff --git a/test/go/src/common/context_test.go b/test/go/src/common/context_test.go
index c6cbad8..0aa217f 100644
--- a/test/go/src/common/context_test.go
+++ b/test/go/src/common/context_test.go
@@ -40,12 +40,17 @@
}
func TestHttpContextTimeout(t *testing.T) {
- unit := test_unit{"127.0.0.1", 9096, "", "http", "binary", false}
+ const (
+ host = "127.0.0.1"
+ port = 9096
+ )
+ addr := fmt.Sprintf("%s:%d", host, port)
+ unit := test_unit{host, port, "", "http", "binary", false}
- server := &http.Server{Addr: unit.host + fmt.Sprintf(":%d", unit.port), Handler: slowHttpHandler{}}
+ server := &http.Server{Addr: addr, Handler: slowHttpHandler{}}
go server.ListenAndServe()
- client, trans, err := StartClient(unit.host, unit.port, unit.domain_socket, unit.transport, unit.protocol, unit.ssl)
+ client, trans, err := StartClient(addr, unit.transport, unit.protocol, unit.ssl)
if err != nil {
t.Errorf("Unable to start client: %v", err)
return
diff --git a/test/go/src/common/server.go b/test/go/src/common/server.go
index f48389d..0af2702 100644
--- a/test/go/src/common/server.go
+++ b/test/go/src/common/server.go
@@ -46,10 +46,10 @@
ssl bool,
certPath string,
handler thrifttest.ThriftTest,
-) (thrift.TProcessor, thrift.TServerTransport, thrift.TTransportFactory, thrift.TProtocolFactory, error) {
+) (thrift.TProcessor, thrift.TServerTransport, thrift.TTransportFactory, thrift.TProtocolFactory, string /* addr */, error) {
var err error
- hostPort := fmt.Sprintf("%s:%d", host, port)
+ hostPort := fmt.Sprintf("%s:0", host)
var cfg *thrift.TConfiguration = nil
var protocolFactory thrift.TProtocolFactory
@@ -65,30 +65,54 @@
case "header":
protocolFactory = thrift.NewTHeaderProtocolFactoryConf(nil)
default:
- return nil, nil, nil, nil, fmt.Errorf("invalid protocol specified %s", protocol)
+ return nil, nil, nil, nil, "", fmt.Errorf("invalid protocol specified %s", protocol)
}
if debugServerProtocol {
protocolFactory = thrift.NewTDebugProtocolFactoryWithLogger(protocolFactory, "server:", thrift.StdLogger(nil))
}
var serverTransport thrift.TServerTransport
+ var addr string
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
+ return nil, nil, nil, nil, "", err
} else {
cfg.Certificates = append(cfg.Certificates, cert)
}
- serverTransport, err = thrift.NewTSSLServerSocket(hostPort, cfg)
+ transport, transportErr := thrift.NewTSSLServerSocket(hostPort, cfg)
+ if transportErr == nil {
+ listenErr := transport.Listen()
+ if listenErr == nil {
+ serverTransport = transport
+ addr = transport.Addr().String()
+ } else {
+ err = listenErr
+ }
+ } else {
+ err = transportErr
+ }
} else {
if domain_socket != "" {
serverTransport, err = thrift.NewTServerSocket(domain_socket)
+ addr = domain_socket
} else {
- serverTransport, err = thrift.NewTServerSocket(hostPort)
+ transport, transportErr := thrift.NewTServerSocket(hostPort)
+ if transportErr == nil {
+ listenErr := transport.Listen()
+ if listenErr == nil {
+ serverTransport = transport
+ addr = transport.Addr().String()
+ } else {
+ err = listenErr
+ }
+ } else {
+ err = transportErr
+ }
}
}
if err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, "", err
}
var transportFactory thrift.TTransportFactory
@@ -107,9 +131,9 @@
case "":
transportFactory = thrift.NewTTransportFactory()
default:
- return nil, nil, nil, nil, fmt.Errorf("invalid transport specified %s", transport)
+ return nil, nil, nil, nil, "", fmt.Errorf("invalid transport specified %s", transport)
}
processor := thrifttest.NewThriftTestProcessor(handler)
- return processor, serverTransport, transportFactory, protocolFactory, nil
+ return processor, serverTransport, transportFactory, protocolFactory, addr, nil
}