Skip to content

Commit a408ea2

Browse files
committed
rename, add test
1 parent 806a727 commit a408ea2

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ func extractUnidirectionalDisconnect(err error) Disconnect {
330330
}
331331
}
332332

333-
// UnidirectionalConnect supposed to be called only from a unidirectional transport layer
333+
// Connect supposed to be called only from a unidirectional transport layer
334334
// to pass initial information about connection and thus initiate Node.OnConnecting
335335
// event. Bidirectional transport initiate connecting workflow automatically
336336
// since client passes Connect command upon successful connection establishment
@@ -343,8 +343,8 @@ func (c *Client) Connect(req ConnectRequest) {
343343

344344
// ConnectNoDisconnect is the same as Client.Connect but does not try to extract Disconnect
345345
// code from the error returned by the connect logic, instead it just returns the error
346-
// to the caller. This error must be handled on the Transport level.
347-
func (c *Client) ConnectWithoutDisconnect(req ConnectRequest) error {
346+
// to the caller. This error must be handled by the caller on the Transport level.
347+
func (c *Client) ConnectNoDisconnect(req ConnectRequest) error {
348348
return c.unidirectionalConnect(req.toProto(), 0, false)
349349
}
350350

client_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3984,3 +3984,35 @@ func TestClientUnsubscribeDuringSubscribeCorrectChannels(t *testing.T) {
39843984
err := client.close(DisconnectForceNoReconnect)
39853985
require.NoError(t, err)
39863986
}
3987+
3988+
func TestClientConnectNoDisconnect(t *testing.T) {
3989+
t.Parallel()
3990+
errBoom := errors.New("boom")
3991+
3992+
testCases := []struct {
3993+
Name string
3994+
Err error
3995+
}{
3996+
{"nil", nil},
3997+
{"error", errBoom},
3998+
}
3999+
4000+
for _, tt := range testCases {
4001+
t.Run(tt.Name, func(t *testing.T) {
4002+
node := defaultTestNode()
4003+
defer func() { _ = node.Shutdown(context.Background()) }()
4004+
4005+
node.OnConnecting(func(context.Context, ConnectEvent) (ConnectReply, error) {
4006+
return ConnectReply{}, tt.Err
4007+
})
4008+
transport := newTestTransport(func() {})
4009+
transport.setUnidirectional(true)
4010+
transport.sink = make(chan []byte, 100)
4011+
ctx := context.Background()
4012+
newCtx := SetCredentials(ctx, &Credentials{UserID: "42"})
4013+
client, _ := newClient(newCtx, node, transport)
4014+
err := client.ConnectNoDisconnect(ConnectRequest{})
4015+
require.Equal(t, tt.Err, err)
4016+
})
4017+
}
4018+
}

0 commit comments

Comments
 (0)