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) + }) +}