Skip to content

Commit

Permalink
pytest_tests: Wait for epoch alignment
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Kulachenko <oleg@nspcc.ru>
  • Loading branch information
vvarg229 committed Sep 5, 2023
1 parent 660da43 commit eb5fb28
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 44 deletions.
4 changes: 2 additions & 2 deletions pytest_tests/steps/storage_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import allure
import pytest
from cluster import Cluster
from epoch import tick_epoch
from epoch import tick_epoch, tick_epoch_and_wait, get_epoch
from grpc_responses import OBJECT_ALREADY_REMOVED
from neofs_testlib.shell import Shell
from python_keywords.neofs_verbs import delete_object, get_object
Expand Down Expand Up @@ -46,7 +46,7 @@ def delete_objects(
endpoint=cluster.default_rpc_endpoint,
)

tick_epoch(shell, cluster)
tick_epoch_and_wait(shell, cluster)
sleep(CLEANUP_TIMEOUT)

with allure.step("Get objects and check errors"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,7 @@ def test_storagegroup_lifetime(self, object_size, expiration_flag, cluster):
expire_at=current_epoch + 1 if expiration_flag == "expire_at" else None,
)
with allure.step("Tick two epochs"):
for _ in range(2):
self.tick_epoch()
self.wait_for_epochs_align()
self.tick_epochs_and_wait(2)
with pytest.raises(Exception, match=OBJECT_NOT_FOUND):
get_storagegroup(
shell=self.shell,
Expand Down
6 changes: 3 additions & 3 deletions pytest_tests/testsuites/acl/test_bearer.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def test_bearer_token_compound_operations(self, wallets, eacl_container_with_obj
@pytest.mark.parametrize("expiration_flag", ["lifetime", "expire_at"])
def test_bearer_token_expiration(self, wallets, eacl_container_with_objects, expiration_flag):
current_epoch = get_epoch(self.shell, self.cluster)
self.tick_epochs(1)
self.tick_epochs_and_wait(1)
cid, objects_oids, file_path = eacl_container_with_objects
user_wallet = wallets.get_wallet()

Expand Down Expand Up @@ -279,7 +279,7 @@ def test_bearer_token_expiration(self, wallets, eacl_container_with_objects, exp
json=True,
)

self.tick_epochs(1)
self.tick_epochs_and_wait(1)

with allure.step(
f"Check {EACLRole.USER.value} with token has access to all operations with container"
Expand All @@ -295,7 +295,7 @@ def test_bearer_token_expiration(self, wallets, eacl_container_with_objects, exp
cluster=self.cluster,
)

self.tick_epochs(1)
self.tick_epochs_and_wait(1)

with allure.step(
f"Check {EACLRole.USER.value} has no access to all operations with container"
Expand Down
4 changes: 2 additions & 2 deletions pytest_tests/testsuites/container/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_container_creation(self, default_wallet, name):
delete_container(
wallet, cid, shell=self.shell, endpoint=self.cluster.default_rpc_endpoint
)
self.tick_epoch()
self.tick_epochs_and_wait(1)
wait_for_container_deletion(
wallet, cid, shell=self.shell, endpoint=self.cluster.default_rpc_endpoint
)
Expand Down Expand Up @@ -157,7 +157,7 @@ def test_container_creation_deletion_parallel(self, default_wallet):
delete_container(
wallet, cid, shell=self.shell, endpoint=self.cluster.default_rpc_endpoint
)
self.tick_epoch()
self.tick_epochs_and_wait(1)
wait_for_container_deletion(
wallet, cid, shell=self.shell, endpoint=self.cluster.default_rpc_endpoint
)
2 changes: 1 addition & 1 deletion pytest_tests/testsuites/network/test_homomorphic_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def containers_cleanup(self, default_wallet: str) -> None:
shell=self.shell,
endpoint=self.cluster.default_rpc_endpoint,
)
self.tick_epoch()
self.tick_epochs_and_wait(1)
wait_for_container_deletion(
default_wallet,
cid,
Expand Down
4 changes: 2 additions & 2 deletions pytest_tests/testsuites/network/test_node_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def create_container_and_pick_node(
def tick_epoch_with_retries(self, attempts: int = 3, timeout: int = 3):
for attempt in range(attempts):
try:
self.tick_epoch()
self.tick_epochs_and_wait(1)
except RuntimeError:
sleep(timeout)
if attempt >= attempts - 1:
Expand Down Expand Up @@ -475,7 +475,7 @@ def wait_for_expected_object_copies(
copies = get_simple_object_copies(wallet, cid, oid, self.shell, nodes)
if copies == expected_copies:
break
tick_epoch(self.shell, self.cluster)
self.tick_epochs_and_wait(1)
sleep(parse_time(NEOFS_CONTRACT_CACHE_TIMEOUT))
else:
raise AssertionError(f"There are no {expected_copies} copies during time")
Expand Down
3 changes: 1 addition & 2 deletions pytest_tests/testsuites/object/test_object_lifetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ def test_object_api_lifetime(
assert get_file_hash(got_file) == file_hash

with allure.step("Tick two epochs"):
for _ in range(2):
self.tick_epoch()
self.tick_epochs_and_wait(2)

# Wait for GC, because object with expiration is counted as alive until GC removes it
wait_for_gc_pass_on_storage_nodes()
Expand Down
15 changes: 7 additions & 8 deletions pytest_tests/testsuites/object/test_object_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from cluster_test_base import ClusterTestBase
from common import STORAGE_GC_TIME
from complex_object_actions import get_link_object, get_storage_object_chunks
from epoch import ensure_fresh_epoch, get_epoch, tick_epoch
from epoch import ensure_fresh_epoch, get_epoch, tick_epoch, tick_epoch_and_wait
from grpc_responses import (
LIFETIME_REQUIRED,
LOCK_NON_REGULAR_OBJECT,
Expand Down Expand Up @@ -98,7 +98,7 @@ def locked_storage_object(
if epoch_diff > 0:
with allure.step(f"Tick {epoch_diff} epochs"):
for _ in range(epoch_diff):
tick_epoch(client_shell, cluster)
tick_epoch_and_wait(client_shell, cluster, current_epoch)
try:
delete_object(
storage_object.wallet_file_path,
Expand Down Expand Up @@ -310,7 +310,7 @@ def test_expired_object_should_be_deleted_after_locks_are_expired(
)

with allure.step("Check object is not deleted at expiration time"):
self.tick_epochs(2)
self.tick_epochs_and_wait(2)
# Must wait to ensure object is not deleted
wait_for_gc_pass_on_storage_nodes()
with expect_not_raises():
Expand All @@ -334,7 +334,7 @@ def check_object_not_found():
)

with allure.step("Wait for object to be deleted after third epoch"):
self.tick_epoch()
self.tick_epochs_and_wait(1)
check_object_not_found()

@allure.title("Should be possible to lock multiple objects at once")
Expand Down Expand Up @@ -386,8 +386,7 @@ def test_should_be_possible_to_lock_multiple_objects_at_once(
)

with allure.step("Tick two epochs"):
self.tick_epoch()
self.tick_epoch()
self.tick_epochs_and_wait(2)

with expect_not_raises():
delete_objects(storage_objects, self.shell, self.cluster)
Expand Down Expand Up @@ -463,7 +462,7 @@ def test_after_lock_expiration_with_lifetime_user_should_be_able_to_delete_objec
lifetime=1,
)

self.tick_epochs(2)
self.tick_epochs_and_wait(2)
with expect_not_raises():
delete_object(
storage_object.wallet_file_path,
Expand Down Expand Up @@ -508,7 +507,7 @@ def test_after_lock_expiration_with_expire_at_user_should_be_able_to_delete_obje
expire_at=current_epoch + 1,
)

self.tick_epochs(2)
self.tick_epochs_and_wait(2)

with expect_not_raises():
delete_object(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def test_expiration_epoch_in_http(self, simple_object_size):
get_via_http_gate(cid=cid, oid=oid, endpoint=http_endpoint)

for expired_objects, not_expired_objects in [(oids[:1], oids[1:]), (oids[:2], oids[2:])]:
self.tick_epoch()
self.tick_epochs_and_wait(1)

# Wait for GC, because object with expiration is counted as alive until GC removes it
wait_for_gc_pass_on_storage_nodes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def test_negative_put_and_get_object3(
shell=self.shell,
endpoint=self.cluster.default_rpc_endpoint,
)
self.tick_epoch()
self.tick_epochs_and_wait(1)
wait_for_container_deletion(
self.wallet,
storage_object_1.cid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def test_unable_put_expired_rfc(self, user_container: str, simple_object_size: i
def test_http_attr_priority_epoch_duration(
self, user_container: str, object_size: int, epoch_duration: int
):
self.tick_epoch()
self.tick_epochs_and_wait(1)
epoch_count = 1
expected_epoch = get_epoch(self.shell, self.cluster) + epoch_count
logger.info(
Expand All @@ -225,8 +225,7 @@ def test_http_attr_priority_epoch_duration(
)
self.validation_for_http_header_attr(head_info=head_info, expected_epoch=expected_epoch)
with allure.step("Check that object becomes unavailable when epoch is expired"):
for _ in range(0, epoch_count + 1):
self.tick_epoch()
self.tick_epochs_and_wait(epoch_count + 1)
assert (
get_epoch(self.shell, self.cluster) == expected_epoch + 1
), f"Epochs should be equal: {get_epoch(self.shell, self.cluster)} != {expected_epoch + 1}"
Expand Down Expand Up @@ -256,7 +255,7 @@ def test_http_attr_priority_epoch_duration(
def test_http_attr_priority_dur_timestamp(
self, user_container: str, object_size: int, epoch_duration: int
):
self.tick_epoch()
self.tick_epochs_and_wait(1)
epoch_count = 2
expected_epoch = get_epoch(self.shell, self.cluster) + epoch_count
logger.info(
Expand All @@ -279,8 +278,7 @@ def test_http_attr_priority_dur_timestamp(
)
self.validation_for_http_header_attr(head_info=head_info, expected_epoch=expected_epoch)
with allure.step("Check that object becomes unavailable when epoch is expired"):
for _ in range(0, epoch_count + 1):
self.tick_epoch()
self.tick_epochs_and_wait(epoch_count + 1)
assert (
get_epoch(self.shell, self.cluster) == expected_epoch + 1
), f"Epochs should be equal: {get_epoch(self.shell, self.cluster)} != {expected_epoch + 1}"
Expand Down Expand Up @@ -310,7 +308,7 @@ def test_http_attr_priority_dur_timestamp(
def test_http_attr_priority_timestamp_rfc(
self, user_container: str, object_size: int, epoch_duration: int
):
self.tick_epoch()
self.tick_epochs_and_wait(1)
epoch_count = 2
expected_epoch = get_epoch(self.shell, self.cluster) + epoch_count
logger.info(
Expand All @@ -333,8 +331,7 @@ def test_http_attr_priority_timestamp_rfc(
)
self.validation_for_http_header_attr(head_info=head_info, expected_epoch=expected_epoch)
with allure.step("Check that object becomes unavailable when epoch is expired"):
for _ in range(0, epoch_count + 1):
self.tick_epoch()
self.tick_epochs_and_wait(epoch_count + 1)
assert (
get_epoch(self.shell, self.cluster) == expected_epoch + 1
), f"Epochs should be equal: {get_epoch(self.shell, self.cluster)} != {expected_epoch + 1}"
Expand Down Expand Up @@ -362,7 +359,7 @@ def test_http_attr_priority_timestamp_rfc(
def test_http_rfc_object_unavailable_after_expir(
self, user_container: str, object_size: int, epoch_duration: int
):
self.tick_epoch()
self.tick_epochs_and_wait(1)
epoch_count = 2
expected_epoch = get_epoch(self.shell, self.cluster) + epoch_count
logger.info(
Expand All @@ -384,8 +381,7 @@ def test_http_rfc_object_unavailable_after_expir(
)
self.validation_for_http_header_attr(head_info=head_info, expected_epoch=expected_epoch)
with allure.step("Check that object becomes unavailable when epoch is expired"):
for _ in range(0, epoch_count + 1):
self.tick_epoch()
self.tick_epochs_and_wait(epoch_count + 1)
# check that {EXPIRATION_EXPIRATION_RFC} absents in header output
assert (
get_epoch(self.shell, self.cluster) == expected_epoch + 1
Expand Down
6 changes: 3 additions & 3 deletions pytest_tests/testsuites/services/s3_gate/test_s3_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest
from aws_cli_client import AwsCliClient
from common import ASSETS_DIR
from epoch import tick_epoch
from epoch import tick_epoch, tick_epoch_and_wait
from file_helper import (
generate_file,
generate_file_with_content,
Expand Down Expand Up @@ -82,7 +82,7 @@ def test_s3_buckets(self, simple_object_size):

with allure.step(f"Delete empty bucket {bucket_2}"):
s3_gate_bucket.delete_bucket_s3(self.s3_client, bucket_2)
tick_epoch(self.shell, self.cluster)
self.tick_epochs_and_wait(1)

with allure.step(f"Check bucket {bucket_2} deleted"):
with pytest.raises(Exception, match=r".*Not Found.*"):
Expand All @@ -98,7 +98,7 @@ def test_s3_buckets(self, simple_object_size):

with allure.step(f"Delete bucket {bucket_1}"):
s3_gate_bucket.delete_bucket_s3(self.s3_client, bucket_1)
self.tick_epoch()
self.tick_epochs_and_wait(1)

with allure.step(f"Check bucket {bucket_1} deleted"):
with pytest.raises(Exception, match=r".*Not Found.*"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def test_session_token_expiration_flags(
session=session_token,
)

self.tick_epochs(2)
self.tick_epochs_and_wait(2)

with allure.step("Verify object operations with created session token are not allowed"):
file_path = generate_file(simple_object_size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def test_static_session_expiration_at_next(
session=token_expire_at_next_epoch,
)

self.tick_epochs(2)
self.tick_epochs_and_wait(2)

with pytest.raises(Exception, match=EXPIRED_SESSION_TOKEN):
head_object(
Expand Down Expand Up @@ -573,7 +573,7 @@ def test_static_session_start_at_next(
session=token_start_at_next_epoch,
)

self.tick_epoch()
self.tick_epochs_and_wait(1)
head_object(
user_wallet.path,
container,
Expand All @@ -583,7 +583,7 @@ def test_static_session_start_at_next(
session=token_start_at_next_epoch,
)

self.tick_epochs(2)
self.tick_epochs_and_wait(2)
with pytest.raises(Exception, match=EXPIRED_SESSION_TOKEN):
head_object(
user_wallet.path,
Expand Down

0 comments on commit eb5fb28

Please sign in to comment.