Skip to content

Commit f2275f4

Browse files
[Fix]: Extent wait in test_executor_dependence_mixed() (#931)
* [Fix]: Extent wait in test_executor_dependence_mixed() * Add timeout for file access * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * make mypy happy * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add one more test --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 434ef85 commit f2275f4

3 files changed

Lines changed: 27 additions & 7 deletions

File tree

src/executorlib/standalone/hdf.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
from concurrent.futures import Future
3+
from time import sleep
34
from typing import Any, Optional
45

56
import cloudpickle
@@ -86,13 +87,25 @@ def get_output(file_name: str) -> tuple[bool, bool, Any]:
8687
Returns:
8788
Tuple[bool, bool, object]: boolean flag indicating if output is available and the output object itself
8889
"""
89-
with h5py.File(file_name, "r") as hdf:
90-
if "output" in hdf:
91-
return True, True, cloudpickle.loads(np.void(hdf["/output"]))
92-
elif "error" in hdf:
93-
return True, False, cloudpickle.loads(np.void(hdf["/error"]))
94-
else:
95-
return False, False, None
90+
91+
def get_output_helper(file_name: str) -> tuple[bool, bool, Any]:
92+
with h5py.File(file_name, "r") as hdf:
93+
if "output" in hdf:
94+
return True, True, cloudpickle.loads(np.void(hdf["/output"]))
95+
elif "error" in hdf:
96+
return True, False, cloudpickle.loads(np.void(hdf["/error"]))
97+
else:
98+
return False, False, None
99+
100+
i = 0
101+
error = FileNotFoundError(f"Output file {file_name} not found.")
102+
while i < 10:
103+
try:
104+
return get_output_helper(file_name=file_name)
105+
except FileNotFoundError:
106+
i += 1
107+
sleep(0.1)
108+
raise error
96109

97110

98111
def get_runtime(file_name: str) -> float:

tests/unit/standalone/test_hdf.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ def test_get_future_from_file(self):
6464
self.assertTrue(isinstance(future, Future))
6565
self.assertFalse(future.done())
6666

67+
def test_get_output_file_missing(self):
68+
cache_directory = os.path.abspath("executorlib_cache")
69+
with self.assertRaises(FileNotFoundError):
70+
get_output(file_name=os.path.join(cache_directory, "does_not_exist.h5"))
71+
6772
def test_get_future_from_file_missing(self):
6873
cache_directory = os.path.abspath("executorlib_cache")
6974
with self.assertRaises(FileNotFoundError):

tests/unit/task_scheduler/file/test_serial.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def test_executor_dependence_mixed(self):
5454
fs1 = exe.submit(my_funct, 1, b=2)
5555
fs2 = exe.submit(my_funct, 1, b=fs1)
5656
self.assertFalse(fs2.done())
57+
self.assertEqual(fs1.result(), 3)
58+
self.assertTrue(fs1.done())
5759
self.assertEqual(fs2.result(), 4)
5860
self.assertTrue(fs2.done())
5961

0 commit comments

Comments
 (0)