MCPcopy Index your code
hub / github.com/cortexproject/cortex / Test_LoadPartialGroups

Function Test_LoadPartialGroups

pkg/ruler/ruler_test.go:2455–2530  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2453}
2454
2455func Test_LoadPartialGroups(t *testing.T) {
2456 const (
2457 user1 = "user1"
2458 user2 = "user2"
2459 user3 = "user3"
2460 )
2461
2462 const (
2463 ruler1 = "ruler-1"
2464 ruler1Host = "1.1.1.1"
2465 ruler1Port = 9999
2466 )
2467
2468 user1Group1 := &rulespb.RuleGroupDesc{User: user1, Namespace: "namespace", Name: "first", Interval: time.Minute}
2469 user1Group2 := &rulespb.RuleGroupDesc{User: user1, Namespace: "namespace", Name: "second", Interval: time.Minute}
2470 user2Group1 := &rulespb.RuleGroupDesc{User: user2, Namespace: "namespace", Name: "first", Interval: time.Minute}
2471 user3Group1 := &rulespb.RuleGroupDesc{User: user3, Namespace: "namespace", Name: "first", Interval: time.Minute}
2472
2473 allRules := map[string]rulespb.RuleGroupList{
2474 user1: {user1Group1, user1Group2},
2475 user2: {user2Group1},
2476 user3: {user3Group1},
2477 }
2478
2479 kvStore, closer := consul.NewInMemoryClient(ring.GetCodec(), log.NewNopLogger(), nil)
2480 t.Cleanup(func() { assert.NoError(t, closer.Close()) })
2481
2482 store := newMockRuleStore(allRules, map[string]error{user1: fmt.Errorf("test")})
2483 u, _ := url.Parse("")
2484 cfg := Config{
2485 RulePath: t.TempDir(),
2486 EnableSharding: true,
2487 ExternalURL: flagext.URLValue{URL: u},
2488 PollInterval: time.Millisecond * 100,
2489 RingCheckPeriod: time.Minute,
2490 ShardingStrategy: util.ShardingStrategyShuffle,
2491 Ring: RingConfig{
2492 InstanceID: ruler1,
2493 InstanceAddr: ruler1Host,
2494 InstancePort: ruler1Port,
2495 KVStore: kv.Config{
2496 Mock: kvStore,
2497 },
2498 HeartbeatTimeout: 1 * time.Minute,
2499 ReplicationFactor: 1,
2500 },
2501 FlushCheckPeriod: 0,
2502 }
2503
2504 r1, manager := buildRuler(t, cfg, nil, store, nil)
2505 r1.limits = &ruleLimits{tenantShard: 1}
2506
2507 require.NoError(t, services.StartAndAwaitRunning(context.Background(), r1))
2508 t.Cleanup(r1.StopAsync)
2509
2510 err := kvStore.CAS(context.Background(), ringKey, func(in any) (out any, retry bool, err error) {
2511 d, _ := in.(*ring.Desc)
2512 if d == nil {

Callers

nothing calls this directly

Calls 14

NewInMemoryClientFunction · 0.92
GetCodecFunction · 0.92
StartAndAwaitRunningFunction · 0.92
NewDescFunction · 0.92
PollFunction · 0.92
newMockRuleStoreFunction · 0.85
buildRulerFunction · 0.85
ParseMethod · 0.80
AddIngesterMethod · 0.80
listRulesMethod · 0.80
CloseMethod · 0.65
CASMethod · 0.65

Tested by

no test coverage detected