|
9 | 9 | import os
|
10 | 10 | import sys
|
11 | 11 | import pytest
|
12 |
| -from typing import Union |
| 12 | +from typing import Optional, Union |
13 | 13 | from datetime import date
|
14 | 14 | from numpy import datetime64
|
15 | 15 | from copy import deepcopy
|
16 | 16 |
|
17 | 17 | from arcticdb.util import marks
|
| 18 | +from arcticdb.util.logger import get_logger |
18 | 19 |
|
19 | 20 | MACOS = sys.platform.lower().startswith("darwin")
|
20 | 21 | LINUX = sys.platform.lower().startswith("linux")
|
21 | 22 | WINDOWS = sys.platform.lower().startswith("win32")
|
22 | 23 |
|
| 24 | + |
| 25 | +# Defined shorter logs on errors |
| 26 | +SHORTER_LOGS = marks.SHORTER_LOGS |
| 27 | +logger = get_logger() |
| 28 | + |
| 29 | +RUNS_ON_GITHUB = os.getenv("GITHUB_ACTIONS") == "true" |
| 30 | + |
| 31 | +def getenv_strip(env_var_name: str, default_value: Optional[str] = None) -> Optional[str]: |
| 32 | + """ |
| 33 | + Get environment variable and strip whitespace safely. |
| 34 | +
|
| 35 | + Useful for string variables that represent enum values like "0" and "1". |
| 36 | + Returns the stripped value or the default if the variable is not set. |
| 37 | + """ |
| 38 | + value = os.getenv(env_var_name) |
| 39 | + return default_value if value is None or value.strip() == "" else value.strip() |
| 40 | + |
| 41 | + |
23 | 42 | # TODO: Some tests are either segfaulting or failing on MacOS with conda builds.
|
24 | 43 | # This is meant to be used as a temporary flag to skip/xfail those tests.
|
25 | 44 | ARCTICDB_USING_CONDA = marks.ARCTICDB_USING_CONDA
|
26 | 45 | MACOS_CONDA_BUILD = ARCTICDB_USING_CONDA and MACOS
|
27 | 46 | MACOS_WHEEL_BUILD = not ARCTICDB_USING_CONDA and MACOS
|
28 | 47 |
|
| 48 | +# These two should become pytest marks as opposed to variables feeding into skipif |
| 49 | +PERSISTENT_STORAGE_TESTS_ENABLED = getenv_strip("ARCTICDB_PERSISTENT_STORAGE_TESTS") == "1" |
| 50 | +FAST_TESTS_ONLY = getenv_strip("ARCTICDB_FAST_TESTS_ONLY") == "1" |
| 51 | +DISABLE_SLOW_TESTS = getenv_strip("ARCTICDB_DISABLE_SLOW_TESTS") == "1" |
| 52 | +if PERSISTENT_STORAGE_TESTS_ENABLED: |
| 53 | + # This is for legacy reasons AWS has different treatment because of persistent storages test workflow at github |
| 54 | + STORAGE_AWS_S3 = getenv_strip("ARCTICDB_STORAGE_AWS_S3", "1") == "1" |
| 55 | +else: |
| 56 | + STORAGE_AWS_S3 = getenv_strip("ARCTICDB_STORAGE_AWS_S3") == "1" |
| 57 | +STORAGE_GCP = getenv_strip("ARCTICDB_STORAGE_GCP") == "1" |
| 58 | +STORAGE_AZURE = getenv_strip("ARCTICDB_STORAGE_AZURE") == "1" |
| 59 | +# Local storage tests are all LMDB, simulated and a real mongo process/service |
| 60 | +LOCAL_STORAGE_TESTS_ENABLED = getenv_strip("ARCTICDB_LOCAL_STORAGE_TESTS_ENABLED", "1") == "1" |
| 61 | +# Each storage can be controlled individually |
| 62 | +STORAGE_LMDB = getenv_strip("ARCTICDB_STORAGE_LMDB") == "1" or (LOCAL_STORAGE_TESTS_ENABLED |
| 63 | + and getenv_strip("ARCTICDB_STORAGE_LMDB") != "0") |
| 64 | +STORAGE_AZURITE = getenv_strip("ARCTICDB_STORAGE_AZURITE") == "1" or (LOCAL_STORAGE_TESTS_ENABLED |
| 65 | + and getenv_strip("ARCTICDB_STORAGE_AZURITE") != "0") |
| 66 | +STORAGE_MONGO = getenv_strip("ARCTICDB_STORAGE_MONGO") == "1" or (LOCAL_STORAGE_TESTS_ENABLED |
| 67 | + and getenv_strip("ARCTICDB_STORAGE_MONGO") != "0") |
| 68 | +STORAGE_MEM = getenv_strip("ARCTICDB_STORAGE_MEM") == "1" or (LOCAL_STORAGE_TESTS_ENABLED |
| 69 | + and getenv_strip("ARCTICDB_STORAGE_MEM") != "0") |
| 70 | +STORAGE_NFS = getenv_strip("ARCTICDB_STORAGE_NFS") == "1" or (LOCAL_STORAGE_TESTS_ENABLED |
| 71 | + and getenv_strip("ARCTICDB_STORAGE_NFS") != "0") |
| 72 | +# When a real storage is turned on the simulated storage is turned off |
| 73 | +if STORAGE_AWS_S3: |
| 74 | + STORAGE_SIM_S3 = False |
| 75 | +else: |
| 76 | + STORAGE_SIM_S3 = (getenv_strip("ARCTICDB_STORAGE_SIM_S3") == "1" |
| 77 | + or (LOCAL_STORAGE_TESTS_ENABLED and getenv_strip("ARCTICDB_STORAGE_SIM_S3") != "0")) |
| 78 | +if STORAGE_GCP: |
| 79 | + STORAGE_SIM_GCP = False |
| 80 | +else: |
| 81 | + STORAGE_SIM_GCP = (getenv_strip("ARCTICDB_STORAGE_SIM_GCP") == "1" |
| 82 | + or (LOCAL_STORAGE_TESTS_ENABLED and getenv_strip("ARCTICDB_STORAGE_SIM_GCP") != "0")) |
| 83 | +if STORAGE_AZURE: |
| 84 | + STORAGE_AZURITE = False |
| 85 | +else: |
| 86 | + STORAGE_AZURITE = (getenv_strip("ARCTICDB_STORAGE_AZURITE") == "1" |
| 87 | + or (LOCAL_STORAGE_TESTS_ENABLED and getenv_strip("ARCTICDB_STORAGE_AZURITE") != "0")) |
| 88 | +TEST_ENCODING_V1 = getenv_strip("ARCTICDB_TEST_ENCODING_V1", "1") == "1" |
| 89 | +TEST_ENCODING_V2 = getenv_strip("ARCTICDB_TEST_ENCODING_V2", "1") == "1" |
| 90 | + |
| 91 | + |
| 92 | +if not SHORTER_LOGS: |
| 93 | + logger.info("-" * 120) |
| 94 | + logger.info(" ARCTICDB ENVIRONMENT VARIABLES:") |
| 95 | + for name, value in os.environ.items(): |
| 96 | + if name.startswith("ARCTICDB_"): |
| 97 | + logger.info(f"{name}={value}") |
| 98 | + logger.info("-" * 120) |
| 99 | + logger.info(" STORAGE STATUS:") |
| 100 | + logger.info(f"RUNS_ON_GITHUB ={RUNS_ON_GITHUB}") |
| 101 | + logger.info(f"LOCAL_STORAGE_TESTS_ENABLED ={LOCAL_STORAGE_TESTS_ENABLED}") |
| 102 | + logger.info(f"STORAGE_LMDB ={STORAGE_LMDB}") |
| 103 | + logger.info(f"STORAGE_MEM ={STORAGE_MEM}") |
| 104 | + logger.info(f"STORAGE_S3 (SIMULATED) ={STORAGE_SIM_S3}") |
| 105 | + logger.info(f"STORAGE_GCP (SIMULATED) ={STORAGE_SIM_GCP}") |
| 106 | + logger.info(f"STORAGE_AZURITE ={STORAGE_AZURITE}") |
| 107 | + logger.info(f"STORAGE_NFS ={STORAGE_NFS}") |
| 108 | + logger.info(f"STORAGE_MONGO ={STORAGE_MONGO}") |
| 109 | + logger.info(f"PERSISTENT_STORAGE_TESTS_ENABLED ={PERSISTENT_STORAGE_TESTS_ENABLED}") |
| 110 | + logger.info(f"STORAGE_AWS_S3 ={STORAGE_AWS_S3}") |
| 111 | + logger.info(f"STORAGE_GCP ={STORAGE_GCP}") |
| 112 | + logger.info(f"STORAGE_AZURE ={STORAGE_AZURE}") |
| 113 | + logger.info(f"Enc.V1 ={TEST_ENCODING_V1}") |
| 114 | + logger.info(f"Enc.V2 ={TEST_ENCODING_V2}") |
| 115 | + logger.info("-" * 120) |
| 116 | + |
| 117 | + |
29 | 118 | _MACOS_AZURE_TESTS_SKIP_REASON = (
|
30 | 119 | "Tests fail for macOS vcpkg builds, either because Azurite is improperly configured"
|
31 | 120 | "on the CI or because there's problem with Azure SDK for C++ in this configuration."
|
32 | 121 | )
|
33 |
| - |
34 | 122 | SKIP_CONDA_MARK = pytest.mark.skipif(
|
35 | 123 | ARCTICDB_USING_CONDA,
|
36 | 124 | reason="Those tests are skipped on conda",
|
37 | 125 | )
|
38 |
| - |
39 |
| -# These two should become pytest marks as opposed to variables feeding into skipif |
40 |
| -PERSISTENT_STORAGE_TESTS_ENABLED = os.getenv("ARCTICDB_PERSISTENT_STORAGE_TESTS") == "1" |
41 |
| -FAST_TESTS_ONLY = os.getenv("ARCTICDB_FAST_TESTS_ONLY") == "1" |
42 |
| -DISABLE_SLOW_TESTS = os.getenv("ARCTICDB_DISABLE_SLOW_TESTS") == "1" |
43 |
| -# Local storage tests are all LMDB, simulated and a real mongo process/service |
44 |
| -LOCAL_STORAGE_TESTS_ENABLED = os.getenv("ARCTICDB_LOCAL_STORAGE_TESTS_ENABLED", "1") == "1" |
45 |
| -STORAGE_LMDB = os.getenv("ARCTICDB_STORAGE_LMDB", "1") == "1" or LOCAL_STORAGE_TESTS_ENABLED == "1" |
46 |
| -STORAGE_AWS_S3 = os.getenv("ARCTICDB_STORAGE_AWS_S3", "1") == "1" |
47 |
| -STORAGE_GCP = os.getenv("ARCTICDB_STORAGE_GCP") == "1" |
48 |
| -STORAGE_AZURE = os.getenv("ARCTICDB_STORAGE_AZURE") == "1" |
49 |
| - |
50 |
| -# Defined shorter logs on errors |
51 |
| -SHORTER_LOGS = marks.SHORTER_LOGS |
52 |
| - |
53 | 126 | # !!!!!!!!!!!!!!!!!!!!!! Below mark (variable) names should reflect where they will be used, not what they do.
|
54 | 127 | # This is to avoid the risk of the name becoming out of sync with the actual condition.
|
55 | 128 | SLOW_TESTS_MARK = pytest.mark.skipif(
|
56 | 129 | FAST_TESTS_ONLY or DISABLE_SLOW_TESTS, reason="Skipping test as it takes a long time to run"
|
57 | 130 | )
|
58 | 131 |
|
59 |
| -AZURE_TESTS_MARK = pytest.mark.skipif( |
60 |
| - FAST_TESTS_ONLY or MACOS or not LOCAL_STORAGE_TESTS_ENABLED, reason=_MACOS_AZURE_TESTS_SKIP_REASON |
61 |
| -) |
62 |
| -"""Mark to skip all Azure tests when MACOS or ARCTICDB_FAST_TESTS_ONLY is set.""" |
63 |
| - |
64 |
| -# Mongo tests will run under local storage tests |
65 |
| -MONGO_TESTS_MARK = pytest.mark.skipif( |
66 |
| - FAST_TESTS_ONLY or sys.platform != "linux" or not LOCAL_STORAGE_TESTS_ENABLED, |
67 |
| - reason="Skipping mongo tests under ARCTICDB_FAST_TESTS_ONLY and if local storage tests are disabled", |
68 |
| -) |
69 | 132 | """Mark on tests using the mongo storage fixtures. Currently skips if ARCTICDB_FAST_TESTS_ONLY."""
|
70 | 133 |
|
71 | 134 | REAL_S3_TESTS_MARK = pytest.mark.skipif(
|
|
90 | 153 | """Mark on tests using S3 model storage.
|
91 | 154 | """
|
92 | 155 | SIM_S3_TESTS_MARK = pytest.mark.skipif(
|
93 |
| - not LOCAL_STORAGE_TESTS_ENABLED, |
| 156 | + not STORAGE_SIM_S3, |
94 | 157 | reason="Ability to disable local storages - simulates s3 is disabled",
|
95 | 158 | )
|
96 | 159 | """Mark on tests using GCP model storage.
|
97 | 160 | """
|
98 | 161 | SIM_GCP_TESTS_MARK = pytest.mark.skipif(
|
99 |
| - not LOCAL_STORAGE_TESTS_ENABLED, |
| 162 | + not STORAGE_SIM_GCP, |
100 | 163 | reason="Ability to disable local storages - simulates gcp is disabled",
|
101 | 164 | )
|
102 | 165 | """Mark on tests using the real GCP storage.
|
|
110 | 173 | """Mark on tests using the MEM storage.
|
111 | 174 | """
|
112 | 175 | MEM_TESTS_MARK = pytest.mark.skipif(
|
113 |
| - not LOCAL_STORAGE_TESTS_ENABLED, |
| 176 | + not STORAGE_MEM, |
114 | 177 | reason="Ability to disable local storages - mem storage is disabled",
|
115 | 178 | )
|
116 | 179 | """Mark on tests using the NFS model storage.
|
117 | 180 | """
|
118 | 181 | SIM_NFS_TESTS_MARK = pytest.mark.skipif(
|
119 |
| - not LOCAL_STORAGE_TESTS_ENABLED, |
| 182 | + not STORAGE_NFS, |
120 | 183 | reason="Ability to disable local storages - simulated nfs is disabled",
|
121 | 184 | )
|
122 | 185 | """Mark on tests using the real GCP storage.
|
123 | 186 | """
|
| 187 | +AZURE_TESTS_MARK = pytest.mark.skipif( |
| 188 | + FAST_TESTS_ONLY or MACOS or not STORAGE_AZURITE, reason=_MACOS_AZURE_TESTS_SKIP_REASON |
| 189 | +) |
| 190 | +"""Mark to skip all Azure tests when MACOS or ARCTICDB_FAST_TESTS_ONLY is set.""" |
124 | 191 |
|
| 192 | +# Mongo tests will run under local storage tests |
| 193 | +MONGO_TESTS_MARK = pytest.mark.skipif( |
| 194 | + FAST_TESTS_ONLY or (not LINUX) or (not STORAGE_MONGO), |
| 195 | + reason="Skipping mongo tests under ARCTICDB_FAST_TESTS_ONLY and if local storage tests are disabled", |
| 196 | +) |
| 197 | +"""Mark on tests or fixtures that need to skip V1 encoding tests |
| 198 | +""" |
| 199 | +TEST_ENCODING_V1_MARK = pytest.mark.skipif( |
| 200 | + not TEST_ENCODING_V1, |
| 201 | + reason="Ability to disable encoding tests - V1 is disabled", |
| 202 | +) |
| 203 | +"""Mark on tests or fixtures that need to skip V2 encoding tests |
| 204 | +""" |
| 205 | +TEST_ENCODING_V2_MARK = pytest.mark.skipif( |
| 206 | + not TEST_ENCODING_V2, |
| 207 | + reason="Ability to disable encoding tests - V2 is disabled", |
| 208 | +) |
125 | 209 |
|
126 | 210 | """Windows and MacOS have different handling of self-signed CA cert for test.
|
127 | 211 | TODO: https://github.com/man-group/ArcticDB/issues/1394"""
|
|
0 commit comments