Skip to content

Commit 4b6ac35

Browse files
committed
fix compactor tests
Signed-off-by: Ben Ye <[email protected]>
1 parent 1dc2400 commit 4b6ac35

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

pkg/compactor/compactor_test.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"encoding/json"
88
"flag"
99
"fmt"
10+
"github.com/thanos-io/thanos/pkg/block"
1011
"os"
1112
"path"
1213
"path/filepath"
@@ -458,7 +459,7 @@ func TestCompactor_ShouldIncrementCompactionErrorIfFailedToCompactASingleTenant(
458459
userID := "test-user"
459460
bucketClient := &bucket.ClientMock{}
460461
bucketClient.MockIter("", []string{userID}, nil)
461-
bucketClient.MockIter(userID+"/", []string{userID + "/01DTVP434PA9VFXSW2JKB3392D", userID + "/01FN6CDF3PNEWWRY5MPGJPE3EX"}, nil)
462+
bucketClient.MockIter(userID+"/", []string{userID + "/01DTVP434PA9VFXSW2JKB3392D/meta.json", userID + "/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
462463
bucketClient.MockIter(userID+"/markers/", nil, nil)
463464
bucketClient.MockExists(path.Join(userID, cortex_tsdb.TenantDeletionMarkPath), false, nil)
464465
bucketClient.MockGet(userID+"/01DTVP434PA9VFXSW2JKB3392D/meta.json", mockBlockMetaJSON("01DTVP434PA9VFXSW2JKB3392D"), nil)
@@ -512,8 +513,8 @@ func TestCompactor_ShouldIterateOverUsersAndRunCompaction(t *testing.T) {
512513
bucketClient.MockIter("", []string{"user-1", "user-2"}, nil)
513514
bucketClient.MockExists(path.Join("user-1", cortex_tsdb.TenantDeletionMarkPath), false, nil)
514515
bucketClient.MockExists(path.Join("user-2", cortex_tsdb.TenantDeletionMarkPath), false, nil)
515-
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX"}, nil)
516-
bucketClient.MockIter("user-2/", []string{"user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ", "user-2/01FN3V83ABR9992RF8WRJZ76ZQ"}, nil)
516+
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
517+
bucketClient.MockIter("user-2/", []string{"user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json", "user-2/01FN3V83ABR9992RF8WRJZ76ZQ/meta.json"}, nil)
517518
bucketClient.MockIter("user-1/markers/", nil, nil)
518519
bucketClient.MockIter("user-2/markers/", nil, nil)
519520
bucketClient.MockGet("user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", mockBlockMetaJSON("01DTVP434PA9VFXSW2JKB3392D"), nil)
@@ -767,8 +768,8 @@ func TestCompactor_ShouldNotCompactBlocksMarkedForSkipCompact(t *testing.T) {
767768
bucketClient.MockIter("", []string{"user-1", "user-2"}, nil)
768769
bucketClient.MockExists(path.Join("user-1", cortex_tsdb.TenantDeletionMarkPath), false, nil)
769770
bucketClient.MockExists(path.Join("user-2", cortex_tsdb.TenantDeletionMarkPath), false, nil)
770-
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX"}, nil)
771-
bucketClient.MockIter("user-2/", []string{"user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ", "user-2/01FN3V83ABR9992RF8WRJZ76ZQ"}, nil)
771+
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
772+
bucketClient.MockIter("user-2/", []string{"user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json", "user-2/01FN3V83ABR9992RF8WRJZ76ZQ/meta.json"}, nil)
772773
bucketClient.MockIter("user-1/markers/", nil, nil)
773774
bucketClient.MockIter("user-2/markers/", nil, nil)
774775
bucketClient.MockGet("user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", mockBlockMetaJSON("01DTVP434PA9VFXSW2JKB3392D"), nil)
@@ -998,8 +999,8 @@ func TestCompactor_ShouldCompactAllUsersOnShardingEnabledButOnlyOneInstanceRunni
998999
bucketClient.MockIter("", []string{"user-1", "user-2"}, nil)
9991000
bucketClient.MockExists(path.Join("user-1", cortex_tsdb.TenantDeletionMarkPath), false, nil)
10001001
bucketClient.MockExists(path.Join("user-2", cortex_tsdb.TenantDeletionMarkPath), false, nil)
1001-
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX"}, nil)
1002-
bucketClient.MockIter("user-2/", []string{"user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ", "user-2/01FN3V83ABR9992RF8WRJZ76ZQ"}, nil)
1002+
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
1003+
bucketClient.MockIter("user-2/", []string{"user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json", "user-2/01FN3V83ABR9992RF8WRJZ76ZQ/meta.json"}, nil)
10031004
bucketClient.MockIter("user-1/markers/", nil, nil)
10041005
bucketClient.MockIter("user-2/markers/", nil, nil)
10051006
bucketClient.MockGet("user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", mockBlockMetaJSON("01DTVP434PA9VFXSW2JKB3392D"), nil)
@@ -1203,7 +1204,7 @@ func TestCompactor_ShouldCompactOnlyShardsOwnedByTheInstanceOnShardingEnabledWit
12031204
// Keys with a value greater than 1 will be groups that should be compacted
12041205
groupHashes := make(map[uint32]int)
12051206
for _, userID := range userIDs {
1206-
blockDirectory := []string{}
1207+
blockFiles := []string{}
12071208

12081209
for blockID, blockTimes := range blocks {
12091210
blockVisitMarker := BlockVisitMarker{
@@ -1218,14 +1219,15 @@ func TestCompactor_ShouldCompactOnlyShardsOwnedByTheInstanceOnShardingEnabledWit
12181219
bucketClient.MockGet(userID+"/"+blockID+"/visit-mark.json", string(visitMarkerFileContent), nil)
12191220
bucketClient.MockGetRequireUpload(userID+"/"+blockID+"/visit-mark.json", string(visitMarkerFileContent), nil)
12201221
bucketClient.MockUpload(userID+"/"+blockID+"/visit-mark.json", nil)
1221-
blockDirectory = append(blockDirectory, userID+"/"+blockID)
1222+
// Iter with recursive so expected to get objects rather than directories.
1223+
blockFiles = append(blockFiles, path.Join(userID, blockID, block.MetaFilename))
12221224

12231225
// Get all of the unique group hashes so that they can be used to ensure all groups were compacted
12241226
groupHash := hashGroup(userID, blockTimes["startTime"], blockTimes["endTime"])
12251227
groupHashes[groupHash]++
12261228
}
12271229

1228-
bucketClient.MockIter(userID+"/", blockDirectory, nil)
1230+
bucketClient.MockIter(userID+"/", blockFiles, nil)
12291231
bucketClient.MockIter(userID+"/markers/", nil, nil)
12301232
bucketClient.MockExists(path.Join(userID, cortex_tsdb.TenantDeletionMarkPath), false, nil)
12311233
bucketClient.MockGet(userID+"/bucket-index.json.gz", "", nil)

0 commit comments

Comments
 (0)