~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Patch Queue Manager
  • Date: 2012-09-19 08:27:25 UTC
  • mfrom: (6562.1.1 2.6-merge-up-2.5)
  • Revision ID: pqm@pqm.ubuntu.com-20120919082725-dzvmca37zj5xx2hh
(jam) Merge bzr-2.5.2-dev into bzr trunk to get the ConnectionReset
        fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
828
828
        self.assertEqual(None, osutils.safe_file_id(None))
829
829
 
830
830
 
 
831
class TestSendAll(tests.TestCase):
 
832
 
 
833
    def test_send_with_disconnected_socket(self):
 
834
        class DisconnectedSocket(object):
 
835
            def __init__(self, err):
 
836
                self.err = err
 
837
            def send(self, content):
 
838
                raise self.err
 
839
            def close(self):
 
840
                pass
 
841
        # All of these should be treated as ConnectionReset
 
842
        errs = []
 
843
        for err_cls in (IOError, socket.error):
 
844
            for errnum in osutils._end_of_stream_errors:
 
845
                errs.append(err_cls(errnum))
 
846
        for err in errs:
 
847
            sock = DisconnectedSocket(err)
 
848
            self.assertRaises(errors.ConnectionReset,
 
849
                osutils.send_all, sock, 'some more content')
 
850
 
 
851
    def test_send_with_no_progress(self):
 
852
        # See https://bugs.launchpad.net/bzr/+bug/1047309
 
853
        # It seems that paramiko can get into a state where it doesn't error,
 
854
        # but it returns 0 bytes sent for requests over and over again.
 
855
        class NoSendingSocket(object):
 
856
            def __init__(self):
 
857
                self.call_count = 0
 
858
            def send(self, bytes):
 
859
                self.call_count += 1
 
860
                if self.call_count > 100:
 
861
                    # Prevent the test suite from hanging
 
862
                    raise RuntimeError('too many calls')
 
863
                return 0
 
864
        sock = NoSendingSocket()
 
865
        self.assertRaises(errors.ConnectionReset,
 
866
                          osutils.send_all, sock, 'content')
 
867
        self.assertEqual(1, sock.call_count)
 
868
 
 
869
 
831
870
class TestPosixFuncs(tests.TestCase):
832
871
    """Test that the posix version of normpath returns an appropriate path
833
872
       when used with 2 leading slashes."""