~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

(jameinel) Treat socket.error(EPIPE) as a ConnectionReset (bug #1047325) so
 that clients will properly reconnect. (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
181
181
        shape = sorted(os.listdir('.'))
182
182
        self.assertEquals(['A', 'B'], shape)
183
183
 
184
 
    def test_rename_exception(self):
185
 
        try:
186
 
            osutils.rename('nonexistent_path', 'different_nonexistent_path')
187
 
        except OSError, e:
188
 
            self.assertEqual(e.old_filename, 'nonexistent_path')
189
 
            self.assertEqual(e.new_filename, 'different_nonexistent_path')
190
 
            self.assertTrue('nonexistent_path' in e.strerror)
191
 
            self.assertTrue('different_nonexistent_path' in e.strerror)
192
 
 
193
184
 
194
185
class TestRandChars(tests.TestCase):
195
186
 
828
819
        self.assertEqual(None, osutils.safe_file_id(None))
829
820
 
830
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
 
831
861
class TestPosixFuncs(tests.TestCase):
832
862
    """Test that the posix version of normpath returns an appropriate path
833
863
       when used with 2 leading slashes."""