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

Function TestIngester_shipBlocks

pkg/ingester/ingester_test.go:4616–4672  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

4614}
4615
4616func TestIngester_shipBlocks(t *testing.T) {
4617 testCases := map[string]struct {
4618 ss bucketindex.Status
4619 expectetNumberOfCall int
4620 }{
4621 "should ship blocks if status ok": {
4622 ss: bucketindex.Status{Version: bucketindex.IndexVersion1, Status: bucketindex.Ok},
4623 expectetNumberOfCall: 1,
4624 },
4625 "should not ship on cmk errors": {
4626 ss: bucketindex.Status{Version: bucketindex.IndexVersion1, Status: bucketindex.CustomerManagedKeyError},
4627 expectetNumberOfCall: 0,
4628 },
4629 }
4630
4631 for name, tc := range testCases {
4632 t.Run(name, func(t *testing.T) {
4633
4634 cfg := defaultIngesterTestConfig(t)
4635 cfg.LifecyclerConfig.JoinAfter = 0
4636 cfg.BlocksStorageConfig.TSDB.ShipConcurrency = 2
4637
4638 // Create ingester
4639 i, err := prepareIngesterWithBlocksStorage(t, cfg, prometheus.NewRegistry())
4640 require.NoError(t, err)
4641 require.NoError(t, services.StartAndAwaitRunning(context.Background(), i))
4642 defer services.StopAndAwaitTerminated(context.Background(), i) //nolint:errcheck
4643
4644 // Wait until it's ACTIVE
4645 test.Poll(t, 1*time.Second, ring.ACTIVE, func() any {
4646 return i.lifecycler.GetState()
4647 })
4648
4649 // Create the TSDB for 3 users and then replace the shipper with the mocked one
4650 mocks := []*shipperMock{}
4651 for _, userID := range []string{"user-1", "user-2", "user-3"} {
4652 bucketindex.WriteSyncStatus(context.Background(), i.TSDBState.bucket, userID, tc.ss, log.NewNopLogger())
4653 userDB, err := i.getOrCreateTSDB(userID, false)
4654 require.NoError(t, err)
4655 require.NotNil(t, userDB)
4656
4657 m := &shipperMock{}
4658 m.On("Sync", mock.Anything).Return(0, nil)
4659 mocks = append(mocks, m)
4660
4661 userDB.shipper = m
4662 }
4663
4664 // Ship blocks and assert on the mocked shipper
4665 i.shipBlocks(context.Background(), nil)
4666
4667 for _, m := range mocks {
4668 m.AssertNumberOfCalls(t, "Sync", tc.expectetNumberOfCall)
4669 }
4670 })
4671 }
4672}
4673

Callers

nothing calls this directly

Calls 10

StartAndAwaitRunningFunction · 0.92
StopAndAwaitTerminatedFunction · 0.92
PollFunction · 0.92
WriteSyncStatusFunction · 0.92
getOrCreateTSDBMethod · 0.80
shipBlocksMethod · 0.80
RunMethod · 0.65
GetStateMethod · 0.45

Tested by

no test coverage detected