forked from TrueCloudLab/frostfs-node
[#1689] engine/test: Refactor TestInhumeIfObjectDoesntExist
test
- Use the same storage engine in multiple parallel tests - Move `Lock`, `Inhume`, `Head` calls to separate functions Change-Id: I00849c1f068f0ab8d92061719d67d6fe786200db Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
This commit is contained in:
parent
908b08108d
commit
487cb34c5d
1 changed files with 46 additions and 38 deletions
|
@ -245,66 +245,74 @@ func benchmarkInhumeMultipart(b *testing.B, numShards, numObjects int) {
|
|||
}
|
||||
|
||||
func TestInhumeIfObjectDoesntExist(t *testing.T) {
|
||||
const numShards = 4
|
||||
|
||||
engine := testNewEngine(t).setShardsNum(t, numShards).prepare(t).engine
|
||||
t.Cleanup(func() { require.NoError(t, engine.Close(context.Background())) })
|
||||
|
||||
t.Run("object is locked", func(t *testing.T) {
|
||||
t.Run("inhume without tombstone", func(t *testing.T) {
|
||||
testInhumeLockedIfObjectDoesntExist(t, false, false)
|
||||
testInhumeLockedIfObjectDoesntExist(t, engine, false, false)
|
||||
})
|
||||
t.Run("inhume with tombstone", func(t *testing.T) {
|
||||
testInhumeLockedIfObjectDoesntExist(t, true, false)
|
||||
testInhumeLockedIfObjectDoesntExist(t, engine, true, false)
|
||||
})
|
||||
t.Run("force inhume", func(t *testing.T) {
|
||||
testInhumeLockedIfObjectDoesntExist(t, false, true)
|
||||
testInhumeLockedIfObjectDoesntExist(t, engine, false, true)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func testInhumeLockedIfObjectDoesntExist(t *testing.T, withTombstone, withForce bool) {
|
||||
func testInhumeLockedIfObjectDoesntExist(t *testing.T, e *StorageEngine, withTombstone, withForce bool) {
|
||||
t.Parallel()
|
||||
|
||||
// Due to the tests design it is possible to set both the options,
|
||||
// however removal with tombstone and force removal are exclusive.
|
||||
require.False(t, withTombstone && withForce)
|
||||
object := oidtest.Address()
|
||||
require.NoError(t, testLockObject(e, object))
|
||||
|
||||
var (
|
||||
errLocked *apistatus.ObjectLocked
|
||||
inhumePrm InhumePrm
|
||||
headPrm HeadPrm
|
||||
ctx = context.Background()
|
||||
container = cidtest.ID()
|
||||
object = oidtest.Address()
|
||||
lock = oidtest.ID()
|
||||
tombstone = oidtest.Address()
|
||||
)
|
||||
object.SetContainer(container)
|
||||
tombstone.SetContainer(container)
|
||||
|
||||
engine := testNewEngine(t).setShardsNum(t, 4).prepare(t).engine
|
||||
defer func() { require.NoError(t, engine.Close(ctx)) }()
|
||||
|
||||
err := engine.Lock(ctx, container, lock, []oid.ID{object.Object()})
|
||||
require.NoError(t, err)
|
||||
|
||||
if withTombstone {
|
||||
inhumePrm.WithTarget(tombstone, object)
|
||||
} else {
|
||||
inhumePrm.MarkAsGarbage(object)
|
||||
}
|
||||
if withForce {
|
||||
inhumePrm.WithForceRemoval()
|
||||
}
|
||||
|
||||
err = engine.Inhume(ctx, inhumePrm)
|
||||
err := testInhumeObject(t, e, object, withTombstone, withForce)
|
||||
if !withForce {
|
||||
var errLocked *apistatus.ObjectLocked
|
||||
require.ErrorAs(t, err, &errLocked)
|
||||
return
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
headPrm.WithAddress(object)
|
||||
_, err = engine.Head(ctx, headPrm)
|
||||
err = testHeadObject(e, object)
|
||||
if withTombstone {
|
||||
require.True(t, client.IsErrObjectAlreadyRemoved(err))
|
||||
} else {
|
||||
require.True(t, client.IsErrObjectNotFound(err))
|
||||
}
|
||||
}
|
||||
|
||||
func testLockObject(e *StorageEngine, obj oid.Address) error {
|
||||
return e.Lock(context.Background(), obj.Container(), oidtest.ID(), []oid.ID{obj.Object()})
|
||||
}
|
||||
|
||||
func testInhumeObject(t testing.TB, e *StorageEngine, obj oid.Address, withTombstone, withForce bool) error {
|
||||
tombstone := oidtest.Address()
|
||||
tombstone.SetContainer(obj.Container())
|
||||
|
||||
// Due to the tests design it is possible to set both the options,
|
||||
// however removal with tombstone and force removal are exclusive.
|
||||
require.False(t, withTombstone && withForce)
|
||||
|
||||
var inhumePrm InhumePrm
|
||||
if withTombstone {
|
||||
inhumePrm.WithTarget(tombstone, obj)
|
||||
} else {
|
||||
inhumePrm.MarkAsGarbage(obj)
|
||||
}
|
||||
if withForce {
|
||||
inhumePrm.WithForceRemoval()
|
||||
}
|
||||
return e.Inhume(context.Background(), inhumePrm)
|
||||
}
|
||||
|
||||
func testHeadObject(e *StorageEngine, obj oid.Address) error {
|
||||
var headPrm HeadPrm
|
||||
headPrm.WithAddress(obj)
|
||||
|
||||
_, err := e.Head(context.Background(), headPrm)
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue