github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/pkg/compactor/compactor_ring_test.go (about)

     1  package compactor
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/grafana/dskit/flagext"
     8  	"github.com/grafana/dskit/ring"
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestRingConfig_DefaultConfigToLifecyclerConfig(t *testing.T) {
    13  	cfg := RingConfig{}
    14  	expected := ring.LifecyclerConfig{}
    15  	flagext.DefaultValues(&cfg, &expected)
    16  
    17  	// The default config of the compactor ring must be the exact same
    18  	// of the default lifecycler config, except few options which are
    19  	// intentionally overridden
    20  	expected.ListenPort = cfg.ListenPort
    21  	expected.RingConfig.ReplicationFactor = 1
    22  	expected.RingConfig.SubringCacheDisabled = true
    23  	expected.NumTokens = 512
    24  	expected.MinReadyDuration = 0
    25  	expected.FinalSleep = 0
    26  
    27  	assert.Equal(t, expected, cfg.ToLifecyclerConfig())
    28  }
    29  
    30  func TestRingConfig_CustomConfigToLifecyclerConfig(t *testing.T) {
    31  	cfg := RingConfig{}
    32  	expected := ring.LifecyclerConfig{}
    33  	flagext.DefaultValues(&cfg, &expected)
    34  
    35  	// Customize the compactor ring config
    36  	cfg.HeartbeatPeriod = 1 * time.Second
    37  	cfg.HeartbeatTimeout = 10 * time.Second
    38  	cfg.InstanceID = "test"
    39  	cfg.InstanceInterfaceNames = []string{"abc1"}
    40  	cfg.InstancePort = 10
    41  	cfg.InstanceAddr = "1.2.3.4"
    42  	cfg.ListenPort = 10
    43  
    44  	// The lifecycler config should be generated based upon the compactor
    45  	// ring config
    46  	expected.HeartbeatPeriod = cfg.HeartbeatPeriod
    47  	expected.RingConfig.HeartbeatTimeout = cfg.HeartbeatTimeout
    48  	expected.RingConfig.SubringCacheDisabled = true
    49  	expected.ID = cfg.InstanceID
    50  	expected.InfNames = cfg.InstanceInterfaceNames
    51  	expected.Port = cfg.InstancePort
    52  	expected.Addr = cfg.InstanceAddr
    53  	expected.ListenPort = cfg.ListenPort
    54  
    55  	// Hardcoded config
    56  	expected.RingConfig.ReplicationFactor = 1
    57  	expected.NumTokens = 512
    58  	expected.MinReadyDuration = 0
    59  	expected.FinalSleep = 0
    60  
    61  	assert.Equal(t, expected, cfg.ToLifecyclerConfig())
    62  }