Skip to content

Commit 6c3ada7

Browse files
echistyakovfacebook-github-bot
authored andcommitted
Extra client unittest checks
Summary: As titled. Reviewed By: leoleovich Differential Revision: D71006330 fbshipit-source-id: e4a7b2c87863f0688be89447ca462b0412c62947
1 parent 943065f commit 6c3ada7

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

thrift/lib/go/thrift/client_test.go

+15-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
"github.com/facebook/fbthrift/thrift/lib/go/thrift/types"
3333
)
3434

35-
func TestClient(t *testing.T) {
35+
func TestNewClientConnectionScenarios(t *testing.T) {
3636
listener, err := net.Listen("tcp", ":0")
3737
if err != nil {
3838
t.Fatalf("failed to listen: %v", err)
@@ -48,7 +48,7 @@ func TestClient(t *testing.T) {
4848
addr := listener.Addr()
4949

5050
// Testing successful client connection
51-
client, err := DeprecatedNewClient(
51+
client, err := NewClient(
5252
WithRocket(),
5353
WithIoTimeout(time.Second),
5454
WithProtocolID(types.ProtocolIDCompact),
@@ -67,7 +67,7 @@ func TestClient(t *testing.T) {
6767
}
6868

6969
// Testing unsuccessful client connection (cannot connect at all)
70-
client, err = DeprecatedNewClient(
70+
client, err = NewClient(
7171
WithRocket(),
7272
WithDialer(func() (net.Conn, error) {
7373
return net.Dial("unix", "/tmp/non_existent_garbage_socket_12345")
@@ -83,7 +83,7 @@ func TestClient(t *testing.T) {
8383
if err != nil {
8484
t.Fatal(fmt.Sprintf("failed to get FD count: %#v", err))
8585
}
86-
client, err = DeprecatedNewClient(
86+
client, err = NewClient(
8787
WithRocket(),
8888
// Invalid protocol that intentionally breaks client creation
8989
WithProtocolID(types.ProtocolID(12345)),
@@ -96,7 +96,7 @@ func TestClient(t *testing.T) {
9696
t.Fatalf("unexpected error when creating client: %v", err)
9797
}
9898
// IMPORTANT!
99-
// Even though we perform an explicit call to Close() in DeprecatedNewClient()
99+
// Even though we perform an explicit call to Close() in NewClient()
100100
// upon protocol error, actual FD closing is done by the garbage collector.
101101
// Without the GC call below - the FD may still linger and affect test results.
102102
runtime.GC()
@@ -131,7 +131,7 @@ func getNumFileDesciptors() (int, error) {
131131
return len(files), nil
132132
}
133133

134-
func TestClientV2(t *testing.T) {
134+
func TestNewClientCreation(t *testing.T) {
135135
listener, err := net.Listen("tcp", ":0")
136136
if err != nil {
137137
t.Fatalf("failed to listen: %v", err)
@@ -153,6 +153,9 @@ func TestClientV2(t *testing.T) {
153153
return net.Dial(addr.Network(), addr.String())
154154
}),
155155
)
156+
if _, ok := channel.(*rocketClient); !ok {
157+
t.Fatalf("channel is not of the correct underlying type")
158+
}
156159
if err != nil {
157160
t.Fatalf("failed to create client: %v", err)
158161
}
@@ -169,6 +172,9 @@ func TestClientV2(t *testing.T) {
169172
return net.Dial(addr.Network(), addr.String())
170173
}),
171174
)
175+
if _, ok := channel.(*SerialChannel); !ok {
176+
t.Fatalf("channel is not of the correct underlying type")
177+
}
172178
if err != nil {
173179
t.Fatalf("failed to create client: %v", err)
174180
}
@@ -185,6 +191,9 @@ func TestClientV2(t *testing.T) {
185191
return net.Dial(addr.Network(), addr.String())
186192
}),
187193
)
194+
if _, ok := channel.(*SerialChannel); !ok {
195+
t.Fatalf("channel is not of the correct underlying type")
196+
}
188197
if err != nil {
189198
t.Fatalf("failed to create client: %v", err)
190199
}

0 commit comments

Comments
 (0)