Skip to content

Commit

Permalink
Merge pull request #6799 from christian-monch/fix-ssh-copy-test
Browse files Browse the repository at this point in the history
Fix a race condition in ssh copy test
  • Loading branch information
yarikoptic committed Jul 6, 2022
2 parents fcfca23 + 4ffb001 commit 7d615d3
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions datalad/support/tests/test_sshconnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,32 @@ def ctrl_path(self):
@skip_if_on_windows
@skip_ssh
@with_tempfile(mkdir=True)
@with_tempfile(content="one")
@with_tempfile(content="two")
@with_tempfile(content='one')
@with_tempfile(content='two')
def test_ssh_copy(sourcedir=None, sourcefile1=None, sourcefile2=None):
port = get_ssh_port('datalad-test')
remote_url = 'ssh://datalad-test:{}'.format(port)
manager = SSHManager()
ssh = manager.get_connection(remote_url)

# write to obscurely named file in sourcedir
obscure_file = opj(sourcedir, get_most_obscure_supported_name())
with open(obscure_file, 'w') as f:
f.write("three")
# copy content of sourcefile3 to an obscurely named file in sourcedir
obscure_file = get_most_obscure_supported_name()
obscure_path = opj(sourcedir, obscure_file)
with open(obscure_path, 'w') as f:
f.write('three')

# copy tempfile list to remote_url:sourcedir
sourcefiles = [sourcefile1, sourcefile2, obscure_file]
# copy first two temp files to remote_url:sourcedir
sourcefiles = [sourcefile1, sourcefile2]
ssh.put(sourcefiles, opj(remote_url, sourcedir))
# copy obscure file to remote_url:sourcedir/'<obscure_file_name>.c opy'
# we copy to a different name because the test setup maps local dir and
# remote dir to the same directory on the test machine. That means the file
# is copied onto itself. With ssh version 9 this leads to an empty file.
# We perform copy instead of just writing the content to the destination
# file, because ww want to ensure that the source file is picked up by
# 'ssh.put()'.
ssh.put([obscure_path], opj(remote_url, sourcedir, obscure_file + '.c opy'))

# docs promise that connection is auto-opened in case of multiplex
if _ssh_manager_is_multiplex:
ok_(ssh.is_open())
Expand All @@ -237,7 +247,8 @@ def test_ssh_copy(sourcedir=None, sourcefile1=None, sourcefile2=None):

# check if targetfiles(and its content) exist in remote_url:targetdir,
# this implies file(s) and recursive directory copying pass
for targetfile, content in zip(sourcefiles, ["one", "two", "three"]):
for targetfile, content in zip(sourcefiles + [obscure_file + '.c opy'],
['one', 'two', 'three']):
targetpath = opj(targetdir, targetfile)
ok_(exists(targetpath))
with open(targetpath, 'r') as fp:
Expand Down

0 comments on commit 7d615d3

Please sign in to comment.