From 428cfed8af0fd795e77b59ef7a99cbf75c4d3f1e Mon Sep 17 00:00:00 2001 From: Aleksey Savchuk Date: Thu, 12 Dec 2024 15:40:32 +0300 Subject: [PATCH] [#1445] metabase/test: Add test for `GetLocks` method Since it'll be working with locks of the new format, i. e. locks with expiration epoch, it's better to have a test for this method to ensure it can handle locks of both old and new formats. Signed-off-by: Aleksey Savchuk --- .../metabase/lock_test.go | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/pkg/local_object_storage/metabase/lock_test.go b/pkg/local_object_storage/metabase/lock_test.go index c7d26f6bf..1aaabf874 100644 --- a/pkg/local_object_storage/metabase/lock_test.go +++ b/pkg/local_object_storage/metabase/lock_test.go @@ -288,3 +288,41 @@ func putAndLockObj(t *testing.T, db *meta.DB, numOfLockedObjs int) ([]*objectSDK return lockedObjs, lockObj } + +func TestGetLocks(t *testing.T) { + t.Parallel() + + db := newDB(t) + defer func() { require.NoError(t, db.Close(context.Background())) }() + + object := oidtest.Address() + + t.Run("no locks for object", func(t *testing.T) { + gotLocks, err := db.GetLocks(context.Background(), object) + require.NoError(t, err) + require.Empty(t, gotLocks) + }) + + locks := []meta.Lock{ + {oidtest.ID(), 1}, + {oidtest.ID(), 2}, + } + + for _, lock := range locks { + require.NoError(t, + db.Lock(context.Background(), object.Container(), lock.ID, []oid.ID{object.Object()}, lock.ExpEpoch), + ) + + // try to lock with the same lock object to ensure + // that all locks are unique and set only once. + require.NoError(t, + db.Lock(context.Background(), object.Container(), lock.ID, []oid.ID{object.Object()}, lock.ExpEpoch+100), + ) + } + + t.Run("object is locked", func(t *testing.T) { + gotLocks, err := db.GetLocks(context.Background(), object) + require.NoError(t, err) + require.ElementsMatch(t, locks, gotLocks) + }) +}