MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestRing_Get_NoMemoryAllocations

Function TestRing_Get_NoMemoryAllocations

pkg/ring/ring_test.go:2855–2882  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2853}
2854
2855func TestRing_Get_NoMemoryAllocations(t *testing.T) {
2856 // Initialise the ring.
2857 ringDesc := &Desc{Ingesters: generateRingInstances(3, 3, 128)}
2858 ring := Ring{
2859 cfg: Config{HeartbeatTimeout: time.Hour, ZoneAwarenessEnabled: true, SubringCacheDisabled: true, ReplicationFactor: 3},
2860 ringDesc: ringDesc,
2861 ringTokens: ringDesc.GetTokens(),
2862 ringTokensByZone: ringDesc.getTokensByZone(),
2863 ringInstanceByToken: ringDesc.getTokensInfo(),
2864 ringZones: getZones(ringDesc.getTokensByZone()),
2865 shuffledSubringCache: map[subringCacheKey]*Ring{},
2866 strategy: NewDefaultReplicationStrategy(),
2867 lastTopologyChange: time.Now(),
2868 KVClient: &MockClient{},
2869 }
2870
2871 buf, bufHosts, bufZones := MakeBuffersForGet()
2872 r := rand.New(rand.NewSource(time.Now().UnixNano()))
2873
2874 numAllocs := testing.AllocsPerRun(10, func() {
2875 set, err := ring.Get(r.Uint32(), Write, buf, bufHosts, bufZones)
2876 if err != nil || len(set.Instances) != 3 {
2877 t.Fail()
2878 }
2879 })
2880
2881 assert.Equal(t, float64(0), numAllocs)
2882}
2883
2884// generateTokensLinear returns tokens with a linear distribution.
2885func generateTokensLinear(instanceID, numInstances, numTokens int) []uint32 {

Callers

nothing calls this directly

Calls 9

GetTokensMethod · 0.95
getTokensByZoneMethod · 0.95
getTokensInfoMethod · 0.95
GetMethod · 0.95
generateRingInstancesFunction · 0.85
getZonesFunction · 0.85
MakeBuffersForGetFunction · 0.85
EqualMethod · 0.65

Tested by

no test coverage detected