config: add a read limit option to the connection.

By default, the read limit is never set by NewConnection.
When using the default pool dialer, a read limit of 512KB is set.
When the read limit option is set, all sockets passed to NewConnection have that read limit set.
This commit is contained in:
Jay
2026-08-10 12:16:23 -04:00
parent 3ea8810f7c
commit 19810798a7
6 changed files with 71 additions and 1 deletions
+33
View File
@@ -108,6 +108,39 @@ func TestNewConnection(t *testing.T) {
}
}
func TestNewConnection_ReadLimit(t *testing.T) {
socket, _, _ := honeybeetest.SetupTestSocket(t)
var limitWasSet bool
var setLimit int64
socket.SetReadLimitFunc = func(limit int64) {
limitWasSet = true
setLimit = limit
}
// when ReadLimit is nil, SetReadLimit should not be called
config, _ := NewConnectionConfig()
NewConnection(context.Background(), socket, config, nil)
assert.False(t, limitWasSet)
// when ReadLimit is set to zero, SetReadLimit should be called
config, _ = NewConnectionConfig(
WithReadLimit(0),
)
NewConnection(context.Background(), socket, config, nil)
assert.True(t, limitWasSet)
assert.Equal(t, int64(0), setLimit)
// when ReadLimit is set to a positive value, SetReadLimit should be called
limitWasSet = false
config, _ = NewConnectionConfig(
WithReadLimit(100),
)
NewConnection(context.Background(), socket, config, nil)
assert.True(t, limitWasSet)
assert.Equal(t, int64(100), setLimit)
}
// ----------------------------------------------------------------------------
// Accessors
// ----------------------------------------------------------------------------