Skip to content

Commit a3d3e6e

Browse files
authored
Merge pull request #313 from SciCatProject/break-after-first-connection
Stop after first successful connection
2 parents 5752841 + babc582 commit a3d3e6e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/scitacean/transfer/select.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ def _connect_first_suitable(
156156
continue
157157
success = True
158158
yield connection
159+
break # Do not try any more transfers.
159160
if not success:
160161
raise FileNotAccessibleError(
161162
f"Unable to {action} files for dataset: "

tests/transfer/select_transfer_test.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,29 @@ def test_select_download_uses_second_child_transfer_success(dataset: Dataset) ->
226226
assert not transfer_2.reverted
227227

228228

229+
def test_select_download_does_not_keep_going_after_first_success(
230+
dataset: Dataset,
231+
) -> None:
232+
transfer_1 = SuccessfulTransfer()
233+
transfer_2 = SuccessfulTransfer()
234+
transfer = SelectFileTransfer([transfer_1, transfer_2])
235+
236+
remote = dataset.source_folder / "file" # type: ignore[operator]
237+
local = Path("local_file")
238+
with transfer.connect_for_download(dataset, RemotePath("file")) as con:
239+
con.download_files(remote=[remote], local=[local])
240+
241+
assert not transfer_1.is_open_for_download
242+
assert transfer_1.downloaded == [(remote, local)]
243+
assert not transfer_1.uploaded
244+
assert not transfer_1.reverted
245+
246+
assert not transfer_2.is_open_for_download
247+
assert not transfer_2.downloaded
248+
assert not transfer_2.uploaded
249+
assert not transfer_2.reverted
250+
251+
229252
def test_select_upload_uses_single_child_transfer_success(dataset: Dataset) -> None:
230253
transfer_1 = SuccessfulTransfer()
231254
transfer = SelectFileTransfer([transfer_1])

0 commit comments

Comments
 (0)