add 2 cases for test object lock #80

Merged
abereziny merged 1 commit from :feature-2 into master 2023-09-01 09:06:50 +00:00

View file

@ -126,6 +126,27 @@ def locked_storage_object(
logger.debug(ex_message)
@wait_for_success(datetime_utils.parse_time(STORAGE_GC_TIME))
def check_object_not_found(wallet_file_path: str, cid: str, oid: str, shell: Shell, rpc_endpoint: str):
abereziny marked this conversation as resolved Outdated

can use StorageObjectInfo here instead of multiple single params
also default_rpc_endpoint should be just rpc_endpoint here

can use StorageObjectInfo here instead of multiple single params also `default_rpc_endpoint` should be just `rpc_endpoint` here
with pytest.raises(Exception, match=OBJECT_NOT_FOUND):
head_object(
wallet_file_path,
cid,
oid,
shell,
rpc_endpoint,
)
def verify_object_available(wallet_file_path: str, cid: str, oid: str, shell: Shell, rpc_endpoint: str):
with expect_not_raises():
head_object(
wallet_file_path,
cid,
oid,
shell,
rpc_endpoint,
)
@pytest.mark.sanity
@pytest.mark.grpc_object_lock
class TestObjectLockWithGrpc(ClusterTestBase):
@ -328,20 +349,13 @@ class TestObjectLockWithGrpc(ClusterTestBase):
self.cluster.default_rpc_endpoint,
)
@wait_for_success(datetime_utils.parse_time(STORAGE_GC_TIME))
def check_object_not_found():
with pytest.raises(Exception, match=OBJECT_NOT_FOUND):
head_object(
storage_object.wallet_file_path,
with allure.step("Wait for object to be deleted after third epoch"):
self.tick_epoch()
check_object_not_found(storage_object.wallet_file_path,
storage_object.cid,
storage_object.oid,
self.shell,
self.cluster.default_rpc_endpoint,
)
with allure.step("Wait for object to be deleted after third epoch"):
self.tick_epoch()
check_object_not_found()
self.cluster.default_rpc_endpoint)
@allure.title("Should be possible to lock multiple objects at once for {object_size}")
@pytest.mark.parametrize(
@ -658,3 +672,156 @@ class TestObjectLockWithGrpc(ClusterTestBase):
self.shell,
self.cluster.default_rpc_endpoint,
)
@allure.title("Expired object should be removed after all locks were expired for {object_size}")
@pytest.mark.parametrize(
abereziny marked this conversation as resolved Outdated

object_size: int -> object_size: ObjectSize everywhere

`object_size: int` -> `object_size: ObjectSize` everywhere
"object_size",
[pytest.lazy_fixture("simple_object_size"), pytest.lazy_fixture("complex_object_size")],
ids=["simple object size", "complex object size"],
)
abereziny marked this conversation as resolved Outdated

Same title correction :)

Same title correction :)
def test_expired_object_should_be_removed_after_relocks_expare_at(
self,
request: FixtureRequest,
user_container: StorageContainer,
object_size: ObjectSize,
):
abereziny marked this conversation as resolved Outdated

We may be more specific here
"Apply first lock to object for 3 epochs"

We may be more specific here `"Apply first lock to object for 3 epochs"`
allure.dynamic.title(
f"Expired object should be removed after all locks were expired for {request.node.callspec.id}"
)
current_epoch = self.ensure_fresh_epoch()
storage_object = user_container.generate_object(object_size.value, expire_at=current_epoch + 1)
with allure.step("Apply first lock to object for 3 epochs"):
lock_object_id_0 = lock_object(
abereziny marked this conversation as resolved Outdated

We can move it near check_object_not_found (for better test readability)

Also, the logic can be made simplier

def verify_lock_available(lock_object_id: str):
      with expect_not_raises():
              head_object(
                            storage_object.wallet_file_path,
                            storage_object.cid,
                            lock_object_id,
                            self.shell,
                            self.cluster.default_rpc_endpoint,
                          )
We can move it near `check_object_not_found` (for better test readability) Also, the logic can be made simplier ``` def verify_lock_available(lock_object_id: str): with expect_not_raises(): head_object( storage_object.wallet_file_path, storage_object.cid, lock_object_id, self.shell, self.cluster.default_rpc_endpoint, ) ```
storage_object.wallet_file_path,
storage_object.cid,
storage_object.oid,
self.shell,
self.cluster.default_rpc_endpoint,
expire_at=current_epoch + 3,
)
self.tick_epochs(2)
with allure.step("Check first lock is still available"):
verify_object_available(
storage_object.wallet_file_path,
storage_object.cid,
lock_object_id_0,
self.shell,
self.cluster.default_rpc_endpoint)
with allure.step("Apply second lock to object for 3 more epochs"):
abereziny marked this conversation as resolved Outdated

"Check first lock is still available"

`"Check first lock is still available"`
lock_object_id_1 = lock_object(
storage_object.wallet_file_path,
storage_object.cid,
abereziny marked this conversation as resolved Outdated

"Apply second lock to object for 3 more epochs"

"Apply second lock to object for 3 more epochs"
storage_object.oid,
self.shell,
self.cluster.default_rpc_endpoint,
expire_at=current_epoch + 5,
)
self.tick_epochs(2)
with allure.step("Verify first lock is expired and removed"):
check_object_not_found(
storage_object.wallet_file_path,
storage_object.cid,
abereziny marked this conversation as resolved Outdated

Separate to 2 steps:

Verify first lock is expired and removed
Verify second lock is still available

Separate to 2 steps: `Verify first lock is expired and removed` `Verify second lock is still available`
lock_object_id_0,
self.shell,
self.cluster.default_rpc_endpoint
)
with allure.step("Verify second lock is still available"):
verify_object_available(
storage_object.wallet_file_path,
abereziny marked this conversation as resolved Outdated

"Apply third lock to object for 3 more epochs"

"Apply third lock to object for 3 more epochs"
storage_object.cid,
lock_object_id_1,
self.shell,
self.cluster.default_rpc_endpoint
)
with allure.step("Apply third lock to object for 3 more epochs"):
lock_object(
storage_object.wallet_file_path,
storage_object.cid,
abereziny marked this conversation as resolved Outdated

"Verify object is deleted after all locks are expired"

"Verify object is deleted after all locks are expired"
storage_object.oid,
self.shell,
self.cluster.default_rpc_endpoint,
expire_at=current_epoch + 7,
)
with allure.step("Verify object is deleted after all locks are expired"):
self.tick_epochs(4)
check_object_not_found(
abereziny marked this conversation as resolved Outdated

Two expired objects with one lock should be deleted after lock expiration

Two expired objects with one lock should be deleted after lock expiration
storage_object.wallet_file_path,
storage_object.cid,
storage_object.oid,
self.shell,
abereziny marked this conversation as resolved Outdated

simple object size and complex object size everywhere :)

`simple object size` and `complex object size` everywhere :)
self.cluster.default_rpc_endpoint
)
@allure.title("Two expired objects with one lock should be deleted after lock expiration for {object_size}")
@pytest.mark.parametrize(
"object_size",
[pytest.lazy_fixture("simple_object_size"), pytest.lazy_fixture("complex_object_size")],
ids=["simple object size", "complex object size"],
)
def test_two_objects_expiration_with_one_lock(
self,
request: FixtureRequest,
user_container: StorageContainer,
object_size: ObjectSize,
):
allure.dynamic.title(
f"Two expired objects with one lock should be deleted after lock expiration for {request.node.callspec.id}"
)
current_epoch = self.ensure_fresh_epoch()
storage_objects: list[StorageObjectInfo] = []
with allure.step("Generate two objects"):
abereziny marked this conversation as resolved Outdated

Lock objects for 4(? please use correct number) epochs

`Lock objects for 4(? please use correct number) epochs`
for epoch_i in range(2):
storage_objects.append(
user_container.generate_object(object_size.value, expire_at=current_epoch + epoch_i + 3)
)
self.tick_epoch()
with allure.step("Lock objects for 4 epochs"):
lock_object(
storage_objects[0].wallet_file_path,
abereziny marked this conversation as resolved Outdated

Verify objects are available during next three epochs

Verify objects are available during next three epochs
storage_objects[0].cid,
",".join([storage_object.oid for storage_object in storage_objects]),
self.shell,
self.cluster.default_rpc_endpoint,
expire_at=current_epoch + 4,
)
with allure.step("Verify objects are available during next three epochs"):
for epoch_i in range(3):
self.tick_epoch()
with allure.step(f"Check objects at epoch {current_epoch + epoch_i + 2}"):
for storage_object in storage_objects:
verify_object_available(
storage_object.wallet_file_path,
abereziny marked this conversation as resolved Outdated

"Verify objects are deleted after lock was expired"

"Verify objects are deleted after lock was expired"
storage_object.cid,
storage_object.oid,
self.shell,
self.cluster.default_rpc_endpoint
)
with allure.step("Verify objects are deleted after lock was expired"):
self.tick_epoch()
for storage_object in storage_objects:
check_object_not_found(
abereziny marked this conversation as resolved Outdated

Redundant new lines (must be one in the end of file)

Redundant new lines (must be one in the end of file)
storage_object.wallet_file_path,
storage_object.cid,
storage_object.oid,
self.shell,
self.cluster.default_rpc_endpoint
)