Skip to content

Commit

Permalink
Merge pull request #850 from projectsyn/fix/parallel-fetching-propaga…
Browse files Browse the repository at this point in the history
…te-exceptions

Propagate exceptions raised while fetching dependencies
  • Loading branch information
simu authored Sep 18, 2023
2 parents 96a44e1 + c5ae870 commit 2b10057
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion commodore/dependency_mgmt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ def fetch_parallel(fetch_fun, cfg, to_fetch):
Fetch dependencies in parallel threads with ThreadPoolExecutor.
"""
with ThreadPoolExecutor() as exe:
exe.map(fetch_fun, itertools.repeat(cfg), to_fetch)
# We need to collect the results from the iterator produced by exe.map to ensure
# that any exceptions raised in `fetch_fun` are propagated, cf.
# https://docs.python.org/3/library/concurrent.futures.html#executor-objects. We
# do so by simply materializing the iterator into a list.
list(exe.map(fetch_fun, itertools.repeat(cfg), to_fetch))


def register_components(cfg: Config):
Expand Down
17 changes: 17 additions & 0 deletions tests/test_dependency_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,23 @@ def test_fetch_components_raises(
)


@patch("commodore.dependency_mgmt._read_components")
@patch("commodore.dependency_mgmt._discover_components")
def test_fetch_components_raises_giterror(
patch_discover, patch_read, config: Config, tmp_path: Path
):
components = ["foo"]
patch_discover.return_value = (components, {})
read_retval = setup_components_upstream(tmp_path, components)
read_retval["foo"].version = "nonexistent"
patch_read.return_value = read_retval

with pytest.raises(Exception) as excinfo:
dependency_mgmt.fetch_components(config)

assert "Failed to checkout revision 'nonexistent'" in str(excinfo.value)


@patch("commodore.dependency_mgmt._read_components")
@patch("commodore.dependency_mgmt._discover_components")
def test_fetch_components_is_minimal(
Expand Down

0 comments on commit 2b10057

Please sign in to comment.