MCPcopy
hub / github.com/grafana/dskit / TestRing_Get_NoMemoryAllocations

Function TestRing_Get_NoMemoryAllocations

ring/ring_test.go:3851–3868  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3849}
3850
3851func TestRing_Get_NoMemoryAllocations(t *testing.T) {
3852 // Initialise the ring.
3853 ringDesc := &Desc{Ingesters: generateRingInstances(initTokenGenerator(t), 3, 3, 128)}
3854 ring := newRingForTesting(Config{HeartbeatTimeout: time.Hour, ZoneAwarenessEnabled: true, SubringCacheDisabled: true, ReplicationFactor: 3}, true)
3855 ring.setRingStateFromDesc(ringDesc, false, false, false)
3856
3857 buf, bufHosts, bufZones := MakeBuffersForGet()
3858 r := rand.New(rand.NewSource(time.Now().UnixNano()))
3859
3860 numAllocs := testing.AllocsPerRun(10, func() {
3861 set, err := ring.Get(r.Uint32(), Write, buf, bufHosts, bufZones)
3862 if err != nil || len(set.Instances) != 3 {
3863 t.Fail()
3864 }
3865 })
3866
3867 assert.Equal(t, float64(0), numAllocs)
3868}
3869
3870// generateTokensLinear returns tokens with a linear distribution.
3871func generateTokensLinear(instanceID, numInstances, numTokens int) []uint32 {

Callers

nothing calls this directly

Calls 8

generateRingInstancesFunction · 0.85
initTokenGeneratorFunction · 0.85
newRingForTestingFunction · 0.85
MakeBuffersForGetFunction · 0.85
setRingStateFromDescMethod · 0.80
FailMethod · 0.80
GetMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected