Skip to content

Commit aca852f

Browse files
Copilotasmyasnikov
andauthored
Add comprehensive unit tests for internal/conn package (#1886)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: asmyasnikov <[email protected]> Co-authored-by: Aleksey Myasnikov <[email protected]>
1 parent 46c6b87 commit aca852f

File tree

9 files changed

+2282
-8
lines changed

9 files changed

+2282
-8
lines changed

internal/conn/conn.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package conn
33
import (
44
"context"
55
"fmt"
6+
"io"
67
"sync"
78
"sync/atomic"
89
"time"
@@ -54,10 +55,16 @@ type (
5455
DialTimeout() time.Duration
5556
GrpcDialOptions() []grpc.DialOption
5657
}
58+
grpcClientConnInterface interface {
59+
grpc.ClientConnInterface
60+
io.Closer
61+
62+
GetState() connectivity.State
63+
}
5764
conn struct {
5865
mtx sync.RWMutex
5966
config connConfig // ro access
60-
grpcConn *grpc.ClientConn
67+
grpcConn grpcClientConnInterface
6168
done chan struct{}
6269
endpoint endpoint.Endpoint // ro access
6370
closed bool
@@ -184,7 +191,7 @@ func (c *conn) GetState() (s State) {
184191
return State(c.state.Load())
185192
}
186193

187-
func (c *conn) realConn(ctx context.Context) (cc *grpc.ClientConn, err error) {
194+
func (c *conn) realConn(ctx context.Context) (cc grpcClientConnInterface, err error) {
188195
if c.isClosed() {
189196
return nil, xerrors.WithStackTrace(errClosedConnection)
190197
}
@@ -200,7 +207,7 @@ func (c *conn) realConn(ctx context.Context) (cc *grpc.ClientConn, err error) {
200207
}
201208

202209
// c.mtx must be locked
203-
func (c *conn) dial(ctx context.Context) (cc *grpc.ClientConn, err error) {
210+
func (c *conn) dial(ctx context.Context) (cc grpcClientConnInterface, err error) {
204211
onDone := trace.DriverOnConnDial(
205212
c.config.Trace(), &ctx,
206213
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/conn.(*conn).dial"),
@@ -259,7 +266,7 @@ func (c *conn) onTransportError(ctx context.Context, cause error) {
259266
}
260267
}
261268

262-
func isAvailable(raw *grpc.ClientConn) bool {
269+
func isAvailable(raw grpcClientConnInterface) bool {
263270
return raw != nil && raw.GetState() == connectivity.Ready
264271
}
265272

@@ -453,7 +460,7 @@ func (c *conn) Invoke(
453460
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/conn.(*conn).Invoke"),
454461
c.endpoint, trace.Method(method),
455462
)
456-
cc *grpc.ClientConn
463+
cc grpcClientConnInterface
457464
md = metadata.MD{}
458465
)
459466
defer func() {

0 commit comments

Comments
 (0)