Changeset 489:e5c90d782f04


Ignore:
Timestamp:
Feb 18, 2006, 9:40:50 PM (15 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Convert:
svn:778c30c8-61e0-0310-89d4-fe2f97a467b2/trunk@508
Message:
Extended `test_keep_connection`. This doesn't work as expected, though.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • _test_real_ftp.py

    r484 r489  
    312312
    313313    def test_keep_connection(self):
    314         # just make sure that `keep_alive` doesn't cause an error (exception)
    315         host = self.host
     314        # adjust server timeout (in seconds) here
     315        server_timeout = 3 * 60.0
    316316        # host
     317        host = self.host
    317318        host.keep_alive()
    318         # written file
     319        # prepare file to read (below)
    319320        written_file = host.file("_test_file_", "w")
    320         written_file.keep_alive()
     321        written_file.write("Test")
    321322        written_file.close()
    322         # read file
     323        # open files
    323324        read_file = host.file("_test_file_", "r")
    324         read_file.keep_alive()
    325         read_file.close()
    326         host.remove("_test_file_")
     325        written_file = host.file("_test_file2_", "w")
     326        written_file.write("x")
     327        stale_read_file = host.file("_test_file_")
     328        stale_written_file = host.file("_test_file3_", "w")
     329        stale_read_file.close()
     330        stale_written_file.write("abc")
     331        stale_written_file.close()
     332        try:
     333            # wait for would-be connection timeout (plus a bit more, to be sure)
     334            interval_length = 30.0
     335            intervals = int(server_timeout / interval_length) + 2
     336            for i in range(intervals):
     337                print "Keeping host alive (%d of %d) " % (i+1, intervals)
     338                host.keep_alive(ignore_errors=True)
     339                time.sleep(interval_length)
     340            # do some tests; order of statements is important
     341            # - access the open files (must be left open so that the stale
     342            #   files get reused)
     343            self.assertEqual(read_file.read(2), "Te")
     344            written_file.write("xyz")
     345            # - try to reuse the stale files
     346            written_file2 = host.file("_test_file3_", "w")
     347            read_file2 = host.file("_test_file_")
     348            written_file2.write("blah")
     349            self.assertEqual(read_file2.read(2), "Te")
     350            written_file2.close()
     351            read_file2.close()
     352            read_file.close()
     353            written_file.close()
     354        finally:
     355            # clean up
     356            print 2, host.listdir(".")
     357#             host.remove("_test_file_")
     358#             host.remove("_test_file2_")
     359#             host.remove("_test_file3_")
    327360
    328361
Note: See TracChangeset for help on using the changeset viewer.