Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test non-empty StorageIDs #8698

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 35 additions & 28 deletions pkg/catalog/catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/treeverse/lakefs/pkg/block"
"github.com/treeverse/lakefs/pkg/catalog"
cUtils "github.com/treeverse/lakefs/pkg/catalog/testutils"
"github.com/treeverse/lakefs/pkg/config"
"github.com/treeverse/lakefs/pkg/graveler"
gUtils "github.com/treeverse/lakefs/pkg/graveler/testutil"
"github.com/treeverse/lakefs/pkg/testutil"
Expand Down Expand Up @@ -72,12 +73,12 @@ func TestCatalog_ListRepositories(t *testing.T) {
// prepare data tests
now := time.Now()
gravelerData := []*graveler.RepositoryRecord{
{RepositoryID: "re", Repository: &graveler.Repository{StorageID: "", StorageNamespace: "storageNS1", CreationDate: now, DefaultBranchID: "main1"}},
{RepositoryID: "repo1", Repository: &graveler.Repository{StorageID: "", StorageNamespace: "storageNS2", CreationDate: now, DefaultBranchID: "main2"}},
{RepositoryID: "repo2", Repository: &graveler.Repository{StorageID: "", StorageNamespace: "storageNS3", CreationDate: now, DefaultBranchID: "main3"}},
{RepositoryID: "repo22", Repository: &graveler.Repository{StorageID: "", StorageNamespace: "storageNS4", CreationDate: now, DefaultBranchID: "main4"}},
{RepositoryID: "repo23", Repository: &graveler.Repository{StorageID: "", StorageNamespace: "storageNS5", CreationDate: now, DefaultBranchID: "main5"}},
{RepositoryID: "repo3", Repository: &graveler.Repository{StorageID: "", StorageNamespace: "storageNS6", CreationDate: now, DefaultBranchID: "main6"}},
{RepositoryID: "re", Repository: &graveler.Repository{StorageID: config.SingleBlockstoreID, StorageNamespace: "storageNS1", CreationDate: now, DefaultBranchID: "main1"}},
{RepositoryID: "repo1", Repository: &graveler.Repository{StorageID: "sid1", StorageNamespace: "storageNS2", CreationDate: now, DefaultBranchID: "main2"}},
{RepositoryID: "repo2", Repository: &graveler.Repository{StorageID: "sid2", StorageNamespace: "storageNS3", CreationDate: now, DefaultBranchID: "main3"}},
{RepositoryID: "repo22", Repository: &graveler.Repository{StorageID: "sid2", StorageNamespace: "storageNS4", CreationDate: now, DefaultBranchID: "main4"}},
{RepositoryID: "repo23", Repository: &graveler.Repository{StorageID: "sid2", StorageNamespace: "storageNS5", CreationDate: now, DefaultBranchID: "main5"}},
{RepositoryID: "repo3", Repository: &graveler.Repository{StorageID: "sid3", StorageNamespace: "storageNS6", CreationDate: now, DefaultBranchID: "main6"}},
}
type args struct {
limit int
Expand All @@ -101,12 +102,12 @@ func TestCatalog_ListRepositories(t *testing.T) {
searchString: "",
},
want: []*catalog.Repository{
{Name: "re", StorageID: "", StorageNamespace: "storageNS1", DefaultBranch: "main1", CreationDate: now},
{Name: "repo1", StorageID: "", StorageNamespace: "storageNS2", DefaultBranch: "main2", CreationDate: now},
{Name: "repo2", StorageID: "", StorageNamespace: "storageNS3", DefaultBranch: "main3", CreationDate: now},
{Name: "repo22", StorageID: "", StorageNamespace: "storageNS4", DefaultBranch: "main4", CreationDate: now},
{Name: "repo23", StorageID: "", StorageNamespace: "storageNS5", DefaultBranch: "main5", CreationDate: now},
{Name: "repo3", StorageID: "", StorageNamespace: "storageNS6", DefaultBranch: "main6", CreationDate: now},
{Name: "re", StorageID: config.SingleBlockstoreID, StorageNamespace: "storageNS1", DefaultBranch: "main1", CreationDate: now},
{Name: "repo1", StorageID: "sid1", StorageNamespace: "storageNS2", DefaultBranch: "main2", CreationDate: now},
{Name: "repo2", StorageID: "sid2", StorageNamespace: "storageNS3", DefaultBranch: "main3", CreationDate: now},
{Name: "repo22", StorageID: "sid2", StorageNamespace: "storageNS4", DefaultBranch: "main4", CreationDate: now},
{Name: "repo23", StorageID: "sid2", StorageNamespace: "storageNS5", DefaultBranch: "main5", CreationDate: now},
{Name: "repo3", StorageID: "sid3", StorageNamespace: "storageNS6", DefaultBranch: "main6", CreationDate: now},
},
wantHasMore: false,
wantErr: false,
Expand All @@ -120,7 +121,7 @@ func TestCatalog_ListRepositories(t *testing.T) {
searchString: "",
},
want: []*catalog.Repository{
{Name: "re", StorageID: "", StorageNamespace: "storageNS1", DefaultBranch: "main1", CreationDate: now},
{Name: "re", StorageID: config.SingleBlockstoreID, StorageNamespace: "storageNS1", DefaultBranch: "main1", CreationDate: now},
},
wantHasMore: true,
wantErr: false,
Expand All @@ -134,7 +135,7 @@ func TestCatalog_ListRepositories(t *testing.T) {
searchString: "",
},
want: []*catalog.Repository{
{Name: "repo1", StorageID: "", StorageNamespace: "storageNS2", DefaultBranch: "main2", CreationDate: now},
{Name: "repo1", StorageID: "sid1", StorageNamespace: "storageNS2", DefaultBranch: "main2", CreationDate: now},
},
wantHasMore: true,
wantErr: false,
Expand All @@ -148,8 +149,8 @@ func TestCatalog_ListRepositories(t *testing.T) {
searchString: "",
},
want: []*catalog.Repository{
{Name: "repo2", StorageID: "", StorageNamespace: "storageNS3", DefaultBranch: "main3", CreationDate: now},
{Name: "repo22", StorageID: "", StorageNamespace: "storageNS4", DefaultBranch: "main4", CreationDate: now},
{Name: "repo2", StorageID: "sid2", StorageNamespace: "storageNS3", DefaultBranch: "main3", CreationDate: now},
{Name: "repo22", StorageID: "sid2", StorageNamespace: "storageNS4", DefaultBranch: "main4", CreationDate: now},
},
wantHasMore: true,
wantErr: false,
Expand All @@ -163,7 +164,7 @@ func TestCatalog_ListRepositories(t *testing.T) {
searchString: "",
},
want: []*catalog.Repository{
{Name: "repo1", StorageID: "", StorageNamespace: "storageNS2", DefaultBranch: "main2", CreationDate: now},
{Name: "repo1", StorageID: "sid1", StorageNamespace: "storageNS2", DefaultBranch: "main2", CreationDate: now},
},
wantHasMore: true,
wantErr: false,
Expand All @@ -177,8 +178,8 @@ func TestCatalog_ListRepositories(t *testing.T) {
searchString: "",
},
want: []*catalog.Repository{
{Name: "repo23", StorageID: "", StorageNamespace: "storageNS5", DefaultBranch: "main5", CreationDate: now},
{Name: "repo3", StorageID: "", StorageNamespace: "storageNS6", DefaultBranch: "main6", CreationDate: now},
{Name: "repo23", StorageID: "sid2", StorageNamespace: "storageNS5", DefaultBranch: "main5", CreationDate: now},
{Name: "repo3", StorageID: "sid3", StorageNamespace: "storageNS6", DefaultBranch: "main6", CreationDate: now},
},
wantHasMore: false,
wantErr: false,
Expand All @@ -192,9 +193,9 @@ func TestCatalog_ListRepositories(t *testing.T) {
searchString: "o2",
},
want: []*catalog.Repository{
{Name: "repo2", StorageID: "", StorageNamespace: "storageNS3", DefaultBranch: "main3", CreationDate: now},
{Name: "repo22", StorageID: "", StorageNamespace: "storageNS4", DefaultBranch: "main4", CreationDate: now},
{Name: "repo23", StorageID: "", StorageNamespace: "storageNS5", DefaultBranch: "main5", CreationDate: now},
{Name: "repo2", StorageID: "sid2", StorageNamespace: "storageNS3", DefaultBranch: "main3", CreationDate: now},
{Name: "repo22", StorageID: "sid2", StorageNamespace: "storageNS4", DefaultBranch: "main4", CreationDate: now},
{Name: "repo23", StorageID: "sid2", StorageNamespace: "storageNS5", DefaultBranch: "main5", CreationDate: now},
},
wantHasMore: false,
wantErr: false,
Expand All @@ -208,8 +209,8 @@ func TestCatalog_ListRepositories(t *testing.T) {
searchString: "o2",
},
want: []*catalog.Repository{
{Name: "repo2", StorageID: "", StorageNamespace: "storageNS3", DefaultBranch: "main3", CreationDate: now},
{Name: "repo22", StorageID: "", StorageNamespace: "storageNS4", DefaultBranch: "main4", CreationDate: now},
{Name: "repo2", StorageID: "sid2", StorageNamespace: "storageNS3", DefaultBranch: "main3", CreationDate: now},
{Name: "repo22", StorageID: "sid2", StorageNamespace: "storageNS4", DefaultBranch: "main4", CreationDate: now},
},
wantHasMore: true,
wantErr: false,
Expand All @@ -223,7 +224,7 @@ func TestCatalog_ListRepositories(t *testing.T) {
searchString: "o2",
},
want: []*catalog.Repository{
{Name: "repo23", StorageID: "", StorageNamespace: "storageNS5", DefaultBranch: "main5", CreationDate: now},
{Name: "repo23", StorageID: "sid2", StorageNamespace: "storageNS5", DefaultBranch: "main5", CreationDate: now},
},
wantHasMore: false,
wantErr: false,
Expand All @@ -237,8 +238,8 @@ func TestCatalog_ListRepositories(t *testing.T) {
searchString: "o2",
},
want: []*catalog.Repository{
{Name: "repo22", StorageID: "", StorageNamespace: "storageNS4", DefaultBranch: "main4", CreationDate: now},
{Name: "repo23", StorageID: "", StorageNamespace: "storageNS5", DefaultBranch: "main5", CreationDate: now},
{Name: "repo22", StorageID: "sid2", StorageNamespace: "storageNS4", DefaultBranch: "main4", CreationDate: now},
{Name: "repo23", StorageID: "sid2", StorageNamespace: "storageNS5", DefaultBranch: "main5", CreationDate: now},
},
wantHasMore: false,
wantErr: false,
Expand Down Expand Up @@ -889,7 +890,13 @@ func createPrepareUncommittedTestScenario(t *testing.T, repositoryID string, num
sort.Slice(diffs[i], func(ii, jj int) bool {
return bytes.Compare(diffs[i][ii].Key, diffs[i][jj].Key) < 0
})
test.CommittedManager.EXPECT().Diff(gomock.Any(), graveler.StorageID(""), repository.StorageNamespace, gomock.Any(), branches[i].CompactedBaseMetaRangeID).MinTimes(1).Return(gUtils.NewDiffIter(diffs[i]), nil)
test.CommittedManager.EXPECT().Diff(
gomock.Any(),
graveler.StorageID(config.SingleBlockstoreID),
repository.StorageNamespace,
gomock.Any(),
branches[i].CompactedBaseMetaRangeID,
).MinTimes(1).Return(gUtils.NewDiffIter(diffs[i]), nil)
}
}

Expand Down
11 changes: 6 additions & 5 deletions pkg/graveler/committed/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
"github.com/treeverse/lakefs/pkg/catalog/testutils"
"github.com/treeverse/lakefs/pkg/config"
"github.com/treeverse/lakefs/pkg/graveler"
"github.com/treeverse/lakefs/pkg/graveler/committed"
"github.com/treeverse/lakefs/pkg/graveler/committed/mock"
Expand Down Expand Up @@ -35,16 +36,16 @@ func TestManager_WriteRange(t *testing.T) {
}{
{
name: "iterator_exhausted",
initStorageID: "",
writeStorageID: "",
initStorageID: config.SingleBlockstoreID,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what we did in this test, but also what we did in the other test files. I would have expected to have twice as many test cases: once for "" aka SIngleBlockstoreID, one for "sid1". (This could have happened with nested test.Run()s, of course.) But instead some test cases switch to testing "", others to "sid1". And I don't understand why.

Obviously I don't understand this for all changes in this file, not only for this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can understand, we're trying to make sure StorageID flows properly from start to finish. By starting with either "" or "sid*" on one side, and making sure we're getting the same result in the other end, we have some confidence it's being passed properly, no?

writeStorageID: config.SingleBlockstoreID,
records: []*graveler.ValueRecord{
{Key: graveler.Key("1"), Value: &graveler.Value{}},
{Key: graveler.Key("2"), Value: &graveler.Value{}},
},
},
{
name: "mismatched_sid",
initStorageID: "",
initStorageID: config.SingleBlockstoreID,
writeStorageID: "summat_else",
records: []*graveler.ValueRecord{
{Key: graveler.Key("1"), Value: &graveler.Value{}},
Expand All @@ -54,8 +55,8 @@ func TestManager_WriteRange(t *testing.T) {
},
{
name: "break_at_key",
initStorageID: "",
writeStorageID: "",
initStorageID: "sid1",
writeStorageID: "sid1",
records: []*graveler.ValueRecord{
{Key: graveler.Key("1"), Value: &graveler.Value{}},
{Key: graveler.Key("2"), Value: &graveler.Value{}},
Expand Down
6 changes: 3 additions & 3 deletions pkg/graveler/committed/meta_range_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestWriter_WriteRecords(t *testing.T) {

rangeManagerMeta := mock.NewMockRangeManager(ctrl)
rangeManagerMeta.EXPECT().GetWriter(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeMetaWriter, nil)
storageID := committed.StorageID("")
storageID := committed.StorageID("sid")
namespace := committed.Namespace("ns")
w := committed.NewGeneralMetaRangeWriter(ctx, rangeManager, rangeManagerMeta, &params, storageID, namespace, nil)

Expand Down Expand Up @@ -102,7 +102,7 @@ func TestWriter_OverlappingRanges(t *testing.T) {
defer ctrl.Finish()

rangeManager := mock.NewMockRangeManager(ctrl)
storageID := committed.StorageID("")
storageID := committed.StorageID("sid")
namespace := committed.Namespace("ns")
rng := committed.Range{MinKey: committed.Key("a"), MaxKey: committed.Key("g")}
rng2 := committed.Range{MinKey: committed.Key("c"), MaxKey: committed.Key("l")}
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestWriter_RecordRangeAndClose(t *testing.T) {
rangeManagerMeta := mock.NewMockRangeManager(ctrl)
fakeMetaWriter := NewFakeRangeWriter(&committed.WriteResult{}, nil)

storageID := committed.StorageID("")
storageID := committed.StorageID("sid")
namespace := committed.Namespace("ns")
record := graveler.ValueRecord{Key: nil, Value: &graveler.Value{}}
rng := committed.Range{ID: "rng2-id", MinKey: committed.Key("a"), MaxKey: committed.Key("g"), Count: 4}
Expand Down
1 change: 1 addition & 0 deletions pkg/graveler/graveler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,7 @@ func TestGraveler_CreateBranch(t *testing.T) {
func TestGraveler_UpdateBranch(t *testing.T) {
gravel := newGraveler(t, nil, &testutil.StagingFake{ValueIterator: testutil.NewValueIteratorFake([]graveler.ValueRecord{{Key: graveler.Key("foo/one"), Value: &graveler.Value{}}})},
&testutil.RefsFake{Branch: &graveler.Branch{}, UpdateErr: kv.ErrPredicateFailed}, nil, nil)
testutil.ShortenBranchUpdateBackOff(gravel.(*graveler.Graveler))
_, err := gravel.UpdateBranch(context.Background(), repository, "", "")
require.ErrorIs(t, err, graveler.ErrTooManyTries)

Expand Down
Loading
Loading