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

Function TestCompactor_DeleteLocalSyncFiles

pkg/compactor/compactor_test.go:1782–1864  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1780}
1781
1782func TestCompactor_DeleteLocalSyncFiles(t *testing.T) {
1783 numUsers := 10
1784
1785 // Setup user IDs
1786 userIDs := make([]string, 0, numUsers)
1787 for i := 1; i <= numUsers; i++ {
1788 userIDs = append(userIDs, fmt.Sprintf("user-%d", i))
1789 }
1790
1791 inmem := objstore.WithNoopInstr(objstore.NewInMemBucket())
1792 for _, userID := range userIDs {
1793 id, err := ulid.New(ulid.Now(), rand.Reader)
1794 require.NoError(t, err)
1795 require.NoError(t, inmem.Upload(context.Background(), userID+"/"+id.String()+"/meta.json", strings.NewReader(mockBlockMetaJSON(id.String()))))
1796 }
1797
1798 // Create a shared KV Store
1799 kvstore, closer := consul.NewInMemoryClient(ring.GetCodec(), log.NewNopLogger(), nil)
1800 t.Cleanup(func() { assert.NoError(t, closer.Close()) })
1801
1802 // Create two compactors
1803 var compactors []*Compactor
1804
1805 for i := 1; i <= 2; i++ {
1806 cfg := prepareConfig()
1807
1808 cfg.ShardingEnabled = true
1809 cfg.ShardingRing.InstanceID = fmt.Sprintf("compactor-%d", i)
1810 cfg.ShardingRing.InstanceAddr = fmt.Sprintf("127.0.0.%d", i)
1811 cfg.ShardingRing.WaitStabilityMinDuration = time.Second
1812 cfg.ShardingRing.WaitStabilityMaxDuration = 5 * time.Second
1813 cfg.ShardingRing.KVStore.Mock = kvstore
1814
1815 // Each compactor will get its own temp dir for storing local files.
1816 c, _, tsdbPlanner, _, _ := prepare(t, cfg, inmem, nil)
1817 t.Cleanup(func() {
1818 require.NoError(t, services.StopAndAwaitTerminated(context.Background(), c))
1819 })
1820
1821 compactors = append(compactors, c)
1822
1823 // Mock the planner as if there's no compaction to do,
1824 // in order to simplify tests (all in all, we just want to
1825 // test our logic and not TSDB compactor which we expect to
1826 // be already tested).
1827 tsdbPlanner.On("Plan", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]*metadata.Meta{}, nil)
1828 }
1829
1830 require.Equal(t, 2, len(compactors))
1831 c1 := compactors[0]
1832 c2 := compactors[1]
1833
1834 // Start first compactor
1835 require.NoError(t, services.StartAndAwaitRunning(context.Background(), c1))
1836
1837 // Wait until a run has been completed on first compactor. This happens as soon as compactor starts.
1838 cortex_testutil.Poll(t, 10*time.Second, 1.0, func() any {
1839 return prom_testutil.ToFloat64(c1.CompactionRunsCompleted)

Callers

nothing calls this directly

Calls 14

NewInMemoryClientFunction · 0.92
GetCodecFunction · 0.92
StopAndAwaitTerminatedFunction · 0.92
StartAndAwaitRunningFunction · 0.92
mockBlockMetaJSONFunction · 0.85
compactUsersMethod · 0.80
prepareConfigFunction · 0.70
prepareFunction · 0.70
StringMethod · 0.65
CloseMethod · 0.65
EqualMethod · 0.65
UploadMethod · 0.45

Tested by

no test coverage detected