Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: keep client default client read limit when realtime doesn't specify #631

Merged
merged 8 commits into from
Feb 2, 2024
41 changes: 41 additions & 0 deletions ably/realtime_channel_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,47 @@ func TestRealtimeChannel_ShouldSetProvidedReadLimit(t *testing.T) {
assert.Equal(t, int64(2048), client.Connection.ReadLimit())
}

func TestRealtimeChannel_SetsNoLimitIfServerNoLimits(t *testing.T) {
AndyTWF marked this conversation as resolved.
Show resolved Hide resolved
// Mock out the dial
dial := DialFunc(func(p string, url *url.URL, timeout time.Duration) (ably.Conn, error) {
sacOO7 marked this conversation as resolved.
Show resolved Hide resolved
return connMock{
SendFunc: func(m *ably.ProtocolMessage) error {
return nil
},
ReceiveFunc: func(deadline time.Time) (*ably.ProtocolMessage, error) {
connDetails := ably.ConnectionDetails{
ClientID: "id1",
ConnectionKey: "foo",
MaxFrameSize: 12,
MaxInboundRate: 14,
MaxMessageSize: 0,
ConnectionStateTTL: ably.DurationFromMsecs(time.Minute * 2),
MaxIdleInterval: ably.DurationFromMsecs(time.Second),
}

return &ably.ProtocolMessage{
Action: ably.ActionConnected,
ConnectionID: "connection-id-1",
ConnectionDetails: &connDetails,
}, nil
},
CloseFunc: func() error {
return nil
},
}, nil
})

_, c := ablytest.NewRealtime(ably.WithDial(dial))

// Wait for a little bit for things to settle
time.Sleep(1 * time.Second)
AndyTWF marked this conversation as resolved.
Show resolved Hide resolved

// Check that the connection read limit is the default - due to websocket.go
// Only allowing the value to be set if the connection is a certain type
// We'll just check -1 here
assert.Equal(t, int64(-1), c.Connection.ReadLimit())
sacOO7 marked this conversation as resolved.
Show resolved Hide resolved
}

func TestRealtimeChannel_ShouldReturnErrorIfReadLimitExceeded(t *testing.T) {
app, client1 := ablytest.NewRealtime(ably.WithEchoMessages(false))
defer safeclose(t, ablytest.FullRealtimeCloser(client1), app)
Expand Down
2 changes: 1 addition & 1 deletion ably/realtime_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ func (c *Connection) eventloop() {
c.connStateTTL = connDetails.ConnectionStateTTL
// Spec RSA7b3, RSA7b4, RSA12a
c.auth.updateClientID(connDetails.ClientID)
if !c.isReadLimitSetExternally {
if !c.isReadLimitSetExternally && connDetails.MaxMessageSize > 0 {
c.readLimit = connDetails.MaxMessageSize // set MaxMessageSize limit as per TO3l8
}
}
Expand Down
Loading