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

Function TestMergeRemoveMissing

pkg/ring/merge_test.go:388–453  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

386}
387
388func TestMergeRemoveMissing(t *testing.T) {
389 now := time.Now().Unix()
390
391 firstRing := func() *Desc {
392 return &Desc{
393 Ingesters: map[string]InstanceDesc{
394 "Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 50}},
395 "Ing 2": {Addr: "addr2", Timestamp: now, State: JOINING, Tokens: []uint32{5, 10, 20, 100, 200}},
396 "Ing 3": {Addr: "addr3", Timestamp: now, State: LEAVING, Tokens: []uint32{5, 10, 20, 100, 200}},
397 },
398 }
399 }
400
401 secondRing := func() *Desc {
402 return &Desc{
403 Ingesters: map[string]InstanceDesc{
404 "Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 50}},
405 "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}},
406 },
407 }
408 }
409
410 expectedFirstSecondMerge := func() *Desc {
411 return &Desc{
412 Ingesters: map[string]InstanceDesc{
413 "Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 50}},
414 "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}},
415 "Ing 3": {Addr: "addr3", Timestamp: now + 3, State: LEFT}, // When deleting, time depends on value passed to merge function.
416 },
417 }
418 }
419
420 {
421 our, ch := mergeLocalCAS(firstRing(), secondRing(), now+3)
422 assert.Equal(t, expectedFirstSecondMerge(), our)
423 assert.Equal(t, &Desc{
424 Ingesters: map[string]InstanceDesc{
425 "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}},
426 "Ing 3": {Addr: "addr3", Timestamp: now + 3, State: LEFT}, // When deleting, time depends on value passed to merge function.
427 },
428 }, ch) // entire second ring is new
429 }
430
431 { // idempotency: (no change after applying same ring again, even if time has advanced)
432 our, ch := mergeLocalCAS(expectedFirstSecondMerge(), secondRing(), now+10)
433 assert.Equal(t, expectedFirstSecondMerge(), our)
434 assert.Equal(t, (*Desc)(nil), ch)
435 }
436
437 { // commutativity is broken when deleting missing entries. But let's make sure we get reasonable results at least.
438 our, ch := mergeLocalCAS(secondRing(), firstRing(), now+3)
439 assert.Equal(t, &Desc{
440 Ingesters: map[string]InstanceDesc{
441 "Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 50}},
442 "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}},
443 "Ing 3": {Addr: "addr3", Timestamp: now, State: LEAVING},
444 },
445 }, our)

Callers

nothing calls this directly

Calls 2

mergeLocalCASFunction · 0.85
EqualMethod · 0.65

Tested by

no test coverage detected