|
| 1 | +from pathlib import Path |
| 2 | +from typing import Any, Generator |
| 3 | +import pytest |
| 4 | + |
| 5 | +from common import CommonScenario, ResultCode, temp_dir_common |
| 6 | +from testing_utils import ScenarioResult, LogContainer |
| 7 | + |
| 8 | + |
| 9 | +pytestmark = pytest.mark.parametrize("version", ["rust"], scope="class") |
| 10 | + |
| 11 | + |
| 12 | +class MultipleKvsScenario(CommonScenario): |
| 13 | + """ |
| 14 | + Common base implementation for multiple KVS tests. |
| 15 | + """ |
| 16 | + |
| 17 | + @pytest.fixture(scope="class") |
| 18 | + def temp_dir( |
| 19 | + self, tmp_path_factory: pytest.TempPathFactory, version: str |
| 20 | + ) -> Generator[Path, None, None]: |
| 21 | + yield from temp_dir_common(tmp_path_factory, self.__class__.__name__, version) |
| 22 | + |
| 23 | + |
| 24 | +@pytest.mark.PartiallyVerifies( |
| 25 | + ["comp_req__persistency__multi_instance", "comp_req__persistency__concurrency"] |
| 26 | +) |
| 27 | +@pytest.mark.FullyVerifies([""]) |
| 28 | +@pytest.mark.Description( |
| 29 | + "Verifies that multiple KVS instances with different IDs store and retrieve independent values without interference." |
| 30 | +) |
| 31 | +@pytest.mark.TestType("requirements-based") |
| 32 | +@pytest.mark.DerivationTechnique("requirements-based") |
| 33 | +class TestMultipleInstanceIds(MultipleKvsScenario): |
| 34 | + @pytest.fixture(scope="class") |
| 35 | + def scenario_name(self) -> str: |
| 36 | + return "cit.multiple_kvs.multiple_instance_ids" |
| 37 | + |
| 38 | + @pytest.fixture(scope="class") |
| 39 | + def test_config(self, temp_dir: Path) -> dict[str, Any]: |
| 40 | + return { |
| 41 | + "kvs_parameters_1": { |
| 42 | + "kvs_parameters": {"instance_id": 1, "dir": str(temp_dir)} |
| 43 | + }, |
| 44 | + "kvs_parameters_2": { |
| 45 | + "kvs_parameters": {"instance_id": 2, "dir": str(temp_dir)} |
| 46 | + }, |
| 47 | + } |
| 48 | + |
| 49 | + def test_ok(self, results: ScenarioResult, logs_info_level: LogContainer): |
| 50 | + assert results.return_code == ResultCode.SUCCESS |
| 51 | + |
| 52 | + key = "number" |
| 53 | + log1 = logs_info_level.find_log("instance", value="kvs1") |
| 54 | + assert log1 is not None |
| 55 | + assert log1.key == key |
| 56 | + assert log1.value == 111.1 |
| 57 | + |
| 58 | + log2 = logs_info_level.find_log("instance", value="kvs2") |
| 59 | + assert log2 is not None |
| 60 | + assert log2.key == key |
| 61 | + assert log2.value == 222.2 |
| 62 | + |
| 63 | + |
| 64 | +@pytest.mark.PartiallyVerifies( |
| 65 | + ["comp_req__persistency__multi_instance", "comp_req__persistency__concurrency"] |
| 66 | +) |
| 67 | +@pytest.mark.FullyVerifies([""]) |
| 68 | +@pytest.mark.Description( |
| 69 | + "Checks that multiple KVS instances with the same ID and key maintain consistent values across instances." |
| 70 | +) |
| 71 | +@pytest.mark.TestType("requirements-based") |
| 72 | +@pytest.mark.DerivationTechnique("requirements-based") |
| 73 | +class TestSameInstanceIdSameValue(MultipleKvsScenario): |
| 74 | + @pytest.fixture(scope="class") |
| 75 | + def scenario_name(self) -> str: |
| 76 | + return "cit.multiple_kvs.same_instance_id_same_value" |
| 77 | + |
| 78 | + @pytest.fixture(scope="class") |
| 79 | + def test_config(self, temp_dir: Path) -> dict[str, Any]: |
| 80 | + return {"kvs_parameters": {"instance_id": 1, "dir": str(temp_dir)}} |
| 81 | + |
| 82 | + def test_ok(self, results: ScenarioResult, logs_info_level: LogContainer): |
| 83 | + assert results.return_code == ResultCode.SUCCESS |
| 84 | + |
| 85 | + key = "number" |
| 86 | + log1 = logs_info_level.find_log("instance", value="kvs1") |
| 87 | + assert log1 is not None |
| 88 | + assert log1.key == key |
| 89 | + assert log1.value == 111.1 |
| 90 | + |
| 91 | + log2 = logs_info_level.find_log("instance", value="kvs2") |
| 92 | + assert log2 is not None |
| 93 | + assert log2.key == key |
| 94 | + assert log2.value == 111.1 |
| 95 | + |
| 96 | + assert log1.value == log2.value |
| 97 | + |
| 98 | + |
| 99 | +@pytest.mark.PartiallyVerifies( |
| 100 | + ["comp_req__persistency__multi_instance", "comp_req__persistency__concurrency"] |
| 101 | +) |
| 102 | +@pytest.mark.FullyVerifies([""]) |
| 103 | +@pytest.mark.Description( |
| 104 | + "Verifies that changes in one KVS instance with a shared ID and key are reflected in another instance, demonstrating interference." |
| 105 | +) |
| 106 | +@pytest.mark.TestType("requirements-based") |
| 107 | +@pytest.mark.DerivationTechnique("requirements-based") |
| 108 | +class TestSameInstanceIdDifferentValue(MultipleKvsScenario): |
| 109 | + @pytest.fixture(scope="class") |
| 110 | + def scenario_name(self) -> str: |
| 111 | + return "cit.multiple_kvs.same_instance_id_diff_value" |
| 112 | + |
| 113 | + @pytest.fixture(scope="class") |
| 114 | + def test_config(self, temp_dir: Path) -> dict[str, Any]: |
| 115 | + return {"kvs_parameters": {"instance_id": 1, "dir": str(temp_dir)}} |
| 116 | + |
| 117 | + def test_ok(self, results: ScenarioResult, logs_info_level: LogContainer): |
| 118 | + assert results.return_code == ResultCode.SUCCESS |
| 119 | + |
| 120 | + # Assertions are same as in 'TestSameInstanceIdSameValue'. |
| 121 | + # Test scenario behavior differs underneath. |
| 122 | + key = "number" |
| 123 | + log1 = logs_info_level.find_log("instance", value="kvs1") |
| 124 | + assert log1 is not None |
| 125 | + assert log1.key == key |
| 126 | + assert log1.value == 111.1 |
| 127 | + |
| 128 | + log2 = logs_info_level.find_log("instance", value="kvs2") |
| 129 | + assert log2 is not None |
| 130 | + assert log2.key == key |
| 131 | + assert log2.value == 111.1 |
| 132 | + |
| 133 | + assert log1.value == log2.value |
0 commit comments