~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: John Arbash Meinel
  • Date: 2013-05-19 14:29:37 UTC
  • mfrom: (6437.63.9 2.5)
  • mto: (6437.63.10 2.5)
  • mto: This revision was merged to the branch mainline in revision 6575.
  • Revision ID: john@arbash-meinel.com-20130519142937-21ykz2n2y2f22za9
Merge in the actual 2.5 branch. It seems I failed before

Show diffs side-by-side

added added

removed removed

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