From 1e6d3e77f9f22783860e8846dfb301b62e7c04a1 Mon Sep 17 00:00:00 2001 From: Liza Date: Tue, 14 Mar 2023 14:55:01 +0300 Subject: [PATCH] Divide test_expiration_epoch_in_http into several (parametrized) Two tests now checks if an expired object can be got. X-Attribute-System-Expiration-Epoch -> X-Attribute-System-Expiration-Epoch python3.9 -> 3.10 in .pre-commit-config.yaml Signed-off-by: Liza --- .pre-commit-config.yaml | 2 +- .../services/http_gate/test_http_gate.py | 52 +++++++++---------- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4da00b4..032a87d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ repos: rev: 22.8.0 hooks: - id: black - language_version: python3.9 + language_version: python3.10 - repo: https://github.com/pycqa/isort rev: 5.12.0 hooks: diff --git a/pytest_tests/testsuites/services/http_gate/test_http_gate.py b/pytest_tests/testsuites/services/http_gate/test_http_gate.py index b24d91a..fdbade9 100644 --- a/pytest_tests/testsuites/services/http_gate/test_http_gate.py +++ b/pytest_tests/testsuites/services/http_gate/test_http_gate.py @@ -1,4 +1,3 @@ -import logging import os import allure @@ -23,7 +22,6 @@ from pytest_tests.helpers.http_gate import ( from pytest_tests.helpers.utility import wait_for_gc_pass_on_storage_nodes from pytest_tests.steps.cluster_test_base import ClusterTestBase -logger = logging.getLogger("NeoLogger") OBJECT_NOT_FOUND_ERROR = "not found" @@ -199,9 +197,11 @@ class TestHttpGate(ClusterTestBase): ) @allure.title("Test Expiration-Epoch in HTTP header") - def test_expiration_epoch_in_http(self, simple_object_size): + @pytest.mark.parametrize("epoch_gap", [0, 1]) + def test_expiration_epoch_in_http(self, simple_object_size, epoch_gap): endpoint = self.cluster.default_rpc_endpoint http_endpoint = self.cluster.default_http_gate_endpoint + min_valid_epoch = get_epoch(self.shell, self.cluster) + epoch_gap cid = create_container( self.wallet, @@ -211,44 +211,40 @@ class TestHttpGate(ClusterTestBase): basic_acl=PUBLIC_ACL, ) file_path = generate_file(simple_object_size) - oids = [] + oids_to_be_expired = [] + oids_to_be_valid = [] - curr_epoch = get_epoch(self.shell, self.cluster) - epochs = (curr_epoch, curr_epoch + 1, curr_epoch + 2, curr_epoch + 100) - - for epoch in epochs: - headers = {"X-Attribute-System-Expiration-Epoch": str(epoch)} + for gap_until in (0, 1, 2, 100): + valid_until = min_valid_epoch + gap_until + headers = {"X-Attribute-System-Expiration-Epoch": str(valid_until)} with allure.step("Put objects using HTTP with attribute Expiration-Epoch"): - oids.append( - upload_via_http_gate( - cid=cid, path=file_path, headers=headers, endpoint=http_endpoint - ) + oid = upload_via_http_gate( + cid=cid, path=file_path, headers=headers, endpoint=http_endpoint ) + if get_epoch(self.shell, self.cluster) + 1 <= valid_until: + oids_to_be_valid.append(oid) + else: + oids_to_be_expired.append(oid) + with allure.step("This object can be got"): + get_via_http_gate(cid=cid, oid=oid, endpoint=http_endpoint) - assert len(oids) == len(epochs), "Expected all objects have been put successfully" + self.tick_epoch() - with allure.step("All objects can be get"): - for oid in oids: - get_via_http_gate(cid=cid, oid=oid, endpoint=http_endpoint) + # Wait for GC, because object with expiration is counted as alive until GC removes it + wait_for_gc_pass_on_storage_nodes() - for expired_objects, not_expired_objects in [(oids[:1], oids[1:]), (oids[:2], oids[2:])]: - self.tick_epoch() - - # Wait for GC, because object with expiration is counted as alive until GC removes it - wait_for_gc_pass_on_storage_nodes() - - for oid in expired_objects: + for oid in oids_to_be_expired: + with allure.step(f"{oid} shall be expired and cannot be got"): try_to_get_object_and_expect_error( cid=cid, oid=oid, error_pattern=OBJECT_NOT_FOUND_ERROR, endpoint=self.cluster.default_http_gate_endpoint, ) - - with allure.step("Other objects can be get"): - for oid in not_expired_objects: - get_via_http_gate(cid=cid, oid=oid, endpoint=http_endpoint) + for oid in oids_to_be_valid: + with allure.step(f"{oid} shall be valid and can be got"): + get_via_http_gate(cid=cid, oid=oid, endpoint=http_endpoint) @allure.title("Test Zip in HTTP header") def test_zip_in_http(self, complex_object_size, simple_object_size):