Skip to content

Commit 2074211

Browse files
authored
Resilient start of simulated storages (#2583)
#### Reference Issues/PRs <!--Example: Fixes #1234. See also #3456.--> #### What does this implement or fix? Problem shoed here: https://github.com/man-group/ArcticDB/actions/runs/16915115493/job/47928193692 On runners time start seems to be varying as found in a comment for moto - it was 240 secs. For azurite and mongo it was default 20. The fix now makes start timeout equal and adds one retry. This code will not harm execution on laptops, but will make startup of tests for simulated and local storages on runners resilient. #### Any other comments? #### Checklist <details> <summary> Checklist for code changes... </summary> - [ ] Have you updated the relevant docstrings, documentation and copyright notice? - [ ] Is this contribution tested against [all ArcticDB's features](../docs/mkdocs/docs/technical/contributing.md)? - [ ] Do all exceptions introduced raise appropriate [error messages](https://docs.arcticdb.io/error_messages/)? - [ ] Are API changes highlighted in the PR description? - [ ] Is the PR labelled as enhancement or bug so it appears in autogenerated release notes? </details> <!-- Thanks for contributing a Pull Request to ArcticDB! Please ensure you have taken a look at: - ArcticDB's Code of Conduct: https://github.com/man-group/ArcticDB/blob/master/CODE_OF_CONDUCT.md - ArcticDB's Contribution Licensing: https://github.com/man-group/ArcticDB/blob/master/docs/mkdocs/docs/technical/contributing.md#contribution-licensing --> --------- Co-authored-by: Georgi Rusev <Georgi Rusev>
1 parent ad7bc5b commit 2074211

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

python/arcticdb/storage_fixtures/azure.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,10 @@ def _safe_enter(self):
193193
self.client_cert_dir = ""
194194
if self.http_protocol == "https":
195195
args += f" --key {self.key_file} --cert {self.cert_file}"
196-
self._p = GracefulProcessUtils.start(args, cwd=self.working_dir)
197-
wait_for_server_to_come_up(self.endpoint_root, "azurite", self._p)
196+
self._p = GracefulProcessUtils.start_with_retry(url=self.endpoint_root,
197+
service_name="azurite", num_retries=2, timeout=240,
198+
process_start_cmd=args,
199+
cwd=self.working_dir)
198200
return self
199201

200202
def __exit__(self, exc_type, exc_value, traceback):

python/arcticdb/storage_fixtures/mongo.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,11 @@ def __init__(self, data_dir: Optional[str] = None, port=0, executable="mongod"):
123123

124124
def _safe_enter(self):
125125
cmd = [self._executable, "--port", str(self._port), "--dbpath", self._data_dir]
126-
self._p = GracefulProcessUtils.start(cmd)
127126
self.mongo_uri = f"mongodb://localhost:{self._port}"
128-
wait_for_server_to_come_up(f"http://localhost:{self._port}", "mongod", self._p)
127+
self._p = GracefulProcessUtils.start_with_retry(url=f"http://localhost:{self._port}",
128+
service_name="mongod", num_retries=2, timeout=240,
129+
process_start_cmd=cmd)
130+
129131
self._client = get_mongo_client(self.mongo_uri)
130132

131133
def __exit__(self, exc_type, exc_value, traceback):

python/arcticdb/storage_fixtures/utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,23 @@ def start(cmd, **kwargs):
6161
print("About to run:", cmd)
6262
creation_flags = subprocess.CREATE_NEW_PROCESS_GROUP if _WINDOWS else 0
6363
return subprocess.Popen(cmd, creationflags=creation_flags, **kwargs)
64+
65+
@staticmethod
66+
def start_with_retry(url: str, service_name: str, num_retries: int, timeout: int,
67+
process_start_cmd: str, **kwargs):
68+
"""Attempts to start the process up to specified times.
69+
70+
Each time will wait for service to be avil at specified url up to the specified timeout"""
71+
for i in range(num_retries): # retry in case of connection problems
72+
try:
73+
p = GracefulProcessUtils.start(process_start_cmd, **kwargs)
74+
wait_for_server_to_come_up(url, service_name, p, timeout=timeout)
75+
return p
76+
except AssertionError:
77+
try:
78+
p.terminate()
79+
except:
80+
pass
6481

6582
@staticmethod
6683
def wait(p: ProcessUnion, timeout_sec: int):

0 commit comments

Comments
 (0)