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:
@@ -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
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user