Updated name.
This commit is contained in:
+6
-6
@@ -47,7 +47,7 @@ func ValidateWorkerConfig(config *WorkerConfig) error {
|
||||
if err := validateMaxQueueSize(config.MaxQueueSize); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateDeadTimeout(config.InactivityTimeout); err != nil {
|
||||
if err := validateInactivityTimeout(config.InactivityTimeout); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@@ -60,9 +60,9 @@ func validateMaxQueueSize(value int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateDeadTimeout(value time.Duration) error {
|
||||
func validateInactivityTimeout(value time.Duration) error {
|
||||
if value < 0 {
|
||||
return InvalidDeadTimeout
|
||||
return InvalidInactivityTimeout
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -78,10 +78,10 @@ func WithMaxQueueSize(value int) WorkerOption {
|
||||
}
|
||||
}
|
||||
|
||||
// When DeadTimeout is zero, the watchdog is disabled.
|
||||
func WithDeadTimeout(value time.Duration) WorkerOption {
|
||||
// When InactivityTimeout is zero, the watchdog is disabled.
|
||||
func WithInactivityTimeout(value time.Duration) WorkerOption {
|
||||
return func(c *WorkerConfig) error {
|
||||
if err := validateDeadTimeout(value); err != nil {
|
||||
if err := validateInactivityTimeout(value); err != nil {
|
||||
return err
|
||||
}
|
||||
c.InactivityTimeout = value
|
||||
|
||||
@@ -33,11 +33,11 @@ func TestValidateWorkerConfig(t *testing.T) {
|
||||
conf: *GetDefaultWorkerConfig(),
|
||||
},
|
||||
{
|
||||
name: "zero dead timeout disabled",
|
||||
name: "zero inactivity timeout disabled",
|
||||
conf: WorkerConfig{InactivityTimeout: 0},
|
||||
},
|
||||
{
|
||||
name: "positive dead timeout",
|
||||
name: "positive inactivity timeout",
|
||||
conf: WorkerConfig{InactivityTimeout: 30 * time.Second},
|
||||
},
|
||||
{
|
||||
@@ -46,9 +46,9 @@ func TestValidateWorkerConfig(t *testing.T) {
|
||||
wantErr: InvalidMaxQueueSize,
|
||||
},
|
||||
{
|
||||
name: "negative dead timeout",
|
||||
name: "negative inactivity timeout",
|
||||
conf: WorkerConfig{InactivityTimeout: -1 * time.Second},
|
||||
wantErr: InvalidDeadTimeout,
|
||||
wantErr: InvalidInactivityTimeout,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -78,18 +78,18 @@ func TestWithMaxQueueSize(t *testing.T) {
|
||||
assert.ErrorIs(t, err, InvalidMaxQueueSize)
|
||||
}
|
||||
|
||||
func TestWithDeadTimeout(t *testing.T) {
|
||||
func TestWithInactivityTimeout(t *testing.T) {
|
||||
conf := &WorkerConfig{}
|
||||
|
||||
err := applyWorkerOptions(conf, WithDeadTimeout(30*time.Second))
|
||||
err := applyWorkerOptions(conf, WithInactivityTimeout(30*time.Second))
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 30*time.Second, conf.InactivityTimeout)
|
||||
|
||||
err = applyWorkerOptions(conf, WithDeadTimeout(0))
|
||||
err = applyWorkerOptions(conf, WithInactivityTimeout(0))
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = applyWorkerOptions(conf, WithDeadTimeout(-1*time.Second))
|
||||
assert.ErrorIs(t, err, InvalidDeadTimeout)
|
||||
err = applyWorkerOptions(conf, WithInactivityTimeout(-1*time.Second))
|
||||
assert.ErrorIs(t, err, InvalidInactivityTimeout)
|
||||
}
|
||||
|
||||
func TestNewPoolConfig(t *testing.T) {
|
||||
|
||||
+2
-2
@@ -10,6 +10,6 @@ var (
|
||||
ErrPeerExists = errors.New("peer already exists")
|
||||
|
||||
// Config errors
|
||||
InvalidMaxQueueSize = errors.New("maximum queue size cannot be negative")
|
||||
InvalidDeadTimeout = errors.New("dead timeout cannot be negative")
|
||||
InvalidMaxQueueSize = errors.New("maximum queue size cannot be negative")
|
||||
InvalidInactivityTimeout = errors.New("inactivity timeout cannot be negative")
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user