[project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-55]

add an sftp unit test for making 100 files
create 100 files on the remote server, set their mode with chmod, then verify
that they're all there and contain the right data.  valeriy is reporting that
sometimes he's getting stuck after 20 and though i'm not seeing it, i want to
add a test to try to pin it down.
This commit is contained in:
Robey Pointer 2004-05-29 18:58:11 +00:00
parent af8cfeced9
commit 4d30633457
1 changed files with 30 additions and 0 deletions

View File

@ -26,6 +26,7 @@ do test file operations in (so no existing files will be harmed).
""" """
import sys, os import sys, os
import random
# need a host and private-key where we have acecss # need a host and private-key where we have acecss
HOST = os.environ.get('TEST_HOST', 'localhost') HOST = os.environ.get('TEST_HOST', 'localhost')
@ -307,3 +308,32 @@ class SFTPTest (unittest.TestCase):
sftp.remove(FOLDER + '/original.txt') sftp.remove(FOLDER + '/original.txt')
except: except:
pass pass
def test_A_lots_of_files(self):
"""
create a bunch of files over the same session.
"""
numfiles = 100
try:
for i in range(numfiles):
f = sftp.open('%s/file%d.txt' % (FOLDER, i), 'w', 1)
f.write('this is file #%d.\n' % i)
f.close()
sftp.chmod('%s/file%d.txt' % (FOLDER, i), 0660)
# now make sure every file is there, by creating a list of filenmes
# and reading them in random order.
numlist = range(numfiles)
while len(numlist) > 0:
r = numlist[random.randint(0, len(numlist) - 1)]
print r,
f = sftp.open('%s/file%d.txt' % (FOLDER, r))
self.assertEqual(f.readline(), 'this is file #%d.\n' % r)
f.close()
numlist.remove(r)
finally:
for i in range(numfiles):
try:
sftp.remove('%s/file%d.txt' % (FOLDER, i))
except:
pass