Skip to content
12 changes: 8 additions & 4 deletions configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,21 @@ func (o *Options) CheckDefaults() {
o.BucketingAPIURI = "https://bucketing-api.devcycle.com"
}

if o.EventFlushIntervalMS < time.Millisecond*500 || o.EventFlushIntervalMS > time.Minute*1 {
if o.EventFlushIntervalMS == 0 {
o.EventFlushIntervalMS = time.Second * 30
} else if o.EventFlushIntervalMS < time.Millisecond*500 || o.EventFlushIntervalMS > time.Minute {
util.Warnf("EventFlushIntervalMS cannot be less than 500ms or longer than 1 minute. Defaulting to 30 seconds.")
o.EventFlushIntervalMS = time.Second * 30
}
if o.ConfigPollingIntervalMS < time.Second*1 {
if o.ConfigPollingIntervalMS == 0 {
o.ConfigPollingIntervalMS = time.Second * 10
} else if o.ConfigPollingIntervalMS < time.Second {
util.Warnf("ConfigPollingIntervalMS cannot be less than 1 second. Defaulting to 10 seconds.")
o.ConfigPollingIntervalMS = time.Second * 10
Comment thread
jonathannorris marked this conversation as resolved.
}

if o.AdvancedOptions.OverrideMaxSSEPolling != 0 && o.AdvancedOptions.OverrideMaxSSEPolling < time.Second*1 {
o.AdvancedOptions.OverrideMaxSSEPolling = time.Second * 1
if o.AdvancedOptions.OverrideMaxSSEPolling != 0 && o.AdvancedOptions.OverrideMaxSSEPolling < time.Second {
o.AdvancedOptions.OverrideMaxSSEPolling = time.Second
}

if o.RequestTimeout <= time.Second*5 {
Expand Down
38 changes: 38 additions & 0 deletions configuration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package devcycle

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
)

func TestCheckDefaults_ZeroValues_AppliesDefaults(t *testing.T) {
o := &Options{}
o.CheckDefaults()

assert.Equal(t, time.Second*30, o.EventFlushIntervalMS)
assert.Equal(t, time.Second*10, o.ConfigPollingIntervalMS)
}
Comment on lines +10 to +16

func TestCheckDefaults_OutOfRange_AppliesDefaults(t *testing.T) {
o := &Options{
Comment on lines +16 to +19
EventFlushIntervalMS: 100 * time.Millisecond,
ConfigPollingIntervalMS: 500 * time.Millisecond,
}
o.CheckDefaults()

assert.Equal(t, time.Second*30, o.EventFlushIntervalMS)
assert.Equal(t, time.Second*10, o.ConfigPollingIntervalMS)
}

func TestCheckDefaults_ValidValues_Unchanged(t *testing.T) {
o := &Options{
EventFlushIntervalMS: time.Second * 10,
ConfigPollingIntervalMS: time.Second * 5,
}
o.CheckDefaults()

assert.Equal(t, time.Second*10, o.EventFlushIntervalMS)
assert.Equal(t, time.Second*5, o.ConfigPollingIntervalMS)
}
Loading